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 ef41d68..a8d6c35 100644 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ