From 0c147b365a8bb2e584d4f957d4d0761f02bebe56 Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Fri, 26 Aug 2011 02:29:31 -0400
Subject: Added get_compiled_select(), get_compiled_insert(),
get_compiled_update(), get_compiled_delete(), and reset_query() methods. to
the Active Record class.
---
system/database/DB_active_rec.php | 257 +++++++++++++++++++++++++++++++++-----
1 file changed, 223 insertions(+), 34 deletions(-)
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 37d162bc1..8c801cd62 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -28,6 +28,9 @@
*/
class CI_DB_active_record extends CI_DB_driver {
+ private $return_delete_sql = FALSE;
+ private $reset_delete_data = FALSE;
+
var $ar_select = array();
var $ar_distinct = FALSE;
var $ar_from = array();
@@ -196,7 +199,7 @@ class CI_DB_active_record extends CI_DB_driver {
$alias = $this->_create_alias_from_table(trim($select));
}
- $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
+ $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias;
$this->ar_select[] = $sql;
@@ -660,12 +663,8 @@ class CI_DB_active_record extends CI_DB_driver {
$prefix = (count($this->ar_like) == 0) ? '' : $type;
$v = $this->escape_like_str($v);
-
- if ($side == 'none')
- {
- $like_statement = $prefix." $k $not LIKE '{$v}'";
- }
- elseif ($side == 'before')
+
+ if ($side == 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
@@ -874,11 +873,11 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function limit($value, $offset = '')
{
- $this->ar_limit = (int) $value;
+ $this->ar_limit = $value;
if ($offset != '')
{
- $this->ar_offset = (int) $offset;
+ $this->ar_offset = $offset;
}
return $this;
@@ -931,6 +930,38 @@ class CI_DB_active_record extends CI_DB_driver {
return $this;
}
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get SELECT query string
+ *
+ * Compiles a SELECT query string and returns the sql.
+ *
+ * @access public
+ * @param string the table name to select from (optional)
+ * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
+ * @return string
+ */
+ public function get_compiled_select($table = '', $reset = TRUE)
+ {
+ if ($table != '')
+ {
+ $this->_track_aliases($table);
+ $this->from($table);
+ }
+
+ $select = $this->_compile_select();
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_select();
+ }
+
+ return $select;
+ }
+
// --------------------------------------------------------------------
@@ -1148,6 +1179,36 @@ class CI_DB_active_record extends CI_DB_driver {
return $this;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get INSERT query string
+ *
+ * Compiles an insert query and returns the sql
+ *
+ * @access public
+ * @param string the table to insert into
+ * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @return string
+ */
+ public function get_compiled_insert($table = '', $reset = TRUE)
+ {
+ if ($this->_validate_insert($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ $sql = $this->_insert($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_write();
+ }
+
+ return $sql;
+ }
+
// --------------------------------------------------------------------
@@ -1156,17 +1217,45 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an insert string and runs the query
*
+ * @access public
* @param string the table to insert data into
* @param array an associative array of insert values
* @return object
*/
- function insert($table = '', $set = NULL)
+ public function insert($table = '', $set = NULL)
{
if ( ! is_null($set))
{
$this->set($set);
}
+
+ if ($this->_validate_insert($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ $sql = $this->_insert($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Validate Insert
+ *
+ * This method is used by both insert() and get_compiled_insert() to
+ * validate that the there data is actually being set and that table
+ * has been chosen to be inserted into.
+ *
+ * @access public
+ * @param string the table to insert data into
+ * @return string
+ */
+ protected function _validate_insert($table = '')
+ {
if (count($this->ar_set) == 0)
{
if ($this->db_debug)
@@ -1186,14 +1275,13 @@ class CI_DB_active_record extends CI_DB_driver {
}
return FALSE;
}
-
- $table = $this->ar_from[0];
}
-
- $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
-
- $this->_reset_write();
- return $this->query($sql);
+ else
+ {
+ $this->ar_from[0] = $table;
+ }
+
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -1242,7 +1330,41 @@ class CI_DB_active_record extends CI_DB_driver {
$this->_reset_write();
return $this->query($sql);
}
+
+
+ // --------------------------------------------------------------------
+ /**
+ * Get UPDATE query string
+ *
+ * Compiles an update query and returns the sql
+ *
+ * @access public
+ * @param string the table to update
+ * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @return string
+ */
+ public function get_compiled_update($table = '', $reset = TRUE)
+ {
+ // Combine any cached components with the current statements
+ $this->_merge_cache();
+
+ if ($this->_validate_update($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_write();
+ }
+
+ return $sql;
+ }
+
+
// --------------------------------------------------------------------
/**
@@ -1265,6 +1387,43 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set($set);
}
+ if ($this->_validate_update($table) === FALSE)
+ {
+ return FALSE;
+ }
+
+ if ($where != NULL)
+ {
+ $this->where($where);
+ }
+
+ if ($limit != NULL)
+ {
+ $this->limit($limit);
+ }
+
+ $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
+
+ $this->_reset_write();
+ return $this->query($sql);
+ }
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Validate Update
+ *
+ * This method is used by both update() and get_compiled_update() to
+ * validate that data is actually being set and that a table has been
+ * chosen to be update.
+ *
+ * @access public
+ * @param string the table to update data on
+ * @return string
+ */
+ protected function _validate_update($table = '')
+ {
if (count($this->ar_set) == 0)
{
if ($this->db_debug)
@@ -1284,24 +1443,11 @@ class CI_DB_active_record extends CI_DB_driver {
}
return FALSE;
}
-
- $table = $this->ar_from[0];
}
-
- if ($where != NULL)
- {
- $this->where($where);
- }
-
- if ($limit != NULL)
+ else
{
- $this->limit($limit);
+ $this->ar_from[0] = $table;
}
-
- $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit);
-
- $this->_reset_write();
- return $this->query($sql);
}
@@ -1326,7 +1472,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($this->db_debug)
{
- return $this->display_error('db_must_use_index');
+ return $this->display_error('db_myst_use_index');
}
return FALSE;
@@ -1503,7 +1649,27 @@ class CI_DB_active_record extends CI_DB_driver {
return $this->query($sql);
}
+
+ // --------------------------------------------------------------------
+ /**
+ * Get DELETE query string
+ *
+ * Compiles a delete query string and returns the sql
+ *
+ * @access public
+ * @param string the table to delete from
+ * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @return string
+ */
+ public function get_compiled_delete($table = '', $reset = TRUE)
+ {
+ $this->return_delete_sql = TRUE;
+ $sql = $this->delete($table, '', NULL, $reset);
+ $this->return_delete_sql = FALSE;
+ return $sql;
+ }
+
// --------------------------------------------------------------------
/**
@@ -1576,9 +1742,15 @@ class CI_DB_active_record extends CI_DB_driver {
{
$this->_reset_write();
}
+
+ if ($this->return_delete_sql === true)
+ {
+ return $sql;
+ }
return $this->query($sql);
}
+
// --------------------------------------------------------------------
@@ -1659,6 +1831,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
}
+
// --------------------------------------------------------------------
@@ -1965,6 +2138,22 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_no_escape = $this->ar_cache_no_escape;
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Reset Active Record values.
+ *
+ * Publicly-visible method to reset the AR values.
+ *
+ * @access public
+ * @return void
+ */
+ public function reset_query()
+ {
+ $this->_reset_select();
+ $this->_reset_write();
+ }
// --------------------------------------------------------------------
@@ -2042,4 +2231,4 @@ class CI_DB_active_record extends CI_DB_driver {
}
/* End of file DB_active_rec.php */
-/* Location: ./system/database/DB_active_rec.php */
\ No newline at end of file
+/* Location: ./system/database/DB_active_rec.php */
--
cgit v1.2.3-24-g4f1b
From 0a3176b56ad069643c400302b1baf9a2c90267ad Mon Sep 17 00:00:00 2001
From: kylefarris
Date: Fri, 26 Aug 2011 02:37:52 -0400
Subject: Small formatting fix.
---
system/database/DB_active_rec.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 8c801cd62..c36e20348 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -947,7 +947,7 @@ class CI_DB_active_record extends CI_DB_driver {
public function get_compiled_select($table = '', $reset = TRUE)
{
if ($table != '')
- {
+ {
$this->_track_aliases($table);
$this->from($table);
}
--
cgit v1.2.3-24-g4f1b
From c1ee04b4532124cbfaff69f50c996af64f63ac51 Mon Sep 17 00:00:00 2001
From: kylefarris
Date: Fri, 26 Aug 2011 02:39:54 -0400
Subject: Updated the changelog to reflect new Active Record methods:
get_compiled_select(), get_compiled_delete(), get_compiled_insert(),
get_compiled_update(), and reset_query().
---
user_guide/changelog.html | 27 ++-------------------------
1 file changed, 2 insertions(+), 25 deletions(-)
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index bb80ab8b8..5fff21f7b 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -66,23 +66,18 @@ Change Log
General Changes
- Callback validation rules can now accept parameters like any other validation rule.
- - Ability to log certain error types, not all under a threshold.
- - Added html_escape() to Common functions to escape HTML output for preventing XSS.
Helpers
- Added increment_string() to String Helper to turn "foo" into "foo-1" or "foo-1" into "foo-2".
- - Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65)
Database
- - Added a CUBRID driver to the Database Driver. Thanks to the CUBRID team for supplying this patch.
+ - Added a CUBRID driver to the Database Driver. Thanks to the CUBRID team for supplying this patch.
- Typecast limit and offset in the Database Driver to integers to avoid possible injection.
- -
- Added additional option 'none' for the optional third argument for $this->db->like() in the Database Driver.
-
+ - Added new Active Record methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
Libraries
@@ -91,13 +86,6 @@ Change Log
Added support to set an optional parameter in your callback rules of validation using the Form Validation Library.
Added a Migration Library to assist with applying incremental updates to your database schema.
Driver children can be located in any package path.
- Added max_filename_increment config setting for Upload library.
- CI_Loader::_ci_autoloader() is now a protected method.
-
-
- Core
-
- - Changed private functions in CI_URI to protected so MY_URI can override them.
@@ -108,11 +96,6 @@ Change Log
If a config class was loaded first then a library with the same name is loaded, the config would be ignored.
Fixed a bug (Reactor #19) where 1) the 404_override route was being ignored in some cases, and 2) auto-loaded libraries were not available to the 404_override controller when a controller existed but the requested method did not.
Fixed a bug (Reactor #89) where MySQL export would fail if the table had hyphens or other non alphanumeric/underscore characters.
- Fixed a bug (#200) where MySQL queries would be malformed after calling count_all() then db->get()
- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
- Fixed a bug (#160) - Removed unneeded array copy in the file cache driver.
- Fixed a bug (#150) - field_data() now correctly returns column length.
- Fixed a bug (#8) - load_class() now looks for core classes in APPPATH first, allowing them to be replaced.
Version 2.0.3
@@ -132,13 +115,7 @@ Change Log
Visual updates to the welcome_message view file and default error templates. Thanks to danijelb for the pull request.
Added insert_batch() function to the PostgreSQL database driver. Thanks to epallerols for the patch.
Added "application/x-csv" to mimes.php.
- Added CSRF protection URI whitelisting.
Fixed a bug where Email library attachments with a "." in the name would using invalid MIME-types.
- Added support for pem,p10,p12,p7a,p7c,p7m,p7r,p7s,crt,crl,der,kdb,rsa,cer,sst,csr Certs to mimes.php.
- Added support pgp,gpg to mimes.php.
- Added support 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
- Added support m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
-
Helpers
--
cgit v1.2.3-24-g4f1b
From 0f35b6e8fd4640915b1793f2e531867b859f1e3d Mon Sep 17 00:00:00 2001
From: kylefarris
Date: Fri, 26 Aug 2011 02:40:56 -0400
Subject: Updated the Active Record documentation to reflect new publicly
visible Active Record methods: get_compiled_select(), get_compiled_delete(),
get_compiled_insert(), get_compiled_update(), and reset_query().
---
user_guide/database/active_record.html | 113 +++++++++++++++++++++++++++++----
1 file changed, 100 insertions(+), 13 deletions(-)
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index 92d9614d5..d53630402 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -73,6 +73,7 @@ is generated by each database adapter. It also allows for safer queries, since
Deleting Data
Method Chaining
Active Record Caching
+Reset Active Record
Selecting Data
@@ -107,6 +108,27 @@ foreach ($query->result() as $row)
Please visit the result functions page for a full discussion regarding result generation.
+$this->db->get_compiled_select();
+
+Compiles the selection query just like $this->db->get() but does not run the query. This method simply returns the SQL query as a string.
+
+$sql = $this->db->get_compiled_select('mytable');
+echo $sql;
+
+// Produces string: SELECT * FROM mytable
+
+The second parameter enables you to set whether or not the active record query will be reset (by default it will be—just like $this->db->get()):
+
+echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
+
+// Produces string: SELECT * FROM mytable LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)
+
+echo $this->db->select('title, content, date')->get_compiled_select();
+
+// Produces string: SELECT title, content, date FROM mytable
+
+The key thing to notice in the above example is that the second query did not utlize $this->db->from() and did not pass a table name into the first parameter. The reason for this outcome is because the query has not been executed using $this->db->get() which resets values or reset directly using $this-db->reset_query().
+
$this->db->get_where();
@@ -334,13 +356,6 @@ $this->db->or_where('id >', $id);
$this->db->like('title', 'match', 'both');
// Produces: WHERE title LIKE '%match%'
-If you do not want to use the wildcard (%) you can pass to the optional third argument the option 'none'.
-
-
- $this->db->like('title', 'match', 'none');
-// Produces: WHERE title LIKE 'match'
-
-
Associative array method:
@@ -528,11 +543,41 @@ $this->db->insert('mytable', $object);
Note: All values are escaped automatically producing safer queries.
+
+$this->db->get_compiled_insert();
+
+Compiles the insertion query just like $this->db->insert() but does not run the query. This method simply returns the SQL query as a string.
+
+
+$data = array(
+ 'title' => 'My title' ,
+ 'name' => 'My Name' ,
+ 'date' => 'My date'
+);
+
+$sql = $this->db->set($data)->get_compiled_insert('mytable');
+echo $sql;
+
+// Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
+
+The second parameter enables you to set whether or not the active record query will be reset (by default it will be—just like $this->db->insert()):
+
+echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE);
+
+// Produces string: INSERT INTO mytable (title) VALUES ('My Title')
+
+echo $this->db->set('content', 'My Content')->get_compiled_insert();
+
+// Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content')
+
+The key thing to notice in the above example is that the second query did not utlize $this->db->from() nor did it pass a table name into the first parameter. The reason this worked is because the query has not been executed using $this->db->insert() which resets values or reset directly using $this-db->reset_query().
+
+
$this->db->insert_batch();
Generates an insert string based on the data you supply, and runs the query. You can either pass an
array or an object to the function. Here is an example using an array:
-
+
$data = array(
array(
'title' => 'My title' ,
@@ -544,7 +589,7 @@ $data = array(
'name' => 'Another Name' ,
'date' => 'Another date'
)
-);
+);
$this->db->update_batch('mytable', $data);
@@ -670,6 +715,14 @@ You can optionally pass this information directly into the update function as a
You may also use the $this->db->set() function described above when performing updates.
+
+$this->db->get_compiled_update();
+
+This works exactly the same way as $this->db->get_compiled_insert() except that it produces an UPDATE SQL string instead of an INSERT SQL string.
+
+For more information view documentation for get_compiled_insert().
+
+
Deleting Data
@@ -699,11 +752,22 @@ the data to the second parameter of the function:
$this->db->where('id', '5');
$this->db->delete($tables);
If you want to delete all data from a table, you can use the truncate() function, or empty_table().
+
+
+$this->db->get_compiled_delete();
+This works exactly the same way as $this->db->get_compiled_insert() except that it produces a DELETE SQL string instead of an INSERT SQL string.
+For more information view documentation for get_compiled_insert().
+
+
+
$this->db->empty_table();
Generates a delete SQL string and runs the query. $this->db->empty_table('mytable');
// Produces
// DELETE FROM mytable
+
+
+
$this->db->truncate();
Generates a truncate SQL string and runs the query.
$this->db->from('mytable');
@@ -716,7 +780,9 @@ $this->db->truncate('mytable');
Note: If the TRUNCATE command isn't available, truncate() will execute as "DELETE FROM table".
- Method Chaining
+
+
+Method Chaining
Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:
@@ -727,9 +793,9 @@ $query = $this->db->get();
Note: Method chaining only works with PHP 5.
-
+
- Active Record Caching
+Active Record Caching
While not "true" caching, Active Record enables you to save (or "cache") certain parts of your queries for reuse at a later point in your script's execution. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.
@@ -769,7 +835,28 @@ $this->db->get('tablename');
//Generates: SELECT `field2` FROM (`tablename`)
Note: The following statements can be cached: select, from, join, where, like, group_by, having, order_by, set
-
+
+
+
+Reset Active Record
+
+Resetting Active Record allows you to start fresh with your query without executing it first using a method like $this->db->get() or $this->db->insert(). Just like the methods that execute a query, this will not reset items you've cached using Active Record Caching.
+This is useful in situations where you are using Active Record to generate SQL (ex. $this->db->get_compiled_select()) but then choose to, for instance, run the query:
+
+
+// Note that the second parameter of the get_compiled_select method is FALSE
+$sql = $this->db->select(array('field1','field2'))->where('field3',5)->get_compiled_select('mytable', FALSE);
+
+// ...
+// Do something crazy with the SQL code... like add it to a cron script for later execution or something...
+// ...
+
+$data = $this->db->get()->result_array();
+
+// Would execute and return an array of results of the following query:
+// SELECT field1, field1 from mytable where field3 = 5;
+
+
--
cgit v1.2.3-24-g4f1b
From 7611601875b619d8201633cf16a790b356182039 Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Wed, 31 Aug 2011 11:17:48 -0400
Subject: Fixed some items based on code comments by gaker.
---
system/database/DB_active_rec.php | 96 ++++++++++++++++++++-------------------
1 file changed, 49 insertions(+), 47 deletions(-)
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index c36e20348..46202224b 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -28,42 +28,42 @@
*/
class CI_DB_active_record extends CI_DB_driver {
- private $return_delete_sql = FALSE;
- private $reset_delete_data = FALSE;
+ protected $return_delete_sql = FALSE;
+ protected $reset_delete_data = FALSE;
- var $ar_select = array();
- var $ar_distinct = FALSE;
- var $ar_from = array();
- var $ar_join = array();
- var $ar_where = array();
- var $ar_like = array();
- var $ar_groupby = array();
- var $ar_having = array();
- var $ar_keys = array();
- var $ar_limit = FALSE;
- var $ar_offset = FALSE;
- var $ar_order = FALSE;
- var $ar_orderby = array();
- var $ar_set = array();
- var $ar_wherein = array();
- var $ar_aliased_tables = array();
- var $ar_store_array = array();
+ protected $ar_select = array();
+ protected $ar_distinct = FALSE;
+ protected $ar_from = array();
+ protected $ar_join = array();
+ protected $ar_where = array();
+ protected $ar_like = array();
+ protected $ar_groupby = array();
+ protected $ar_having = array();
+ protected $ar_keys = array();
+ protected $ar_limit = FALSE;
+ protected $ar_offset = FALSE;
+ protected $ar_order = FALSE;
+ protected $ar_orderby = array();
+ protected $ar_set = array();
+ protected $ar_wherein = array();
+ protected $ar_aliased_tables = array();
+ protected $ar_store_array = array();
// Active Record Caching variables
- var $ar_caching = FALSE;
- var $ar_cache_exists = array();
- var $ar_cache_select = array();
- var $ar_cache_from = array();
- var $ar_cache_join = array();
- var $ar_cache_where = array();
- var $ar_cache_like = array();
- var $ar_cache_groupby = array();
- var $ar_cache_having = array();
- var $ar_cache_orderby = array();
- var $ar_cache_set = array();
+ protected $ar_caching = FALSE;
+ protected $ar_cache_exists = array();
+ protected $ar_cache_select = array();
+ protected $ar_cache_from = array();
+ protected $ar_cache_join = array();
+ protected $ar_cache_where = array();
+ protected $ar_cache_like = array();
+ protected $ar_cache_groupby = array();
+ protected $ar_cache_having = array();
+ protected $ar_cache_orderby = array();
+ protected $ar_cache_set = array();
- var $ar_no_escape = array();
- var $ar_cache_no_escape = array();
+ protected $ar_no_escape = array();
+ protected $ar_cache_no_escape = array();
// --------------------------------------------------------------------
@@ -873,11 +873,11 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function limit($value, $offset = '')
{
- $this->ar_limit = $value;
+ $this->ar_limit = (int) $value;
if ($offset != '')
{
- $this->ar_offset = $offset;
+ $this->ar_offset = (int) $offset;
}
return $this;
@@ -931,7 +931,6 @@ class CI_DB_active_record extends CI_DB_driver {
return $this;
}
-
// --------------------------------------------------------------------
/**
@@ -962,7 +961,6 @@ class CI_DB_active_record extends CI_DB_driver {
return $select;
}
-
// --------------------------------------------------------------------
/**
@@ -1199,7 +1197,13 @@ class CI_DB_active_record extends CI_DB_driver {
return FALSE;
}
- $sql = $this->_insert($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
+ $sql = $this->_insert(
+ $this->_protect_identifiers(
+ $this->ar_from[0], TRUE, NULL, FALSE
+ ),
+ array_keys($this->ar_set),
+ array_values($this->ar_set)
+ );
if ($reset === TRUE)
{
@@ -1208,7 +1212,6 @@ class CI_DB_active_record extends CI_DB_driver {
return $sql;
}
-
// --------------------------------------------------------------------
@@ -1234,13 +1237,18 @@ class CI_DB_active_record extends CI_DB_driver {
return FALSE;
}
- $sql = $this->_insert($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
+ $sql = $this->_insert(
+ $this->_protect_identifiers(
+ $this->ar_from[0], TRUE, NULL, FALSE
+ ),
+ array_keys($this->ar_set),
+ array_values($this->ar_set)
+ );
$this->_reset_write();
return $this->query($sql);
}
-
// --------------------------------------------------------------------
/**
@@ -1331,7 +1339,6 @@ class CI_DB_active_record extends CI_DB_driver {
return $this->query($sql);
}
-
// --------------------------------------------------------------------
/**
@@ -1364,7 +1371,6 @@ class CI_DB_active_record extends CI_DB_driver {
return $sql;
}
-
// --------------------------------------------------------------------
/**
@@ -1407,7 +1413,6 @@ class CI_DB_active_record extends CI_DB_driver {
$this->_reset_write();
return $this->query($sql);
}
-
// --------------------------------------------------------------------
@@ -1449,8 +1454,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_from[0] = $table;
}
}
-
-
+
// --------------------------------------------------------------------
/**
@@ -1751,7 +1755,6 @@ class CI_DB_active_record extends CI_DB_driver {
return $this->query($sql);
}
-
// --------------------------------------------------------------------
/**
@@ -1832,7 +1835,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
-
// --------------------------------------------------------------------
/**
--
cgit v1.2.3-24-g4f1b
From 2de2fa022253597c8f5c807218be3aa05fac340e Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Wed, 31 Aug 2011 11:52:20 -0400
Subject: Merged changes with development.
---
system/database/DB_active_rec.php | 12 ++++++++----
user_guide/changelog.html | 20 +++++++++++++++++++-
user_guide/database/active_record.html | 9 +++++++--
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 46202224b..076cc7ce4 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -199,7 +199,7 @@ class CI_DB_active_record extends CI_DB_driver {
$alias = $this->_create_alias_from_table(trim($select));
}
- $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias;
+ $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias));
$this->ar_select[] = $sql;
@@ -664,7 +664,11 @@ class CI_DB_active_record extends CI_DB_driver {
$v = $this->escape_like_str($v);
- if ($side == 'before')
+ if ($side == 'none')
+ {
+ $like_statement = $prefix." $k $not LIKE '{$v}'";
+ }
+ elseif ($side == 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
@@ -1476,7 +1480,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($this->db_debug)
{
- return $this->display_error('db_myst_use_index');
+ return $this->display_error('db_must_use_index');
}
return FALSE;
@@ -2233,4 +2237,4 @@ class CI_DB_active_record extends CI_DB_driver {
}
/* End of file DB_active_rec.php */
-/* Location: ./system/database/DB_active_rec.php */
+/* Location: ./system/database/DB_active_rec.php */
\ No newline at end of file
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 5fff21f7b..b2a892b54 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -66,17 +66,23 @@ Change Log
General Changes
- Callback validation rules can now accept parameters like any other validation rule.
+ - Ability to log certain error types, not all under a threshold.
+ - Added html_escape() to Common functions to escape HTML output for preventing XSS.
Helpers
- Added increment_string() to String Helper to turn "foo" into "foo-1" or "foo-1" into "foo-2".
+ - Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65)
Database
- - Added a CUBRID driver to the Database Driver. Thanks to the CUBRID team for supplying this patch.
+ - Added a CUBRID driver to the Database Driver. Thanks to the CUBRID team for supplying this patch.
- Typecast limit and offset in the Database Driver to integers to avoid possible injection.
+ -
+ Added additional option 'none' for the optional third argument for $this->db->like() in the Database Driver.
+
- Added new Active Record methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
@@ -86,6 +92,8 @@ Change Log
Added support to set an optional parameter in your callback rules of validation using the Form Validation Library.
Added a Migration Library to assist with applying incremental updates to your database schema.
Driver children can be located in any package path.
+ Added max_filename_increment config setting for Upload library.
+ CI_Loader::_ci_autoloader() is now a protected method.
@@ -96,6 +104,11 @@ Change Log
If a config class was loaded first then a library with the same name is loaded, the config would be ignored.
Fixed a bug (Reactor #19) where 1) the 404_override route was being ignored in some cases, and 2) auto-loaded libraries were not available to the 404_override controller when a controller existed but the requested method did not.
Fixed a bug (Reactor #89) where MySQL export would fail if the table had hyphens or other non alphanumeric/underscore characters.
+ Fixed a bug (#200) where MySQL queries would be malformed after calling count_all() then db->get()
+ Fixed a bug (#181) where a mis-spelling was in the form validation language file.
+ Fixed a bug (#160) - Removed unneeded array copy in the file cache driver.
+ Fixed a bug (#150) - field_data() now correctly returns column length.
+ Fixed a bug (#8) - load_class() now looks for core classes in APPPATH first, allowing them to be replaced.
Version 2.0.3
@@ -115,7 +128,12 @@ Change Log
Visual updates to the welcome_message view file and default error templates. Thanks to danijelb for the pull request.
Added insert_batch() function to the PostgreSQL database driver. Thanks to epallerols for the patch.
Added "application/x-csv" to mimes.php.
+ Added CSRF protection URI whitelisting.
Fixed a bug where Email library attachments with a "." in the name would using invalid MIME-types.
+ Added support for pem,p10,p12,p7a,p7c,p7m,p7r,p7s,crt,crl,der,kdb,rsa,cer,sst,csr Certs to mimes.php.
+ Added support pgp,gpg to mimes.php.
+ Added support 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
+ Added support m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
Helpers
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index d53630402..874dda58e 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -337,7 +337,6 @@ $this->db->or_where('id >', $id);
Simple key/value method:
$this->db->like('title', 'match');
-
// Produces: WHERE title LIKE '%match%'
If you use multiple function calls they will be chained together with AND between them:
@@ -356,6 +355,13 @@ $this->db->or_where('id >', $id);
$this->db->like('title', 'match', 'both');
// Produces: WHERE title LIKE '%match%'
+If you do not want to use the wildcard (%) you can pass to the optional third argument the option 'none'.
+
+
+ $this->db->like('title', 'match', 'none');
+// Produces: WHERE title LIKE 'match'
+
+
Associative array method:
@@ -794,7 +800,6 @@ $query = $this->db->get();
Note: Method chaining only works with PHP 5.
-
Active Record Caching
While not "true" caching, Active Record enables you to save (or "cache") certain parts of your queries for reuse at a later point in your script's execution. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.
--
cgit v1.2.3-24-g4f1b
From c4234c1ad57cf0b4545c6bc553ce3c9781625505 Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Wed, 31 Aug 2011 11:57:35 -0400
Subject: Fixed some formatting and stuff.
---
user_guide/changelog.html | 38 +++++++++++++++++-----------------
user_guide/database/active_record.html | 1 +
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index b2a892b54..a47880e68 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -66,23 +66,23 @@ Change Log
General Changes
- Callback validation rules can now accept parameters like any other validation rule.
- - Ability to log certain error types, not all under a threshold.
- - Added html_escape() to Common functions to escape HTML output for preventing XSS.
+ - Ability to log certain error types, not all under a threshold.
+ - Added html_escape() to Common functions to escape HTML output for preventing XSS.
Helpers
- Added increment_string() to String Helper to turn "foo" into "foo-1" or "foo-1" into "foo-2".
- - Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65)
+ - Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65)
Database
- Added a CUBRID driver to the Database Driver. Thanks to the CUBRID team for supplying this patch.
- Typecast limit and offset in the Database Driver to integers to avoid possible injection.
- -
- Added additional option 'none' for the optional third argument for $this->db->like() in the Database Driver.
-
+ -
+ Added additional option 'none' for the optional third argument for $this->db->like() in the Database Driver.
+
- Added new Active Record methods that return the SQL string of queries without executing them: get_compiled_select(), get_compiled_insert(), get_compiled_update(), get_compiled_delete().
@@ -92,8 +92,8 @@ Change Log
Added support to set an optional parameter in your callback rules of validation using the Form Validation Library.
Added a Migration Library to assist with applying incremental updates to your database schema.
Driver children can be located in any package path.
- Added max_filename_increment config setting for Upload library.
- CI_Loader::_ci_autoloader() is now a protected method.
+ Added max_filename_increment config setting for Upload library.
+ CI_Loader::_ci_autoloader() is now a protected method.
@@ -104,11 +104,11 @@ Change Log
If a config class was loaded first then a library with the same name is loaded, the config would be ignored.
Fixed a bug (Reactor #19) where 1) the 404_override route was being ignored in some cases, and 2) auto-loaded libraries were not available to the 404_override controller when a controller existed but the requested method did not.
Fixed a bug (Reactor #89) where MySQL export would fail if the table had hyphens or other non alphanumeric/underscore characters.
- Fixed a bug (#200) where MySQL queries would be malformed after calling count_all() then db->get()
- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
- Fixed a bug (#160) - Removed unneeded array copy in the file cache driver.
- Fixed a bug (#150) - field_data() now correctly returns column length.
- Fixed a bug (#8) - load_class() now looks for core classes in APPPATH first, allowing them to be replaced.
+ Fixed a bug (#200) where MySQL queries would be malformed after calling count_all() then db->get()
+ Fixed a bug (#181) where a mis-spelling was in the form validation language file.
+ Fixed a bug (#160) - Removed unneeded array copy in the file cache driver.
+ Fixed a bug (#150) - field_data() now correctly returns column length.
+ Fixed a bug (#8) - load_class() now looks for core classes in APPPATH first, allowing them to be replaced.
Version 2.0.3
@@ -128,12 +128,12 @@ Change Log
Visual updates to the welcome_message view file and default error templates. Thanks to danijelb for the pull request.
Added insert_batch() function to the PostgreSQL database driver. Thanks to epallerols for the patch.
Added "application/x-csv" to mimes.php.
- Added CSRF protection URI whitelisting.
+ Added CSRF protection URI whitelisting.
Fixed a bug where Email library attachments with a "." in the name would using invalid MIME-types.
- Added support for pem,p10,p12,p7a,p7c,p7m,p7r,p7s,crt,crl,der,kdb,rsa,cer,sst,csr Certs to mimes.php.
- Added support pgp,gpg to mimes.php.
- Added support 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
- Added support m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
+ Added support for pem,p10,p12,p7a,p7c,p7m,p7r,p7s,crt,crl,der,kdb,rsa,cer,sst,csr Certs to mimes.php.
+ Added support pgp,gpg to mimes.php.
+ Added support 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
+ Added support m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
Helpers
@@ -222,7 +222,7 @@ Hg Tag: v2.0.1
Added $config['cookie_secure'] to the config file to allow requiring a secure (HTTPS) in order to set cookies.
Added the constant CI_CORE to help differentiate between Core: TRUE and Reactor: FALSE.
Added an ENVIRONMENT constant in index.php, which affects PHP error reporting settings, and optionally,
- which configuration files are loaded (see below). Read more on the Handling Environments page.
+ which configuration files are loaded (see below). Read more on the Handling Environments page.
Added support for environment-specific configuration files.
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index 874dda58e..aa888d28f 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -337,6 +337,7 @@ $this->db->or_where('id >', $id);
Simple key/value method:
$this->db->like('title', 'match');
+
// Produces: WHERE title LIKE '%match%'
If you use multiple function calls they will be chained together with AND between them:
--
cgit v1.2.3-24-g4f1b
From 81ef70f32951de5f7b4196c1db9ce969133362dd Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Wed, 31 Aug 2011 11:59:12 -0400
Subject: One more formatting fix.
---
system/database/DB_active_rec.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 076cc7ce4..59cd1972c 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -664,11 +664,11 @@ class CI_DB_active_record extends CI_DB_driver {
$v = $this->escape_like_str($v);
- if ($side == 'none')
- {
- $like_statement = $prefix." $k $not LIKE '{$v}'";
- }
- elseif ($side == 'before')
+ if ($side == 'none')
+ {
+ $like_statement = $prefix." $k $not LIKE '{$v}'";
+ }
+ elseif ($side == 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
--
cgit v1.2.3-24-g4f1b
From 2873ac64f1476551cc546f30ec6187e580cc8155 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 13 Oct 2011 11:23:44 -0300
Subject: Added simple backtrace to php error file
---
application/errors/error_php.php | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index f085c2037..279556a98 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -6,5 +6,14 @@
Message:
Filename:
Line Number:
-
+Backtrace:
+
+
+
+ File:
+ Line:
+ Function:
+
+ endif ?>
+ endforeach ?>
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From bb117677ab5a6096168f7c052853c94ecba19339 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 13 Oct 2011 11:52:02 -0300
Subject: Fixed code style issue
---
application/errors/error_php.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index 279556a98..cebf91724 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -8,7 +8,7 @@
Line Number:
Backtrace:
-
+
File:
Line:
--
cgit v1.2.3-24-g4f1b
From 233b671f0f704ad75685ef9845ae9267643dd77d Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 13 Oct 2011 11:56:44 -0300
Subject: Added backtrace contstant
---
index.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/index.php b/index.php
index c50cfed43..312fbfb1d 100644
--- a/index.php
+++ b/index.php
@@ -34,6 +34,7 @@ if (defined('ENVIRONMENT'))
{
case 'development':
error_reporting(-1);
+ define('SHOW_ERROR_BACKTRACE', TRUE);
break;
case 'testing':
--
cgit v1.2.3-24-g4f1b
From 5600828101627a76768e4f1edbb0197d11885318 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Thu, 13 Oct 2011 11:59:44 -0300
Subject: Switch debug backtrace based on SHOW_ERROR_BACKTRACE contstant
---
application/errors/error_php.php | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index cebf91724..cf6cb9fac 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -6,14 +6,16 @@
Message:
Filename:
Line Number:
-Backtrace:
-
-
-
- File:
- Line:
- Function:
-
- endif ?>
- endforeach ?>
+
+ Backtrace:
+
+
+
+ File:
+ Line:
+ Function:
+
+ endif ?>
+ endforeach ?>
+
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From db46d02ac23b8e0bc2416e197494d3b795b57530 Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Fri, 14 Oct 2011 15:17:09 -0400
Subject: trying to resolve some merge issues
---
application/config/migration.php | 82 ++++++++++++++++++++--------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/application/config/migration.php b/application/config/migration.php
index dba870010..d88554d91 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -1,42 +1,42 @@
-migration->latest() this is the version that schema will
-| be upgraded / downgraded to.
-|
-*/
-$config['migration_version'] = 0;
-
-
-/*
-|--------------------------------------------------------------------------
-| Migrations Path
-|--------------------------------------------------------------------------
-|
-| Path to your migrations folder.
-| Typically, it will be within your application path.
-| Also, writing permission is required within the migrations path.
-|
-*/
-$config['migration_path'] = APPPATH . 'migrations/';
-
-
-/* End of file migration.php */
+migration->latest() this is the version that schema will
+| be upgraded / downgraded to.
+|
+*/
+$config['migration_version'] = 0;
+
+
+/*
+|--------------------------------------------------------------------------
+| Migrations Path
+|--------------------------------------------------------------------------
+|
+| Path to your migrations folder.
+| Typically, it will be within your application path.
+| Also, writing permission is required within the migrations path.
+|
+*/
+$config['migration_path'] = APPPATH . 'migrations/';
+
+
+/* End of file migration.php */
/* Location: ./application/config/migration.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 5494077cd755effc3204cdba8bfac5bd2d8ad74d Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Fri, 14 Oct 2011 16:50:14 -0300
Subject: Fixed merge error.
---
application/config/migration.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/application/config/migration.php b/application/config/migration.php
index 41b89626f..8f3a2f6c5 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -111,5 +111,4 @@ $config['migration_path'] = APPPATH . 'migrations/';
/* End of file migration.php */
->>>>>>> a2125a5d830fd390b4cf35f77e9bb0558cfa2dd7:application/config/migration.php
/* Location: ./application/config/migration.php */
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 02e7c8b14d53e4b4b5334c6ae64e49c211f56bf1 Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Fri, 14 Oct 2011 16:51:07 -0300
Subject: REALLY fixed merge problem.
---
application/config/migration.php | 43 ----------------------------------------
1 file changed, 43 deletions(-)
diff --git a/application/config/migration.php b/application/config/migration.php
index 8f3a2f6c5..3ca47f688 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -1,46 +1,3 @@
-<<<<<<< HEAD:application/config/migration.php
-migration->latest() this is the version that schema will
-| be upgraded / downgraded to.
-|
-*/
-$config['migration_version'] = 0;
-
-
-/*
-|--------------------------------------------------------------------------
-| Migrations Path
-|--------------------------------------------------------------------------
-|
-| Path to your migrations folder.
-| Typically, it will be within your application path.
-| Also, writing permission is required within the migrations path.
-|
-*/
-$config['migration_path'] = APPPATH . 'migrations/';
-
-
-/* End of file migration.php */
-=======
Date: Fri, 14 Oct 2011 17:59:49 -0300
Subject: Updated to new documentation for new active record methods.
---
user_guide_src/source/database/active_record.rst | 108 +++++++++++++++++++++++
1 file changed, 108 insertions(+)
diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst
index e1fc00bc5..7230812de 100644
--- a/user_guide_src/source/database/active_record.rst
+++ b/user_guide_src/source/database/active_record.rst
@@ -54,6 +54,36 @@ $query, which can be used to show the results::
Please visit the :doc:`result functions ` page for a full
discussion regarding result generation.
+$this->db->get_compiled_select()
+================================
+
+Compiles the selection query just like `$this->db->get()`_ but does not *run*
+the query. This method simply returns the SQL query as a string.
+
+Example::
+
+ $sql = $this->db->get_compiled_select('mytable');
+ echo $sql;
+
+ // Produces string: SELECT * FROM mytable
+
+The second parameter enables you to set whether or not the active record query
+will be reset (by default it will be—just like `$this->db->get()`)::
+
+ echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
+ // Produces string: SELECT * FROM mytable LIMIT 20, 10
+ // (in MySQL. Other databases have slightly different syntax)
+
+ echo $this->db->select('title, content, date')->get_compiled_select();
+
+ // Produces string: SELECT title, content, date FROM mytable
+
+The key thing to notice in the above example is that the second query did not
+utlize `$this->db->from()`_ and did not pass a table name into the first
+parameter. The reason for this outcome is because the query has not been
+executed using `$this->db->get()`_ which resets values or reset directly
+using `$this-db->reset_query()`_.
+
$this->db->get_where()
======================
@@ -540,6 +570,41 @@ object.
.. note:: All values are escaped automatically producing safer queries.
+$this->db->get_compiled_insert()
+================================
+Compiles the insertion query just like `$this->db->insert()`_ but does not
+*run* the query. This method simply returns the SQL query as a string.
+
+Example::
+
+ $data = array(
+ 'title' => 'My title',
+ 'name' => 'My Name',
+ 'date' => 'My date'
+ );
+
+ $sql = $this->db->set($data)->get_compiled_insert('mytable');
+ echo $sql;
+
+ // Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
+
+The second parameter enables you to set whether or not the active record query
+will be reset (by default it will be--just like `$this->db->insert()`_)::
+
+ echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE);
+
+ // Produces string: INSERT INTO mytable (title) VALUES ('My Title')
+
+ echo $this->db->set('content', 'My Content')->get_compiled_insert();
+
+ // Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content')
+
+The key thing to notice in the above example is that the second query did not
+utlize `$this->db->from()`_ nor did it pass a table name into the first
+parameter. The reason this worked is because the query has not been executed
+using `$this->db->insert()`_ which resets values or reset directly using
+`$this->db->reset_query()`_.
+
$this->db->insert_batch()
=========================
@@ -717,6 +782,14 @@ array of values, the third parameter is the where key.
.. note:: All values are escaped automatically producing safer queries.
+$this->db->get_compiled_update()
+================================
+
+This works exactly the same way as ``$this->db->get_compiled_insert()`` except
+that it produces an UPDATE SQL string instead of an INSERT SQL string.
+
+For more information view documentation for `$this->get_compiled_insert()`_.
+
*************
Deleting Data
@@ -784,6 +857,13 @@ Generates a truncate SQL string and runs the query.
.. note:: If the TRUNCATE command isn't available, truncate() will
execute as "DELETE FROM table".
+
+$this->db->get_compiled_delete()
+================================
+This works exactly the same way as ``$this->db->get_compiled_insert()`` except
+that it produces a DELETE SQL string instead of an INSERT SQL string.
+
+For more information view documentation for `$this->get_compiled_insert()`_.
***************
Method Chaining
@@ -854,3 +934,31 @@ Here's a usage example::
where, like, group_by, having, order_by, set
+
+*******************
+Reset Active Record
+*******************
+
+Resetting Active Record allows you to start fresh with your query without
+executing it first using a method like $this->db->get() or $this->db->insert().
+Just like the methods that execute a query, this will *not* reset items you've
+cached using `Active Record Caching`_.
+
+This is useful in situations where you are using Active Record to generate SQL
+(ex. ``$this->db->get_compiled_select()``) but then choose to, for instance,
+run the query::
+
+ // Note that the second parameter of the get_compiled_select method is FALSE
+ $sql = $this->db->select(array('field1','field2'))
+ ->where('field3',5)
+ ->get_compiled_select('mytable', FALSE);
+
+ // ...
+ // Do something crazy with the SQL code... like add it to a cron script for
+ // later execution or something...
+ // ...
+
+ $data = $this->db->get()->result_array();
+
+ // Would execute and return an array of results of the following query:
+ // SELECT field1, field1 from mytable where field3 = 5;
--
cgit v1.2.3-24-g4f1b
From 053dbc851f4c209ae05e1f079bb6da22e629b507 Mon Sep 17 00:00:00 2001
From: Kyle Farris
Date: Fri, 14 Oct 2011 18:06:52 -0300
Subject: Updated changelog to new changelog format.
---
user_guide_src/source/changelog.rst | 3 +++
1 file changed, 3 insertions(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index a6a2683aa..d0b935224 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -46,6 +46,9 @@ Release Date: Not Released
$this->db->like() in the :doc:`Database
Driver `.
- Added $this->db->insert_batch() support to the OCI8 (Oracle) driver.
+ - Added new :doc:`Active Record ` methods that return
+ the SQL string of queries without executing them: get_compiled_select(),
+ get_compiled_insert(), get_compiled_update(), get_compiled_delete().
- Libraries
--
cgit v1.2.3-24-g4f1b
From 2d096c0339f1cef810cc74e93f4d0633ee8e215f Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Mon, 17 Oct 2011 12:24:56 -0400
Subject: Added changelog item
---
user_guide_src/source/changelog.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 3e1643524..0b12d758c 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -8,7 +8,7 @@ Version 2.1.0 (planned)
Release Date: Not Released
- General Changes
-
+ - Added an optional backtrace to php-error template
- Added Android to the list of user agents.
- Added Windows 7 to the list of user platforms.
- Callback validation rules can now accept parameters like any other
--
cgit v1.2.3-24-g4f1b
From deb65968c2be11b72f1072d5fd840edd1da031dd Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Mon, 17 Oct 2011 12:26:02 -0400
Subject: Added changelog item
---
user_guide_src/source/changelog.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 0b12d758c..e4c318f43 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -8,7 +8,8 @@ Version 2.1.0 (planned)
Release Date: Not Released
- General Changes
- - Added an optional backtrace to php-error template
+
+ - Added an optional backtrace to php-error template,
- Added Android to the list of user agents.
- Added Windows 7 to the list of user platforms.
- Callback validation rules can now accept parameters like any other
--
cgit v1.2.3-24-g4f1b
From 52aff71bac8bf93eff797e35d875334ebd3585a0 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Mon, 17 Oct 2011 12:26:56 -0400
Subject: Added changelog item
---
user_guide_src/source/changelog.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index e4c318f43..97e949542 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -9,7 +9,7 @@ Release Date: Not Released
- General Changes
- - Added an optional backtrace to php-error template,
+ - Added an optional backtrace to php-error template.
- Added Android to the list of user agents.
- Added Windows 7 to the list of user platforms.
- Callback validation rules can now accept parameters like any other
--
cgit v1.2.3-24-g4f1b
From 3e414f9f72e387449d9e3984e1869b386564deaf Mon Sep 17 00:00:00 2001
From: Chris Muench
Date: Sun, 16 Oct 2011 23:03:55 -0400
Subject: Check for string value before doing str_replace. (Issue #439)
---
system/libraries/Session.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index dd951c325..867314bf9 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -749,7 +749,10 @@ class CI_Session {
*/
function _unescape_slashes(&$val, $key)
{
- $val= str_replace('{{slash}}', '\\', $val);
+ if (is_string($val))
+ {
+ $val= str_replace('{{slash}}', '\\', $val);
+ }
}
// --------------------------------------------------------------------
--
cgit v1.2.3-24-g4f1b
From caa1db64141cc8bfbdbe3a4f6f7b639331d5d3ba Mon Sep 17 00:00:00 2001
From: Derek Jones
Date: Mon, 17 Oct 2011 21:17:21 -0500
Subject: added some additional notes to the 2.0.0 update notes to highlight
some of the potential gotchas, fixes #588
---
user_guide_src/source/changelog.rst | 2 +
user_guide_src/source/installation/upgrade_200.rst | 52 ++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 906e2ebaa..bbf2ec778 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -323,6 +323,8 @@ Bug fixes for 2.0.1
- Fixed a bug (Reactor #69) where the SHA1 library was named
incorrectly.
+.. _2.0.0-changelog:
+
Version 2.0.0
=============
diff --git a/user_guide_src/source/installation/upgrade_200.rst b/user_guide_src/source/installation/upgrade_200.rst
index 064e1b534..0bcbd5c99 100644
--- a/user_guide_src/source/installation/upgrade_200.rst
+++ b/user_guide_src/source/installation/upgrade_200.rst
@@ -5,6 +5,10 @@ Upgrading from 1.7.2 to 2.0.0
Before performing an update you should take your site offline by
replacing the index.php file with a static one.
+*******************
+Update Instructions
+*******************
+
Step 1: Update your CodeIgniter files
=====================================
@@ -88,3 +92,51 @@ Step 8: Update your user guide
Please replace your local copy of the user guide with the new version,
including the image files.
+
+
+************
+Update Notes
+************
+
+Please refer to the :ref:`2.0.0 Change Log <2.0.0-changelog>` for full
+details, but here are some of the larger changes that are more likely to
+impact your code:
+
+- CodeIgniter now requires PHP 5.1.6.
+- Scaffolding has been removed.
+- The CAPTCHA plugin in now a :doc:`helper `.
+- The JavaScript calendar plugin was removed.
+- The *system/cache* and *system/logs* directories are now in the application
+ directory.
+- The Validation class has been removed. Please see the
+ :doc:`Form Validation library `
+- "default" is now a reserved name.
+- The xss_clean() function has moved to the :doc:`Security Class
+ `.
+- do_xss_clean() now returns FALSE if the uploaded file fails XSS checks.
+- The :doc:`Session Class ` requires now the use of an
+ encryption key set in the config file.
+- The following deprecated Active Record functions have been removed:
+ ``orwhere``, ``orlike``, ``groupby``, ``orhaving``, ``orderby``,
+ ``getwhere``.
+- ``_drop_database()`` and ``_create_database()`` functions have been removed
+ from the db utility drivers.
+- The ``dohash()`` function of the :doc:`Security helper
+ `
+ has been renamed to ``do_hash()`` for naming consistency.
+
+The config folder
+=================
+
+The following files have been changed:
+
+- config.php
+- database.php
+- mimes.php
+- routes.php
+- user_agents.php
+
+The following files have been added:
+
+- foreign_chars.php
+- profiler.php
--
cgit v1.2.3-24-g4f1b
From 84bcc6e9b8b1648d3a52102d2a96d617c60508f0 Mon Sep 17 00:00:00 2001
From: Derek Jones
Date: Mon, 17 Oct 2011 21:24:27 -0500
Subject: fixed typo in AR docs. NOTE: Sphinx gives a ReST error for unknown
title targets, but they do exist, and links are built properly
---
user_guide_src/source/database/active_record.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst
index 7230812de..5555a30bc 100644
--- a/user_guide_src/source/database/active_record.rst
+++ b/user_guide_src/source/database/active_record.rst
@@ -79,11 +79,12 @@ will be reset (by default it will be—just like `$this->db->get()`)::
// Produces string: SELECT title, content, date FROM mytable
The key thing to notice in the above example is that the second query did not
-utlize `$this->db->from()`_ and did not pass a table name into the first
+utilize `$this->db->from()`_ and did not pass a table name into the first
parameter. The reason for this outcome is because the query has not been
executed using `$this->db->get()`_ which resets values or reset directly
using `$this-db->reset_query()`_.
+
$this->db->get_where()
======================
--
cgit v1.2.3-24-g4f1b
From 961684280faccb7f32da700201422ecd8a454a0a Mon Sep 17 00:00:00 2001
From: Derek Jones
Date: Mon, 17 Oct 2011 22:57:44 -0500
Subject: updated Directory helper docs to use proper PHP method Sphinx roles
---
user_guide_src/source/helpers/directory_helper.rst | 27 +++++++++++-----------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/user_guide_src/source/helpers/directory_helper.rst b/user_guide_src/source/helpers/directory_helper.rst
index 6c259adb1..fd169886c 100644
--- a/user_guide_src/source/helpers/directory_helper.rst
+++ b/user_guide_src/source/helpers/directory_helper.rst
@@ -18,15 +18,20 @@ This helper is loaded using the following code
The following functions are available:
-directory_map('source directory')
-=================================
+directory_map()
+===============
This function reads the directory path specified in the first parameter
and builds an array representation of it and all its contained files.
+
+.. php:method:: directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]])
-Example
-
-::
+ :param string $source_dir: path to the ource directory
+ :param integer $directory_depth: depth of directories to traverse (0 =
+ fully recursive, 1 = current dir, etc)
+ :param boolean $hidden: whether to include hidden directories
+
+Examples::
$map = directory_map('./mydirectory/');
@@ -35,23 +40,17 @@ Example
Sub-folders contained within the directory will be mapped as well. If
you wish to control the recursion depth, you can do so using the second
-parameter (integer). A depth of 1 will only map the top level directory
-
-::
+parameter (integer). A depth of 1 will only map the top level directory::
$map = directory_map('./mydirectory/', 1);
By default, hidden files will not be included in the returned array. To
-override this behavior, you may set a third parameter to true (boolean)
-
-::
+override this behavior, you may set a third parameter to true (boolean)::
$map = directory_map('./mydirectory/', FALSE, TRUE);
Each folder name will be an array index, while its contained files will
-be numerically indexed. Here is an example of a typical array
-
-::
+be numerically indexed. Here is an example of a typical array::
Array (
[libraries] => Array
--
cgit v1.2.3-24-g4f1b
From 9a902cb3b9cb9e6133c42aa047f410ed4f6dcdf1 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Tue, 18 Oct 2011 04:06:29 -0400
Subject: Moved backtrace constant to config/constants.php
---
application/config/constants.php | 12 ++++++++++++
index.php | 1 -
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/application/config/constants.php b/application/config/constants.php
index 4a879d360..fcf1aae89 100644
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -36,6 +36,18 @@ define('FOPEN_READ_WRITE_CREATE', 'a+b');
define('FOPEN_WRITE_CREATE_STRICT', 'xb');
define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
+/*
+|--------------------------------------------------------------------------
+| Display Debug backtrace
+|--------------------------------------------------------------------------
+|
+| If set to true, a backtrace will be displayed along with php errors. If
+| error_reporting is disabled, the backtrace will not display, regardless
+| of this setting
+|
+*/
+define('SHOW_ERROR_BACKTRACE', TRUE);
+
/* End of file constants.php */
/* Location: ./application/config/constants.php */
\ No newline at end of file
diff --git a/index.php b/index.php
index 312fbfb1d..c50cfed43 100644
--- a/index.php
+++ b/index.php
@@ -34,7 +34,6 @@ if (defined('ENVIRONMENT'))
{
case 'development':
error_reporting(-1);
- define('SHOW_ERROR_BACKTRACE', TRUE);
break;
case 'testing':
--
cgit v1.2.3-24-g4f1b
From d609a59ab5f30bc0ee0d9d5b619a1201fef59461 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Tue, 18 Oct 2011 06:27:31 -0400
Subject: Minor formatting changes
---
application/config/constants.php | 2 +-
application/errors/error_php.php | 19 ++++++++++++-------
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/application/config/constants.php b/application/config/constants.php
index fcf1aae89..f41f86b74 100644
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -41,7 +41,7 @@ define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
| Display Debug backtrace
|--------------------------------------------------------------------------
|
-| If set to true, a backtrace will be displayed along with php errors. If
+| If set to TRUE, a backtrace will be displayed along with php errors. If
| error_reporting is disabled, the backtrace will not display, regardless
| of this setting
|
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index cf6cb9fac..f2f71857f 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -6,16 +6,21 @@
Message:
Filename:
Line Number:
+
+
Backtrace:
-
-
- File:
- Line:
- Function:
-
- endif ?>
+
+
+
+ File:
+ Line:
+ Function:
+
+ endif ?>
+
endforeach ?>
+
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 8bf00384deafdb73e00422dd5c9f541564ea85ca Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Tue, 18 Oct 2011 06:28:41 -0400
Subject: Minor formatting changes
---
application/errors/error_php.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index f2f71857f..b7fdec44a 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -23,4 +23,5 @@
endforeach ?>
+
\ No newline at end of file
--
cgit v1.2.3-24-g4f1b
From 5160cc9a869e27a696f93f64127eef15c54f5d64 Mon Sep 17 00:00:00 2001
From: Timothy Warren
Date: Tue, 18 Oct 2011 06:50:06 -0400
Subject: Renamed constant, added 10px margin to backtrace
---
application/config/constants.php | 2 +-
application/errors/error_php.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/application/config/constants.php b/application/config/constants.php
index f41f86b74..ee177f5ad 100644
--- a/application/config/constants.php
+++ b/application/config/constants.php
@@ -46,7 +46,7 @@ define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
| of this setting
|
*/
-define('SHOW_ERROR_BACKTRACE', TRUE);
+define('SHOW_DEBUG_BACKTRACE', TRUE);
/* End of file constants.php */
diff --git a/application/errors/error_php.php b/application/errors/error_php.php
index b7fdec44a..514e477e8 100644
--- a/application/errors/error_php.php
+++ b/application/errors/error_php.php
@@ -7,13 +7,13 @@
Filename:
Line Number:
-
+
Backtrace:
-
+
File:
Line:
Function:
--
cgit v1.2.3-24-g4f1b