From 40ca41b9c94a20146cc4a343ac2896e911d81dda Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 18 May 2010 11:58:44 -0600 Subject: [PATCH] Two more places to use Horde_Db_Adapter_Base --- framework/admintools/horde-remove-pref.php | 39 ++++++++++++++++++------------ framework/admintools/horde-sql-shell.php | 20 +++++++-------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/framework/admintools/horde-remove-pref.php b/framework/admintools/horde-remove-pref.php index 587df5709..4b69af45e 100755 --- a/framework/admintools/horde-remove-pref.php +++ b/framework/admintools/horde-remove-pref.php @@ -14,32 +14,39 @@ $live = false; require_once dirname(__FILE__) . '/horde-base.php'; -Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true, 'nocompress' => true)); +Horde_Registry::appInit('horde', array( + 'authentication' => 'none', + 'cli' => true +)); -$scope = $cli->prompt(_("Enter value for pref_scope:")); -$name = $cli->prompt(_("Enter value for pref_name:")); +$scope = $cli->prompt('Enter value for pref_scope:'); +$name = $cli->prompt('Enter value for pref_name:'); /* Open the database. */ -$db = $injector->getInstance('Horde_Db_Pear')->getOb(); +$db = $injector->getInstance('Horde_Db_Base_Adapter'); if ($live) { $sql = 'DELETE FROM horde_prefs WHERE pref_scope = ? AND pref_name = ?'; $values = array($scope, $name); - $result = $db->getAll($sql, $values); - if (is_a($result, 'PEAR_Error')) { - var_dump($result); - } elseif (empty($result)) { - $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope)); - } else { - $cli->writeln(sprintf(_("Preferences \"%s\" deleted in scope \"%s\"."), $name, $scope)); + try { + if ($db->delete($sql, $values)) { + $cli->writeln(sprintf(_("Preferences \"%s\" deleted in scope \"%s\"."), $name, $scope)); + } else { + $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope)); + } + } catch (Horde_Db_Exception $e) { + print_r($e); } } else { $sql = 'SELECT * FROM horde_prefs WHERE pref_scope = ? AND pref_name = ?'; $values = array($scope, $name); - $result = $db->getAll($sql, $values); - if (empty($result)) { - $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope)); - } else { - var_dump($result); + try { + if ($result = $db->selectAll($sql, $values)) { + var_dump($result); + } else { + $cli->writeln(sprintf(_("No preference \"%s\" found in scope \"%s\"."), $name, $scope)); + } + } catch (Horde_Db_Exception $e) { + print_r($e); } } diff --git a/framework/admintools/horde-sql-shell.php b/framework/admintools/horde-sql-shell.php index 4c2e95d8f..2522b66f0 100755 --- a/framework/admintools/horde-sql-shell.php +++ b/framework/admintools/horde-sql-shell.php @@ -11,23 +11,21 @@ */ require_once dirname(__FILE__) . '/horde-base.php'; -Horde_Registry::appInit('horde', array('authentication' => 'none', 'cli' => true)); +Horde_Registry::appInit('horde', array( + 'authentication' => 'none', + 'cli' => true +)); -$dbh = $injector->getInstance('Horde_Db_Pear')->getOb(); - -// list databases command -// $result = $dbh->getListOf('databases'); - -// list tables command -// $result = $dbh->getListOf('tables'); +$dbh = $injector->getInstance('Horde_Db_Adapter_Base'); // read sql file for statements to run $statements = new Horde_Db_StatementParser($_SERVER['argv'][1]); foreach ($statements as $stmt) { echo "Running:\n " . preg_replace('/\s+/', ' ', $stmt) . "\n"; - $result = $dbh->query($stmt); - if (is_a($result, 'PEAR_Error')) { - var_dump($result); + try { + $dbh->execute($stmt); + } catch (Horde_Db_Exception $e) { + print_r($e); exit; } -- 2.11.0