From 559f3ab13aa3b741b492cb70dd69a05acfc343ef Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 13 Sep 2012 15:44:57 +0000 Subject: [PATCH] Update readme and added 'get_compiled_' methods to query builder --- README.md | 2 +- classes/query_builder.php | 108 +++++++++++++++++++++++++++++++++- tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 3 files changed, 108 insertions(+), 2 deletions(-) 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 78a109567a1c9b6aaa9a6a65c767a51bc3e2962b..0644fd99807573ed9e1a70c45f0657e35d54dcd5 100644 GIT binary patch delta 583 zcmZ9IJ4*vW5XWaP$vrZJtS?Y(l8YfKhzST{DbYqzF@#_xLHr7K3WvpZma>SAf~_FF zQmKUs7J|JTa)vVxjl@Q<5!}mV5wgS1%zxRL-_BZA#gm^twYL1I7_=&1uGlb!b(dk z@pa7^4~b%DV2se%ne=l?6rFh6clk5Ye2+(s~;v7541JPC}C7#)W@iw(Ey`CMw=LIX0+vm zhWwN~Sb=yb*kVO`Ltnx5YAR$^Q`oe>V4*iz-t(jlZqR_D7KfPD1-VEPVi5zn)i{7E zSXJRWqQgU2hof*3Hbq_z8!#v8qoO`0vKs|d;TNr?BF+X|3u2votxSNBpK5_$JmEAc z@Ms0IB29i`g0EJv58X~L6#iMn47uc`GInt78I6n_696$rbV>F%u+Qb(6*vuA$J08V z)^WAny#EDzh{LzaI6=<&&I@KU@||mOJ(8tYvR3mDup2zK=dt<9t60zW*1LPfKJh>P uC_H&S^M=`ke5ceslBL(?$8UJbcZ(R~8}B$sfS