From e1b8683d7983cca11219d618f093b842429bd41c Mon Sep 17 00:00:00 2001 From: GDmac Date: Fri, 8 Nov 2013 16:52:54 +0100 Subject: Fix #2406 query builder cache Signed-off-by: GDmac --- system/database/DB_query_builder.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index a73460394..0d0421306 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2557,18 +2557,22 @@ abstract class CI_DB_query_builder extends CI_DB_driver { return; } - foreach ($this->qb_cache_exists as $val) + $parts = array_unique($this->qb_cache_exists); // select, from, etc. + + foreach ($parts as $val) { $qb_variable = 'qb_'.$val; $qb_cache_var = 'qb_cache_'.$val; - if (count($this->$qb_cache_var) > 0) + $qb_new = $this->$qb_cache_var; + + foreach ($this->$qb_variable as $qb_var) { - foreach ($this->$qb_cache_var as &$cache_var) - { - in_array($cache_var, $this->$qb_variable, TRUE) OR $this->{$qb_variable}[] = $cache_var; - } + in_array($qb_var, $qb_new, TRUE) OR $qb_new[] = $qb_var; } + + $this->$qb_variable = $qb_new; + } // If we are "protecting identifiers" we need to examine the "from" -- cgit v1.2.3-24-g4f1b From 01e9fb1d6aab8e513a9ebd786e9abff74d8b63ca Mon Sep 17 00:00:00 2001 From: GDmac Date: Sat, 9 Nov 2013 08:01:52 +0100 Subject: docs: get_compile_select get_compile_select(null,false) without reset also preserves LIMIT settings --- user_guide_src/source/database/query_builder.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst index 65609c1cb..5e0dcb4be 100644 --- a/user_guide_src/source/database/query_builder.rst +++ b/user_guide_src/source/database/query_builder.rst @@ -68,7 +68,7 @@ Example:: // Produces string: SELECT * FROM mytable The second parameter enables you to set whether or not the query builder query -will be reset (by default it will be—just like `$this->db->get()`):: +will be reset (by default it will be reset, just like when using `$this->db->get()`):: echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE); // Produces string: SELECT * FROM mytable LIMIT 20, 10 @@ -76,7 +76,7 @@ will be reset (by default it will be—just like `$this->db->get()`):: echo $this->db->select('title, content, date')->get_compiled_select(); - // Produces string: SELECT title, content, date FROM mytable + // Produces string: SELECT title, content, date FROM mytable LIMIT 20, 10 The key thing to notice in the above example is that the second query did not utilize `$this->db->from()`_ and did not pass a table name into the first @@ -1055,4 +1055,4 @@ run the query:: $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; \ No newline at end of file + // SELECT field1, field1 from mytable where field3 = 5; -- cgit v1.2.3-24-g4f1b From 17a0528c23c4d6cf95b03299fbfe2ff789b82249 Mon Sep 17 00:00:00 2001 From: GDmac Date: Mon, 11 Nov 2013 13:18:09 +0100 Subject: Cleanup PR #2719 for Fix #2406 query builder cache Signed-off-by: GDmac --- system/database/DB_query_builder.php | 7 ++----- user_guide_src/source/database/query_builder.rst | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 0d0421306..fb8514f5c 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2557,22 +2557,19 @@ abstract class CI_DB_query_builder extends CI_DB_driver { return; } - $parts = array_unique($this->qb_cache_exists); // select, from, etc. - - foreach ($parts as $val) + foreach (array_unique($this->qb_cache_exists) as $val) // select, from, etc. { $qb_variable = 'qb_'.$val; $qb_cache_var = 'qb_cache_'.$val; $qb_new = $this->$qb_cache_var; - foreach ($this->$qb_variable as $qb_var) + foreach ($this->$qb_variable as &$qb_var) { in_array($qb_var, $qb_new, TRUE) OR $qb_new[] = $qb_var; } $this->$qb_variable = $qb_new; - } // If we are "protecting identifiers" we need to examine the "from" diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst index 5e0dcb4be..480067407 100644 --- a/user_guide_src/source/database/query_builder.rst +++ b/user_guide_src/source/database/query_builder.rst @@ -1055,4 +1055,4 @@ run the query:: $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; + // SELECT field1, field1 from mytable where field3 = 5; \ No newline at end of file -- cgit v1.2.3-24-g4f1b