Skip to content

Commit

Permalink
Bug: 14216 Attempt to report back meaningful results.
Browse files Browse the repository at this point in the history
For non-select statements, report back number of rows affected.
  • Loading branch information
mrubinsk committed Jan 6, 2016
1 parent d412bc8 commit b754ca3
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions horde/admin/sqlshell.php
Expand Up @@ -39,11 +39,35 @@
$q_cache = array_slice($q_cache, -20);
$session->set('horde', 'sql_query_cache', $q_cache);

// Parse out the query results.
try {
$result = $db->select(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
} catch (Horde_Db_Exception $e) {
$notification->push($e);
if (stripos($command, 'UPDATE') === 0) {
$type = 'update';
try {
$result = $db->update(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
} catch (Horde_Db_Exception $e) {
$notification->push($e);
}
} elseif (stripos($command, 'INSERT') === 0) {
$type = 'insert';
try {
$result = $db->insert(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
} catch (Horde_Db_Exception $e) {
$notification->push($e);
}
} elseif (stripos($command, 'DELETE') === 0) {
$type = 'delete';
try {
$result = $db->delete(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
} catch (Horde_Db_Exception $e) {
$notification->push($e);
}
} else {
// Default to a SELECT and hope for the best.
$type = 'select';
try {
$result = $db->select(Horde_String::convertCharset($command, 'UTF-8', $conf['sql']['charset']));
} catch (Horde_Db_Exception $e) {
$notification->push($e);
}
}
}

Expand All @@ -59,6 +83,19 @@
$view->q_cache = $q_cache;
$view->title = $title;

switch ($type) {
case 'insert':
$notification->push(_("The INSERT command completed successfully."), 'horde.success');
unset($result);
break;
case 'update':
$notification->push(sprintf(_("The UPDATE command completed successfully. A total of %d rows were modified."), $result), 'horde.success');
unset($result);
break;
case 'delete':
$notification->push(sprintf(_("The DELETE command completed successfully. A total of %d rows were deleted."), $result), 'horde.success');
}

if (isset($result)) {
$keys = null;
$rows = array();
Expand Down

0 comments on commit b754ca3

Please sign in to comment.