From 6a68d8c0e10dc37bf4c2e1ce9805e5ed09083822 Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 25 Oct 2008 17:43:45 +0000 Subject: [PATCH] MDL-16930 dml: converting print_error to exceptions --- lib/dml/moodle_database.php | 20 ++++++++++---------- lib/dml/mssql_adodb_moodle_database.php | 2 +- lib/dml/oci8po_adodb_moodle_database.php | 4 ++-- lib/dml/postgres7_adodb_moodle_database.php | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index 4a53a50f38..9f8727a179 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -318,7 +318,7 @@ abstract class moodle_database { } } else { - print_error('typenotimplement'); + throw new dml_exception('typenotimplement'); } return array($sql, $params); } @@ -358,7 +358,7 @@ abstract class moodle_database { } if ($dollar_count) { if ($count) { - print_error('mixedtypesqlparam'); + throw new dml_exception('mixedtypesqlparam'); } $type = SQL_PARAMS_DOLLAR; $count = $dollar_count; @@ -366,7 +366,7 @@ abstract class moodle_database { } if ($q_count) { if ($count) { - print_error('mixedtypesqlparam'); + throw new dml_exception('mixedtypesqlparam'); } $type = SQL_PARAMS_QM; $count = $q_count; @@ -385,7 +385,7 @@ abstract class moodle_database { } if ($count > count($params)) { - print_error('invalidqueryparam'); + throw new dml_exception('invalidqueryparam'); } if ($type & $allowed_types) { // bitwise AND @@ -408,12 +408,12 @@ abstract class moodle_database { foreach ($named_matches[0] as $key) { $key = trim($key, ':'); if (!array_key_exists($key, $params)) { - print_error('missingkeyinsql', '', '', $key); + throw new dml_exception('missingkeyinsql', '', '', $key); } $finalparams[$key] = $params[$key]; } if ($count != count($finalparams)) { - print_error('duplicateparaminsql'); + throw new dml_exception('duplicateparaminsql'); } if ($target_type & SQL_PARAMS_QM) { @@ -422,11 +422,11 @@ abstract class moodle_database { } else if ($target_type & SQL_PARAMS_NAMED) { return array($sql, $finalparams, SQL_PARAMS_NAMED); } else { // $type & SQL_PARAMS_DOLLAR - print_error('boundsyntaxnotsupport'); + throw new dml_exception('boundsyntaxnotsupport'); } } else if ($type == SQL_PARAMS_DOLLAR) { - print_error('boundsyntaxnotsupport'); + throw new dml_exception('boundsyntaxnotsupport'); } else { // $type == SQL_PARAMS_QM if (count($params) != $count) { @@ -448,7 +448,7 @@ abstract class moodle_database { } return array($sql, $finalparams, SQL_PARAMS_NAMED); } else { // $type & SQL_PARAMS_DOLLAR - print_error('boundsyntaxnotsupport'); + throw new dml_exception('boundsyntaxnotsupport'); } } } @@ -1417,7 +1417,7 @@ abstract class moodle_database { $params = array(); foreach ($conditions as $key=>$value) { if (is_int($key)) { - print_error('invalidnumkey'); + throw new dml_exception('invalidnumkey'); } if (is_null($value)) { $where[] = "$key IS NULL"; diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index c9350e1450..e3157164d6 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -16,7 +16,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database { public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) { if ($prefix == '' and !$this->external) { //Enforce prefixes for everybody but mysql - print_error('prefixcannotbeempty', 'error', '', $this->get_dbfamily()); + throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily()); } return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions); } diff --git a/lib/dml/oci8po_adodb_moodle_database.php b/lib/dml/oci8po_adodb_moodle_database.php index 3d02f662d8..77dcbbb184 100644 --- a/lib/dml/oci8po_adodb_moodle_database.php +++ b/lib/dml/oci8po_adodb_moodle_database.php @@ -13,12 +13,12 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database { public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) { if ($prefix == '' and !$this->external) { //Enforce prefixes for everybody but mysql - print_error('prefixcannotbeempty', 'error', '', $this->get_dbfamily()); + throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily()); } if (!$this->external and strlen($prefix) > 2) { //Max prefix length for Oracle is 2cc $a = (object)array('dbfamily'=>'oracle', 'maxlength'=>2); - print_error('prefixtoolong', 'error', '', $a); + throw new dml_exception('prefixtoolong', $a); } return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions); } diff --git a/lib/dml/postgres7_adodb_moodle_database.php b/lib/dml/postgres7_adodb_moodle_database.php index 0710cec63f..d11f9f4a86 100644 --- a/lib/dml/postgres7_adodb_moodle_database.php +++ b/lib/dml/postgres7_adodb_moodle_database.php @@ -12,7 +12,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database { public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) { if ($prefix == '' and !$this->external) { //Enforce prefixes for everybody but mysql - print_error('prefixcannotbeempty', 'error', '', $this->get_dbfamily()); + throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily()); } return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions); } -- 2.39.5