diff --git a/README.md b/README.md index 676cf4a..0a56506 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Create a connection array or object similar to this: The parameters required depend on the database. ### Running Queries -Query uses the same interface as CodeIgniter's [Active Record class](http://codeigniter.com/user_guide/database/active_record.html). However, it does not implement the `insert_batch` or `update_batch` methods. +Query uses the same interface as CodeIgniter's [Active Record class](http://codeigniter.com/user_guide/database/active_record.html). However, it does not implement the `insert_batch`, `update_batch` or caching methods. ####You can also run queries manually. diff --git a/classes/query_builder.php b/classes/query_builder.php index 72f9cbe..fda1979 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -1247,11 +1247,116 @@ class Query_Builder { return $res; } + // -------------------------------------------------------------------------- + // ! Query Returning Methods + // -------------------------------------------------------------------------- + + /** + * Returns the generated 'select' sql query + * + * @param string $table + * @param bool $reset + * @return string + */ + public function get_compiled_select($table='', $reset=TRUE) + { + // Set the table + if ( ! empty($table)) + { + $this->from($table); + } + + $sql = $this->_compile(); + + // Reset the query builder for the next query + if ($reset) + { + $this->_reset(); + } + + return $sql; + } + + // -------------------------------------------------------------------------- + + /** + * Returns the generated 'insert' sql query + * + * @param string $table + * @param bool $reset + * @return string + */ + public function get_compiled_insert($table, $reset=TRUE) + { + $sql = $this->_compile("insert", $table); + + // Reset the query builder for the next query + if ($reset) + { + $this->_reset(); + } + + return $sql; + } + + // -------------------------------------------------------------------------- + + /** + * Returns the generated 'insert' sql query + * + * @param string $table + * @param bool $reset + * @return string + */ + public function get_compiled_update($table='', $reset=TRUE) + { + $sql = $this->_compile('update', $table); + + // Reset the query builder for the next query + if ($reset) + { + $this->_reset(); + } + + return $sql; + } + + // -------------------------------------------------------------------------- + + /** + * Returns the generated 'insert' sql query + * + * @param string $table + * @param bool $reset + * @return string + */ + public function get_compiled_delete($table="", $reset=TRUE) + { + $sql = $this->_compile("delete", $table); + + // Reset the query builder for the next query + if ($reset) + { + $this->_reset(); + } + + return $sql; + } // -------------------------------------------------------------------------- // ! Miscellaneous Methods // -------------------------------------------------------------------------- + /** + * Resets the query builder for the next query + */ + public function reset_query() + { + $this->_reset(); + } + + // -------------------------------------------------------------------------- + /** * Calls a function further down the inheritence chain * @@ -1286,7 +1391,8 @@ class Query_Builder { // Skip properties that are needed for every query if (in_array($name, array( 'db', - 'sql' + 'sql', + 'queries', ))) { continue; diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 78a1095..0644fd9 100644 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ