From 10de783b1431e58f014922db263f83fc2f443004 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 25 Sep 2012 17:16:36 +0000 Subject: [PATCH] Fix contributing file, beginning of prefixes --- classes/query_builder.php | 98 ++++++++++++++++++++-------------- composer.json | 10 +++- tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 3 files changed, 68 insertions(+), 40 deletions(-) diff --git a/classes/query_builder.php b/classes/query_builder.php index 1888918..68f8405 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -138,6 +138,13 @@ class Query_Builder { */ public $sql; + /** + * Database table prefix + * + * @var string + */ + public $table_prefix = ''; + /** * Query component order mapping * for complex select queries @@ -223,6 +230,12 @@ class Query_Builder { throw new BadDBDriverException('Database driver does not exist, or is not supported'); } + // Set the table prefix, if it exists + if (isset($params->prefix)) + { + $this->table_prefix = $params->prefix; + } + // Create the dsn for the database to connect to switch($dbtype) { @@ -1088,7 +1101,7 @@ class Query_Builder { } // Reset for next query - $this->_reset(); + $this->reset_query(); return $result; } @@ -1159,7 +1172,7 @@ class Query_Builder { } // Reset for next query - $this->_reset(); + $this->reset_query(); $rows = $result->fetchAll(); @@ -1187,7 +1200,7 @@ class Query_Builder { $res = $this->prepare_execute($sql, $this->values); - $this->_reset(); + $this->reset_query(); return $res; } @@ -1213,7 +1226,7 @@ class Query_Builder { $res = $this->prepare_execute($sql, $this->values); - $this->_reset(); + $this->reset_query(); // Run the query return $res; @@ -1241,7 +1254,7 @@ class Query_Builder { $res = $this->prepare_execute($sql, $this->values); - $this->_reset(); + $this->reset_query(); // Delete the table rows, and return the result return $res; @@ -1271,7 +1284,7 @@ class Query_Builder { // Reset the query builder for the next query if ($reset) { - $this->_reset(); + $this->reset_query(); } return $sql; @@ -1293,7 +1306,7 @@ class Query_Builder { // Reset the query builder for the next query if ($reset) { - $this->_reset(); + $this->reset_query(); } return $sql; @@ -1315,7 +1328,7 @@ class Query_Builder { // Reset the query builder for the next query if ($reset) { - $this->_reset(); + $this->reset_query(); } return $sql; @@ -1337,7 +1350,7 @@ class Query_Builder { // Reset the query builder for the next query if ($reset) { - $this->_reset(); + $this->reset_query(); } return $sql; @@ -1347,41 +1360,12 @@ class Query_Builder { // ! Miscellaneous Methods // -------------------------------------------------------------------------- - /** - * Resets the query builder for the next query - */ - public function reset_query() - { - $this->_reset(); - } - - // -------------------------------------------------------------------------- - - /** - * Calls a function further down the inheritence chain - * - * @param string $name - * @param array $params - * @return mixed - */ - public function __call($name, $params) - { - if (method_exists($this->db, $name)) - { - return call_user_func_array(array($this->db, $name), $params); - } - - return NULL; - } - - // -------------------------------------------------------------------------- - /** * Clear out the class variables, so the next query can be run * * @return void */ - private function _reset() + public function reset_query() { // Only unset class variables that // are not callable. Otherwise, we'll @@ -1415,6 +1399,42 @@ class Query_Builder { // -------------------------------------------------------------------------- + /** + * Auto-prefix table names + * + * @param string $table + * @return string + */ + private function prefix($table) + { + // If there isn't a prefix, just return + if (empty($this->table_prefix)) + { + return $table; + } + } + + // -------------------------------------------------------------------------- + + /** + * Calls a function further down the inheritence chain + * + * @param string $name + * @param array $params + * @return mixed + */ + public function __call($name, $params) + { + if (method_exists($this->db, $name)) + { + return call_user_func_array(array($this->db, $name), $params); + } + + return NULL; + } + + // -------------------------------------------------------------------------- + /** * String together the sql statements for sending to the db * diff --git a/composer.json b/composer.json index 916d1d9..0ecf991 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,15 @@ "name":"aviat4ion/query", "type":"library", "description":"Database Query Builder and Abstraction layer", - "keywords":["database", "query builder", "mysql", "firebird", "sqlite", "postgres"], + "keywords":[ + "database", + "query builder", + "mysql", + "firebird", + "sqlite", + "postgres", + "pdo" + ], "homepage":"https://github.com/aviat4ion/Query", "license":"dbad-license", "authors": [{ diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index ef41d68d1092c513a2ae2141197a81d76d0cdb83..a8d6c35bcea61b8cfd2b2e9524fea39070ed0135 100644 GIT binary patch delta 457 zcmY*W&r1S96n>+t<-XRP=wgRL-Na6z1Vs=Od9)t}VYiU*59r_@utdzMjxj_+bd3&K zpr^zRoeQE%Cp8K@q!LSck$UT9(G2f>?}K^YH*dx?wovv<+LsB?gWi*}|*7-h@23S}>(A>%bngzO>9evo~_+t>=q==(P7x%*ww<)?&bp3MPdng)Rk`!jK{$MUxcGQUouA z$p!m%49jc@I_>>tDX>*dm`*i;#>sLH>&}h1$U5MhMd3$}0@p1#=N6>(5Ttn=T&)+@ zcmzgBUuhB8)#8vPPH9oFDBnl<9o}2BI%XkwW@^R7QC3j06(d_1aT5mVs;ees4$ z4Pd}%-_YFG28V*$E8?{}a