From a43f04efd15f1c0ac513e8f58b0d3797df63a79c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 9 Apr 2012 15:41:48 -0400 Subject: [PATCH] Reorganize db drivers --- .../{firebird.php => firebird_driver.php} | 124 +--------------- sys/db/drivers/firebird/firebird_result.php | 134 ++++++++++++++++++ .../mysql/{mysql.php => mysql_driver.php} | 2 +- .../odbc/{odbc.php => odbc_driver.php} | 2 +- .../pgsql/{pgsql.php => pgsql_driver.php} | 2 +- .../sqlite/{sqlite.php => sqlite_driver.php} | 2 +- tests/index.php | 5 +- tests/test_dbs/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 8 files changed, 142 insertions(+), 129 deletions(-) rename sys/db/drivers/firebird/{firebird.php => firebird_driver.php} (80%) create mode 100644 sys/db/drivers/firebird/firebird_result.php rename sys/db/drivers/mysql/{mysql.php => mysql_driver.php} (99%) rename sys/db/drivers/odbc/{odbc.php => odbc_driver.php} (99%) rename sys/db/drivers/pgsql/{pgsql.php => pgsql_driver.php} (99%) rename sys/db/drivers/sqlite/{sqlite.php => sqlite_driver.php} (99%) diff --git a/sys/db/drivers/firebird/firebird.php b/sys/db/drivers/firebird/firebird_driver.php similarity index 80% rename from sys/db/drivers/firebird/firebird.php rename to sys/db/drivers/firebird/firebird_driver.php index c5ebbe4..0dce1b6 100644 --- a/sys/db/drivers/firebird/firebird.php +++ b/sys/db/drivers/firebird/firebird_driver.php @@ -497,126 +497,4 @@ SQL; return $output_sql; } } - -// -------------------------------------------------------------------------- - -/** - * Firebird result class to emulate PDOStatement Class - */ -class Firebird_Result { - - private $statement; - - /** - * Create the object by passing the resource for - * the query - * - * @param resource $link - */ - public function __construct($link) - { - $this->statement = $link; - } - - // -------------------------------------------------------------------------- - - /** - * Emulate PDO fetch public function - * - * @param int $fetch_style - * @return mixed - */ - public function fetch($fetch_style=PDO::FETCH_ASSOC, $statement=NULL) - { - if ( ! is_null($statement)) - { - $this->statement = $statement; - } - - switch($fetch_style) - { - case PDO::FETCH_OBJ: - return fbird_fetch_object($this->statement, IBASE_FETCH_BLOBS); - break; - - case PDO::FETCH_NUM: - return fbird_fetch_row($this->statement, IBASE_FETCH_BLOBS); - break; - - default: - return fbird_fetch_assoc($this->statement, IBASE_FETCH_BLOBS); - break; - } - } - - // -------------------------------------------------------------------------- - - /** - * Emulate PDO fetchAll public function - * - * @param int $fetch_style - * @return mixed - */ - public function fetchAll($fetch_style=PDO::FETCH_ASSOC, $statement=NULL) - { - $all = array(); - - while($row = $this->fetch($fetch_style, $statement)) - { - $all[] = $row; - } - - $this->result = $all; - - return $all; - } - - // -------------------------------------------------------------------------- - - /** - * Run a prepared statement query - * - * @param array $args - * @return bool - */ - public function execute($args) - { - //Add the prepared statement as the first parameter - array_unshift($args, $this->statement); - - // Let php do all the hard stuff in converting - // the array of arguments into a list of arguments - // Then pass the resource to the constructor - $this->__construct(call_user_func_array('fbird_execute', $args)); - - return $this; - } - - // -------------------------------------------------------------------------- - - /** - * Return the number of rows affected by the previous query - * - * @return int - */ - public function rowCount() - { - return fbird_affected_rows(); - } - - // -------------------------------------------------------------------------- - - /** - * Method to emulate PDO->errorInfo / PDOStatement->errorInfo - * - * @return array - */ - public function errorInfo() - { - $code = fbird_errcode(); - $msg = fbird_errmsg(); - - return array(0, $code, $msg); - } -} -// End of firebird.php \ No newline at end of file +// End of firebird_driver.php \ No newline at end of file diff --git a/sys/db/drivers/firebird/firebird_result.php b/sys/db/drivers/firebird/firebird_result.php new file mode 100644 index 0000000..6c84651 --- /dev/null +++ b/sys/db/drivers/firebird/firebird_result.php @@ -0,0 +1,134 @@ +statement = $link; + } + + // -------------------------------------------------------------------------- + + /** + * Emulate PDO fetch public function + * + * @param int $fetch_style + * @return mixed + */ + public function fetch($fetch_style=PDO::FETCH_ASSOC, $statement=NULL) + { + if ( ! is_null($statement)) + { + $this->statement = $statement; + } + + switch($fetch_style) + { + case PDO::FETCH_OBJ: + return fbird_fetch_object($this->statement, IBASE_FETCH_BLOBS); + break; + + case PDO::FETCH_NUM: + return fbird_fetch_row($this->statement, IBASE_FETCH_BLOBS); + break; + + default: + return fbird_fetch_assoc($this->statement, IBASE_FETCH_BLOBS); + break; + } + } + + // -------------------------------------------------------------------------- + + /** + * Emulate PDO fetchAll public function + * + * @param int $fetch_style + * @return mixed + */ + public function fetchAll($fetch_style=PDO::FETCH_ASSOC, $statement=NULL) + { + $all = array(); + + while($row = $this->fetch($fetch_style, $statement)) + { + $all[] = $row; + } + + $this->result = $all; + + return $all; + } + + // -------------------------------------------------------------------------- + + /** + * Run a prepared statement query + * + * @param array $args + * @return bool + */ + public function execute($args) + { + //Add the prepared statement as the first parameter + array_unshift($args, $this->statement); + + // Let php do all the hard stuff in converting + // the array of arguments into a list of arguments + // Then pass the resource to the constructor + $this->__construct(call_user_func_array('fbird_execute', $args)); + + return $this; + } + + // -------------------------------------------------------------------------- + + /** + * Return the number of rows affected by the previous query + * + * @return int + */ + public function rowCount() + { + return fbird_affected_rows(); + } + + // -------------------------------------------------------------------------- + + /** + * Method to emulate PDO->errorInfo / PDOStatement->errorInfo + * + * @return array + */ + public function errorInfo() + { + $code = fbird_errcode(); + $msg = fbird_errmsg(); + + return array(0, $code, $msg); + } +} +// End of firebird_result.php \ No newline at end of file diff --git a/sys/db/drivers/mysql/mysql.php b/sys/db/drivers/mysql/mysql_driver.php similarity index 99% rename from sys/db/drivers/mysql/mysql.php rename to sys/db/drivers/mysql/mysql_driver.php index 9472c6f..b938787 100644 --- a/sys/db/drivers/mysql/mysql.php +++ b/sys/db/drivers/mysql/mysql_driver.php @@ -221,4 +221,4 @@ class MySQL extends DB_PDO { return '`'.implode('`.`', $hiers).'`'; } } -//End of mysql.php \ No newline at end of file +//End of mysql_driver.php \ No newline at end of file diff --git a/sys/db/drivers/odbc/odbc.php b/sys/db/drivers/odbc/odbc_driver.php similarity index 99% rename from sys/db/drivers/odbc/odbc.php rename to sys/db/drivers/odbc/odbc_driver.php index eb47fee..987b83d 100644 --- a/sys/db/drivers/odbc/odbc.php +++ b/sys/db/drivers/odbc/odbc_driver.php @@ -188,4 +188,4 @@ class ODBC extends DB_PDO { return ''; } } -// End of odbc.php \ No newline at end of file +// End of odbc_driver.php \ No newline at end of file diff --git a/sys/db/drivers/pgsql/pgsql.php b/sys/db/drivers/pgsql/pgsql_driver.php similarity index 99% rename from sys/db/drivers/pgsql/pgsql.php rename to sys/db/drivers/pgsql/pgsql_driver.php index 3d52b70..f635f2c 100644 --- a/sys/db/drivers/pgsql/pgsql.php +++ b/sys/db/drivers/pgsql/pgsql_driver.php @@ -281,4 +281,4 @@ SQL; return ''; } } -//End of pgsql.php \ No newline at end of file +//End of pgsql_driver.php \ No newline at end of file diff --git a/sys/db/drivers/sqlite/sqlite.php b/sys/db/drivers/sqlite/sqlite_driver.php similarity index 99% rename from sys/db/drivers/sqlite/sqlite.php rename to sys/db/drivers/sqlite/sqlite_driver.php index a7850ea..f1ec267 100644 --- a/sys/db/drivers/sqlite/sqlite.php +++ b/sys/db/drivers/sqlite/sqlite_driver.php @@ -312,4 +312,4 @@ SQL; return $output_sql; } } -//End of sqlite.php \ No newline at end of file +//End of sqlite_driver.php \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index 99adbd9..8580849 100644 --- a/tests/index.php +++ b/tests/index.php @@ -56,9 +56,10 @@ foreach(pdo_drivers() as $d) continue; } - $src_file = "{$src_path}{$d}.php"; + // Load by driver folder + $src_dir = "{$src_path}{$d}"; - if(is_file($src_file)) + if(is_dir($src_dir)) { array_map('do_include', glob($src_path.$d.'/*.php')); require_once("{$test_path}{$d}.php"); diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index 8241b62267a1adc61827c56c38ff936782d68755..9e662189f666321c4708004c9fe9a80b5219e702 100755 GIT binary patch delta 1087 zcmaiy!D|yi6o=nTVjK6_W{4E2ptIYiMgnRUwWT+S6x2gcQ9&>DRD|lOJ&2($Lg(T^ zu!nc37ykhfOPgEqsvgv3$gZmSt$LzJTb--`nT2>Ztyn(AF#ly-j8 z#kzcX0CSWsQtzWL z1YCzFn%@6Hm(CtwRjz0{=-B+nnl5+n98n)j$4Qnm5@wb#v*e-8?c3Z3asD*zhggyK zV~IzvdpLfaDZ&bKoJp>!3&D`&cEnhYoeySf`cfuG+?l)~g<_HU0tQTGAo_ delta 1010 zcmZvb&r2IY7(l;S$Y9(V zx8eQ}=(gQaa6eB0H1r8zvCn@2N@K_Q#}A_k0xUhsAuxSCPyI@lfA($)DVP+N6m3!@ zq-d9-LyAr*x}@kn6g(lUi&Uk<=0}~CMxJBWZh1gD{LsO~k8Fb$kCuQ}tQRJEE+mKd zz!D$ao$0rC(1sPvz;n!kjYDwFv+(C`S}<36b+juR9+p`9o7Yd^n@amQpt}EKo_$pd zXP9A+)Q*pK;fwybs(!-)rpE{n2gKOr4KYN|*(X)=F|7_f>{HbmCPTdn^e@<6U{0yu zb<7n$8eU@Z5|j5s;LWM;HOz#{?O3sFD&8{8#AGHW^G2)UcTw@%Sn;~yB_=O1dDo2M z)mZUzQ}L2vCMGj6naiz;=cD4eSn;gkB_=O1d0!gEGqK`gQ}MK6CMGj6nV+>Pei{`| z#)>BlFEM$E$vb*qoD8;MHQWfnY)fxTby~xsrSHS1IK}Gfy{G@6t21=eiHB2a#Ye6l M{KI@@-^az$EpXiOk^lez