Skip to content

Instantly share code, notes, and snippets.

@GDmac
Last active December 28, 2015 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GDmac/7435165 to your computer and use it in GitHub Desktop.
Save GDmac/7435165 to your computer and use it in GitHub Desktop.
CI merge cache, QB/AR no escape
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index f0fe96c35622a77066952d6a23fc526044590df7..d912540b5e2cd825b705088bee2497ba72fd04aa 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -2561,14 +2561,30 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$qb_variable = 'qb_'.$val;
$qb_cache_var = 'qb_cache_'.$val;
- $qb_new = $this->$qb_cache_var;
-
- foreach ($this->$qb_variable as &$qb_var)
+
+ // prep arrays with cached values
+ $qb_new = $this->$qb_cache_var;
+ $qb_escape = $this->qb_cache_no_escape;
+
+ foreach ($this->$qb_variable as $i => &$qb_var)
{
- in_array($qb_var, $qb_new, TRUE) OR $qb_new[] = $qb_var;
+ if ( ! in_array($qb_var, $qb_new, TRUE))
+ {
+ $qb_new[] = $qb_var;
+ if ($val == 'select') $qb_escape[] = $this->qb_no_escape[$i];
+ }
+ else
+ {
+ // if ($val == 'select')
+ // {
+ // i don't feel like doing an expensive
+ // foreach lookup, just to override escape?
+ // }
+ }
}
$this->$qb_variable = $qb_new;
+ if ($val == 'select') $this->qb_no_escape = $qb_escape;
}
// If we are "protecting identifiers" we need to examine the "from"
@@ -2577,10 +2593,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$this->_track_aliases($this->qb_from);
}
-
- $this->qb_no_escape = array_merge($this->qb_no_escape, array_diff($this->qb_cache_no_escape, $this->qb_no_escape));
}
-
// --------------------------------------------------------------------
/**
@narfbg
Copy link

narfbg commented Nov 15, 2013

Is the else condition necessary?

@GDmac
Copy link
Author

GDmac commented Dec 23, 2013

nope, the else part "could" be used to loop thru previously stored select variables and change the escape setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment