From cd3255a8a2fc039c00871953159ceb834d604a29 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 30 Apr 2012 14:49:30 -0400 Subject: [PATCH] Various Query Builder improvements --- classes/db_pdo.php | 3 + classes/query_builder.php | 31 +- docs/classes/DB_PDO.html | 2 +- docs/classes/DB_Reg.html | 2 +- docs/classes/DB_SQL.html | 2 +- docs/classes/DB_Util.html | 2 +- docs/classes/Firebird.html | 2 +- docs/classes/Firebird_Result.html | 2 +- docs/classes/Firebird_SQL.html | 2 +- docs/classes/Firebird_Util.html | 2 +- docs/classes/MySQL.html | 2 +- docs/classes/MySQL_SQL.html | 2 +- docs/classes/MySQL_Util.html | 2 +- docs/classes/ODBC.html | 2 +- docs/classes/ODBC_SQL.html | 2 +- docs/classes/ODBC_Util.html | 2 +- docs/classes/PgSQL.html | 2 +- docs/classes/PgSQL_SQL.html | 2 +- docs/classes/PgSQL_Util.html | 2 +- docs/classes/Query_Builder.html | 9 +- docs/classes/SQLite.html | 2 +- docs/classes/SQLite_SQL.html | 2 +- docs/classes/SQLite_Util.html | 2 +- docs/classes/Settings.html | 2 +- docs/deprecated.html | 2 +- docs/errors.html | 2 +- docs/graph_class.html | 2 +- docs/markers.html | 2 +- docs/namespaces/default.html | 2 +- docs/packages/.html | 2 +- docs/packages/Default.html | 2 +- docs/packages/Query.Drivers.html | 2 +- docs/packages/Query.Helper Classes.html | 2 +- docs/packages/Query.Query.html | 2 +- docs/packages/Query.html | 2 +- docs/structure.xml | 727 ++++++++++++------------ tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 37 files changed, 408 insertions(+), 426 deletions(-) diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 85da6c7..a24279f 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -202,6 +202,9 @@ abstract class DB_PDO extends PDO { { return array_map(array($this, 'quote_ident'), $ident); } + + // Remove existing escape characters + $ident = str_replace($this->escape_char, '', $ident); // Split each identifier by the period $hiers = explode('.', $ident); diff --git a/classes/query_builder.php b/classes/query_builder.php index f86f27f..292a57f 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -22,6 +22,10 @@ */ class Query_Builder { + // -------------------------------------------------------------------------- + // ! SQL Clause Strings + // -------------------------------------------------------------------------- + /** * Compiled 'select' clause * @@ -57,15 +61,10 @@ class Query_Builder { */ private $group_string; + // -------------------------------------------------------------------------- + // ! SQL Clause Arrays // -------------------------------------------------------------------------- - /** - * key/val pairs for insert/update statement - * - * @var array - */ - private $set_array; - /** * Keys for insert/update statement * @@ -87,6 +86,8 @@ class Query_Builder { */ private $group_array; + // -------------------------------------------------------------------------- + // ! Other Class vars // -------------------------------------------------------------------------- /** @@ -856,12 +857,12 @@ class Query_Builder { * @param mixed $val * @return $this */ - public function set($key, $val) + public function set($key, $val = NULL) { // Plain key, value pair if (is_scalar($key) && is_scalar($val)) { - $this->set_array[$key] = $val; + $this->set_array_keys[] = $key; $this->values[] = $val; } // Object or array @@ -869,18 +870,14 @@ class Query_Builder { { foreach($key as $k => $v) { - $this->set_array[$k] = $v; - - foreach($vals as $v) - { - $this->values[] = $v; - } + $this->set_array_keys[] = $k; + $this->values[] = $v; } } // Use the keys of the array to make the insert/update string // Escape the field names - $this->set_array_keys = array_map(array($this->db, 'quote_ident'), array_keys($this->set_array)); + $this->set_array_keys = array_map(array($this->db, 'quote_ident'), $this->set_array_keys); // Generate the "set" string $this->set_string = implode('=?, ', $this->set_array_keys); @@ -1395,7 +1392,7 @@ class Query_Builder { break; case "insert": - $param_count = count($this->set_array); + $param_count = count($this->set_array_keys); $params = array_fill(0, $param_count, '?'); $sql = 'INSERT INTO '. $this->quote_ident($table) . ' (' . implode(', ', $this->set_array_keys) . diff --git a/docs/classes/DB_PDO.html b/docs/classes/DB_PDO.html index 47209aa..0fc2526 100644 --- a/docs/classes/DB_PDO.html +++ b/docs/classes/DB_PDO.html @@ -662,7 +662,7 @@ the connection/database
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/DB_Reg.html b/docs/classes/DB_Reg.html index fb26c60..d7230ca 100644 --- a/docs/classes/DB_Reg.html +++ b/docs/classes/DB_Reg.html @@ -151,7 +151,7 @@ and organizes database connections

+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/DB_SQL.html b/docs/classes/DB_SQL.html index d89a52d..61e9d27 100644 --- a/docs/classes/DB_SQL.html +++ b/docs/classes/DB_SQL.html @@ -268,7 +268,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/DB_Util.html b/docs/classes/DB_Util.html index be55220..5d99ae1 100644 --- a/docs/classes/DB_Util.html +++ b/docs/classes/DB_Util.html @@ -208,7 +208,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/Firebird.html b/docs/classes/Firebird.html index 164881b..45057b9 100644 --- a/docs/classes/Firebird.html +++ b/docs/classes/Firebird.html @@ -812,7 +812,7 @@ the last query executed
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/Firebird_Result.html b/docs/classes/Firebird_Result.html index b532da2..792e2b2 100644 --- a/docs/classes/Firebird_Result.html +++ b/docs/classes/Firebird_Result.html @@ -503,7 +503,7 @@ the query
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/Firebird_SQL.html b/docs/classes/Firebird_SQL.html index b043f8f..bbf0800 100644 --- a/docs/classes/Firebird_SQL.html +++ b/docs/classes/Firebird_SQL.html @@ -296,7 +296,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/Firebird_Util.html b/docs/classes/Firebird_Util.html index 1177e8b..de9382a 100644 --- a/docs/classes/Firebird_Util.html +++ b/docs/classes/Firebird_Util.html @@ -211,7 +211,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/MySQL.html b/docs/classes/MySQL.html index 9f76e0e..c4dfbfe 100644 --- a/docs/classes/MySQL.html +++ b/docs/classes/MySQL.html @@ -848,7 +848,7 @@ the connection/database
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/MySQL_SQL.html b/docs/classes/MySQL_SQL.html index 92650b8..a644134 100644 --- a/docs/classes/MySQL_SQL.html +++ b/docs/classes/MySQL_SQL.html @@ -280,7 +280,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/MySQL_Util.html b/docs/classes/MySQL_Util.html index bd1f69a..47e10be 100644 --- a/docs/classes/MySQL_Util.html +++ b/docs/classes/MySQL_Util.html @@ -207,7 +207,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/ODBC.html b/docs/classes/ODBC.html index 5e1f0e1..925baaa 100644 --- a/docs/classes/ODBC.html +++ b/docs/classes/ODBC.html @@ -850,7 +850,7 @@ the connection/database
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/ODBC_SQL.html b/docs/classes/ODBC_SQL.html index 7ecd0d5..7c88283 100644 --- a/docs/classes/ODBC_SQL.html +++ b/docs/classes/ODBC_SQL.html @@ -280,7 +280,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/ODBC_Util.html b/docs/classes/ODBC_Util.html index 5470dee..2b79b1f 100644 --- a/docs/classes/ODBC_Util.html +++ b/docs/classes/ODBC_Util.html @@ -202,7 +202,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/PgSQL.html b/docs/classes/PgSQL.html index efe7d1f..1624b70 100644 --- a/docs/classes/PgSQL.html +++ b/docs/classes/PgSQL.html @@ -850,7 +850,7 @@ the connection/database
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/PgSQL_SQL.html b/docs/classes/PgSQL_SQL.html index db8a7e5..f6940e3 100644 --- a/docs/classes/PgSQL_SQL.html +++ b/docs/classes/PgSQL_SQL.html @@ -296,7 +296,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/PgSQL_Util.html b/docs/classes/PgSQL_Util.html index f173150..c6fd18f 100644 --- a/docs/classes/PgSQL_Util.html +++ b/docs/classes/PgSQL_Util.html @@ -207,7 +207,7 @@
+ generated on 2012-04-30T14:49:04-04:00.
diff --git a/docs/classes/Query_Builder.html b/docs/classes/Query_Builder.html index ab657db..51ae102 100644 --- a/docs/classes/Query_Builder.html +++ b/docs/classes/Query_Builder.html @@ -125,7 +125,6 @@ passed array with key / value pairs
where()
for complex select queries">Query component order mapping for complex select queries
$query_map
  • Compiled 'select' clause
    $select_string
  • -
  • key/val pairs for insert/update statement
    $set_array
  • Keys for insert/update statement
    $set_array_keys
  • Compiled arguments for insert / update
    $set_string
  • Alias to $this->db->sql
    $sql
  • @@ -1049,12 +1048,6 @@ for complex select queries

    - 
    -

    key/val pairs for insert/update statement

    -
    $set_array : array
    -
    -

    -
     

    Keys for insert/update statement

    $set_array_keys : array
    @@ -1086,7 +1079,7 @@ for complex select queries
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/classes/SQLite.html b/docs/classes/SQLite.html index 2a4e57f..0c10746 100644 --- a/docs/classes/SQLite.html +++ b/docs/classes/SQLite.html @@ -865,7 +865,7 @@ method if the database does not support 'TRUNCATE';
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/classes/SQLite_SQL.html b/docs/classes/SQLite_SQL.html index e7673fb..f14b7cb 100644 --- a/docs/classes/SQLite_SQL.html +++ b/docs/classes/SQLite_SQL.html @@ -280,7 +280,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/classes/SQLite_Util.html b/docs/classes/SQLite_Util.html index d119c01..85c1697 100644 --- a/docs/classes/SQLite_Util.html +++ b/docs/classes/SQLite_Util.html @@ -207,7 +207,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/classes/Settings.html b/docs/classes/Settings.html index 5f74927..c66f2f8 100644 --- a/docs/classes/Settings.html +++ b/docs/classes/Settings.html @@ -243,7 +243,7 @@ directly - the settings should be safe!
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/deprecated.html b/docs/deprecated.html index 5cbb4d5..d280714 100644 --- a/docs/deprecated.html +++ b/docs/deprecated.html @@ -66,7 +66,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/errors.html b/docs/errors.html index 67d5061..decfd00 100644 --- a/docs/errors.html +++ b/docs/errors.html @@ -92,7 +92,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/graph_class.html b/docs/graph_class.html index 835f425..58cfb20 100644 --- a/docs/graph_class.html +++ b/docs/graph_class.html @@ -63,7 +63,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/markers.html b/docs/markers.html index 151e5a5..1347451 100644 --- a/docs/markers.html +++ b/docs/markers.html @@ -68,7 +68,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/namespaces/default.html b/docs/namespaces/default.html index cc6349d..7ee131e 100644 --- a/docs/namespaces/default.html +++ b/docs/namespaces/default.html @@ -282,7 +282,7 @@ instantiates the specific db driver

    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/packages/.html b/docs/packages/.html index 5c8ce16..fa3b93e 100644 --- a/docs/packages/.html +++ b/docs/packages/.html @@ -66,7 +66,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/packages/Default.html b/docs/packages/Default.html index 0e4ee30..aec5f18 100644 --- a/docs/packages/Default.html +++ b/docs/packages/Default.html @@ -93,7 +93,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/packages/Query.Drivers.html b/docs/packages/Query.Drivers.html index b691644..aeaaf70 100644 --- a/docs/packages/Query.Drivers.html +++ b/docs/packages/Query.Drivers.html @@ -210,7 +210,7 @@ data-fetching methods

    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/packages/Query.Helper Classes.html b/docs/packages/Query.Helper Classes.html index 9e3ec49..dfc4edc 100644 --- a/docs/packages/Query.Helper Classes.html +++ b/docs/packages/Query.Helper Classes.html @@ -96,7 +96,7 @@
    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/packages/Query.Query.html b/docs/packages/Query.Query.html index 9849cb8..67f87f3 100644 --- a/docs/packages/Query.Query.html +++ b/docs/packages/Query.Query.html @@ -114,7 +114,7 @@ instantiates the specific db driver

    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/packages/Query.html b/docs/packages/Query.html index af5bd22..c3bef02 100644 --- a/docs/packages/Query.html +++ b/docs/packages/Query.html @@ -315,7 +315,7 @@ instantiates the specific db driver

    + generated on 2012-04-30T14:49:04-04:00.
    diff --git a/docs/structure.xml b/docs/structure.xml index aa36916..9a68f7a 100644 --- a/docs/structure.xml +++ b/docs/structure.xml @@ -510,7 +510,7 @@ directly - the settings should be safe!]]> - + Free Query Builder / Database Abstraction Layer

    ]]>
    @@ -724,197 +724,197 @@ directly - the settings should be safe!]]> - + empty_table function - + - + string - + mixed - + $table - + get_schemas function - + - + array - + get_tables function - + - + array - + get_dbs function - + - + array - + get_views function - + - + array - + get_sequences function - + - + array - + get_functions function - + - + array - + get_procedures function - + - + array - + get_triggers function - + - + array - + get_system_tables function - + - + array - + driver_query function - + - + string - + bool - + mixed - + $sql - + $filtered_index - + num_rows function - + - + int - + truncate function - + - + string - + void - + $table - + switch_db function - + - + string - + void - + $name @@ -922,7 +922,7 @@ the connection/database]]>
    - + Free Query Builder / Database Abstraction Layer

    ]]>
    @@ -943,153 +943,142 @@ instantiates the specific db driver]]>
    - + $select_string - + - + string - + $from_string - + - + string - + $set_string - + - + string - + $order_string - + - + string - + $group_string - + - + string - - $set_array - - - - - - array - - - - + $set_array_keys - + - + array - + $order_array - + - + array - + $group_array - + - + array - + $values - + - + array - + $limit - + - + int - + $offset - + - + int - + $sql - + db->sql]]> - + \DB_PDO - + $query_map - + Format:

    @@ -1099,1026 +1088,1026 @@ for complex select queries]]> 'conjunction' => ' AND ', 'string' => 'k=?' )

    ]]>
    - + array
    - + $having_map - + - + array - + $conn_name - + - + string - + __construct function - + - + object - + $params - + select function - + - + string - + \$this - + $fields - + select_max function - + - + string - + string - + \$this - + $field - + $as - + select_min function - + - + string - + string - + \$this - + $field - + $as - + select_avg function - + - + string - + string - + \$this - + $field - + $as - + select_sum function - + - + string - + string - + \$this - + $field - + $as - + distinct function - + - + \$this - + from function - + - + string - + \$this - + $dbname - + like function - + - + string - + mixed - + string - + \$this - + $field - + $val - + $pos - + or_like function - + - + string - + mixed - + string - + \$this - + $field - + $val - + $pos - + not_like function - + - + string - + mixed - + string - + \$this - + $field - + $val - + $pos - + or_not_like function - + - + string - + mixed - + string - + \$this - + $field - + $val - + $pos - + having function - + - + mixed - + mixed - + \$this - + $key - + $val - + or_having function - + - + mixed - + mixed - + \$this - + $key - + $val - + _where function - + - + mixed - + mixed - + array - + $key - + $val - + where function - + - + mixed - + mixed - + \$this - + $key - + $val - + or_where function - + - + string - + mixed - + \$this - + $field - + $val - + where_in function - + - + mixed - + mixed - + \$this - + $field - + $val - + or_where_in function - + - + string - + mixed - + \$this - + $field - + $val - + where_not_in function - + - + string - + mixed - + \$this - + $field - + $val - + or_where_not_in function - + - + string - + mixed - + \$this - + $field - + $val - + set function - + - + mixed - + mixed - + \$this - + $key - + $val - + - + join function - + - + string - + string - + string - + \$this - + $table - + $condition - + $type - + group_by function - + - + mixed - + \$this - + $field - + order_by function - + - + string - + string - + \$this - + $field - + $type - + limit function - + - + int - + int - + string - + $limit - + $offset - + group_start function - + - + \$this - + or_group_start function - + - + \$this - + or_not_group_start function - + - + \$this - + group_end function - + - + \$this - + get function - + - - + + int - + int - + object - + $table - + $limit - + $offset - + get_where function - + - + string - + array - + int - + int - + object - + $table - + $where - + $limit - + $offset - + count_all function - + - + string - + int - + $table - + count_all_results function - + - + string - + int - + $table - + insert function - + - + string - + mixed - + mixed - + $table - + $data - + update function - + - + string - + mixed - + mixed - + $table - + $data - + delete function - + - + string - + mixed - + mixed - + $table - + $where - + __call function - + - + string - + array - + mixed - + $name - + $params - + _reset function - + - + _compile function - + - + string - + string - + \$string - + $type - + $table diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 81abab29e9ce3cf3f3f192c2ed185f2dff57a359..109d0c1254c7fdc2b8654eb0ff4346d36b7327c4 100644 GIT binary patch delta 1313 zcmah|L1+_E5S`i0noYi;UnJZUceV8w(+L=m+1;9)7H*p@0qQrp@~ZJ<5qL1^%> zCl3~df3ODyJ%|?-Y)=Y;2M-urKM%jJBz zobN+8m3x+f#*(6JM~Gw50~n_Zz`_Tg0R~U5bbQ#)7(jwWzhbyYx)+x#cb!8m3&s1l zWgsz-Rv_&_#scXCa#tYZfpi0zSdz(@#EE6cOJ>}A=VbiFz{hxyOD^R^?D^CgH|$rx z4PzQ^+HKHfcfzWbh41LWdu)Tp*bcX_6GkZJFbj*2g*%XfcW|U$%bP{pgDxutgLXT# zQgkWqwo(fN=>te70Q^-8wR-?>C_MoPNc*CCRS}taQKM(|<#GWnE?}7yr(KvS%^bT? znw_8`j~+$~sWCV)$|<}BXP8nGO}#>L%H>|sHH&bfyQznIvMSO?<4uLmHW7|4E;ukY zJy$wQs;jHwu;tX$%9hCDRrP37WX5BWB${DZJ5yppD`Bn3oMpX+zN9IOD0wS%Yo;f88)`aKpgR(7Czp%hXRV^^Fd3&8>y=(U0`h z#-`c%?Nb}^v|h5 zRz)v`r&ZxoAa9SWPg|lD2UO1&;xTpn3h_J*HgXNtya@guJig}fHIJ_@Z4i$i&QK*P vq67QX&kfO=F?EK=VEz`_LSGGi6|dFHsyL4q8Zy$5fp09DfC!xy(kJx4}(Wr zgm+Lu{{y`=UK9~M)QjLrd&+8Kno2E#2QLLDJDD|PA3O8DGrQlxR7^VlR-!C`-SLF+kVvn~07HglTK1}pA0Ed)}W}GwGF0`VDnNzv-=A$((I1@Z2 zcv^5n@QmPNf{zPs3T|z3+u-b4E92OClU;dv^Xs?>?9Bj;7tMkhyCqG79f4J|1h4E8 ztfB+&Ee8yo2E)$6Gphh+un2#wEZnn-uxL#~Ap5pmgdI6%S|zxFh1hG^%)%3M66kFk zkJ8_Lbm?M*6LhzW<<#LE-H-4zZFO;qU81cBPf~6dOZ7Pi;Enu01xyA9t&LbiqWiP` zs13dct?6kS^K_wuXIYK*+jwG(AHwp|3O(qcBZs1Ia{6Nj%d9~w2N=+oUwE9&((@k9 z*R`9bYpv;8=LWRu2)#N)uf}xR*uzOyRoLx4bY(vCT~=QHDJwru>pK#wZPKwV2d&jI zAkln)^+&M&5Y|`NwT{I4Nwu!bZy%tqs;yA{hs0_dwUZpQR?C1yt7S0oMzG!x)*Hfl z3M&uVWuB@wKIa+w-NpI5w$WIv^(K3CYZqUu%i{L%9Ek{z(VZSv=(D^)t#>`V-1rB3 CkGJOl