From b9e2dc46c90d4315b17121ce0cc2705017ec237c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 30 Apr 2012 14:22:27 -0400 Subject: [PATCH] Streamline a few query builder methods --- classes/query_builder.php | 84 ++++++++++------------------------ tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 2 files changed, 24 insertions(+), 60 deletions(-) diff --git a/classes/query_builder.php b/classes/query_builder.php index 2f7ea75..dfdb84c 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -463,33 +463,21 @@ class Query_Builder { */ public function or_like($field, $val, $pos='both') { - $field = $this->quote_ident($field); + // Do the like method + $this->like($field, $val, $pos); + + $l = $field. ' LIKE ?'; + + // Pop the incorrect query mapping off of the array + array_pop($this->query_map); // Add the like string into the order map - $l = $field. ' LIKE ?'; - - if ($pos == 'before') - { - $val = "%{$val}"; - } - elseif ($pos == 'after') - { - $val = "{$val}%"; - } - else - { - $val = "%{$val}%"; - } - $this->query_map[] = array( 'type' => 'like', 'conjunction' => (empty($this->query_map)) ? 'WHERE ' : ' OR ', 'string' => $l ); - // Add to the values array - $this->values[] = $val; - return $this; } @@ -505,33 +493,21 @@ class Query_Builder { */ public function not_like($field, $val, $pos='both') { - $field = $this->quote_ident($field); + // Do the like method + $this->like($field, $val, $pos); + + // Pop the incorrect query mapping off of the array + array_pop($this->query_map); // Add the like string into the order map $l = $field. ' NOT LIKE ?'; - if ($pos == 'before') - { - $val = "%{$val}"; - } - elseif ($pos == 'after') - { - $val = "{$val}%"; - } - else - { - $val = "%{$val}%"; - } - $this->query_map[] = array( 'type' => 'like', 'conjunction' => (empty($this->query_map)) ? ' WHERE ' : ' AND ', 'string' => $l ); - // Add to the values array - $this->values[] = $val; - return $this; } @@ -547,33 +523,21 @@ class Query_Builder { */ public function or_not_like($field, $val, $pos='both') { - $field = $this->quote_ident($field); + // Do the like method + $this->like($field, $val, $pos); + + // Pop the incorrect query mapping off of the array + array_pop($this->query_map); // Add the like string into the order map $l = $field. ' NOT LIKE ?'; - if ($pos == 'before') - { - $val = "%{$val}"; - } - elseif ($pos == 'after') - { - $val = "{$val}%"; - } - else - { - $val = "%{$val}%"; - } - $this->query_map[] = array( 'type' => 'like', 'conjunction' => (empty($this->query_map)) ? ' WHERE ' : ' OR ', 'string' => $l ); - // Add to the values array - $this->values[] = $val; - return $this; } @@ -801,14 +765,15 @@ class Query_Builder { */ public function or_where_in($field, $val=array()) { + // Do the were_in method + $this->where_in($field, $val); + + // Pop the incorrect query mapping off of the array + array_pop($this->query_map); + $field = $this->quote_ident($field); $params = array_fill(0, count($val), '?'); - foreach($val as $v) - { - $this->values[] = $v; - } - $string = $field . ' IN ('.implode(',', $params).') '; $this->query_map[] = array( @@ -932,7 +897,6 @@ class Query_Builder { */ public function join($table, $condition, $type='') { - // Paste it back together $table = implode(" ", array_map(array($this->db, 'quote_ident'), explode(' ', trim($table)))); //$condition = preg_replace('`(\W)`', " $1 ", $condition); $cond_array = explode(' ', trim($condition)); @@ -1373,7 +1337,7 @@ class Query_Builder { * @param string $table * @return $string */ - private function _compile($type='', $table="") + private function _compile($type='', $table='') { $sql = ''; diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 156abffa4ebe7d5289cd98a780ebda82ecb0d2b8..375a5b25885b9df66b8519c619e1d76f71cbd2d3 100644 GIT binary patch delta 879 zcmZ8f&ubGw6n>NJ+H_w+#~%k#shcJtL4+nO8tPKE>!L+e+JjiUND%}*h!_8WMP!eX zV&PG|if0eC@uDDj_aumVNZM^nkw!gu@aCJHOoPs_`|YkM$476$g-zd$N#aJb2v{N1^J} zV7=IYN9e-6VhyS#7Zz~}*0BUux0;9Ic*FPL{2drk%3aLg+6Y?P+pm{Wpl4&CYD zdEwJq53e$8E10ELAEVHB0p9WM90;Bg47V~42VAYH*&gl(!|8P&7et%vO^g_>Y;x{4 zJ@|ps^m%}%#0>R$B{XqH$8e)#_{1=;_n(fZbr`l-$D==6tm7%2D&0@9F3!$ zB=*@}6KCu-T$>5Ump^gwFD9C`4gdfE delta 863 zcmZ9KPiPZC6vp2qyVBc+$5!nO3sH&Ntu8y!q|Cw{hHxVMmi({8*!v{FdFF-*&{sM6I)Q8%exy%DdC~)iKW5Io+mp(GR>27EBflQ=GWFe8o zL>h@S6In{6mB?};4{S)=kYb@{`nFr{g?0O@)$N!`)81&J@$!~k&JWz{t_cTb%n)u^ zA?#X5;i*-JJ0%}x%08Sgu`f-*dnQ5CWon&VmoqufY-dS0D_wY?Ty^Sp3hdZRvGUH?P)#5%c4T&Cbn5FZt~d` zTKRzu`aHsUafni0iFBOiXs#&61%5g%18hhuIa6 z(7kUMMmkvYwO82#&|Z%3=}o{q1@q|ckYOIZ;E!Y3&u5jQZO*5T)A`h1aRIc~b<=g# zb#oQRrBC0PF?&Y?@u2p3rLw62ZvskbA%&VS3#9SnHo92ZvA_kyZ+O;tE}wu@K( E0dI+~sQ>@~