function drush_salesforce_api_soql in Salesforce Suite 7.2
Same name and namespace in other branches
- 6.2 salesforce_api/salesforce_api.drush.inc \drush_salesforce_api_soql()
Execute a SOQL query.
File
- salesforce_api/
salesforce_api.drush.inc, line 183 - Drush integration for Salesforce. Provides commands to examine and query Salesforce data.
Code
function drush_salesforce_api_soql() {
_salesforce_api_drush_check_soap();
$args = func_get_args();
$command = implode(' ', $args);
if ($sf = salesforce_api_connect()) {
try {
timer_start('soql_query');
$result = $sf->client
->query($command);
$timer = timer_stop('soql_query');
foreach ($result->records as $r) {
if (!isset($rows)) {
$header = array();
foreach ($r as $k => $v) {
$header[] = $k;
}
$rows = array(
$header,
);
}
$row = array();
foreach ($r as $k => $v) {
$row[] = $v;
}
$rows[] = $row;
}
drush_print_table($rows, TRUE);
drush_print("\n" . dt('!count rows in set (!time sec)', array(
'!count' => $result->size,
'!time' => number_format($timer['time'] / 1000, 2),
)));
} catch (Exception $e) {
drush_print($e->faultstring);
}
}
else {
drush_print('Could not connect to Salesforce.');
}
}