From 842b4b5fd4f605f5e95235b4d91786ce879fb4f2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 25 Apr 2013 08:15:56 -0400 Subject: [PATCH] Fixed bug with handling functions in select --- classes/db_pdo.php | 19 +- docs/classes/BadConnectionException.html | 2 +- docs/classes/BadDBDriverException.html | 2 +- docs/classes/DB_PDO.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 | 2 +- docs/classes/Query_Parser.html | 2 +- docs/classes/SQLite.html | 2 +- docs/classes/SQLite_SQL.html | 2 +- docs/classes/SQLite_Util.html | 2 +- docs/classes/iDB_SQL.html | 2 +- docs/classes/iQuery_Builder.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.Query.html | 2 +- docs/packages/Query.html | 2 +- docs/structure.xml | 826 +++++++++++------------ tests/core/db_qb_test.php | 16 + tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 38 files changed, 480 insertions(+), 449 deletions(-) diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 8e26a0c..c724670 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -279,8 +279,23 @@ abstract class DB_PDO extends PDO { $hiers = explode('.', $ident); $hiers = array_map('mb_trim', $hiers); - // Return the re-compiled string - return implode('.', array_map(array($this, '_quote'), $hiers)); + // Re-compile the string + $raw = implode('.', array_map(array($this, '_quote'), $hiers)); + + // Fix functions + $funcs = array(); + preg_match_all("#{$this->escape_char}([a-zA-Z0-9_]+(\((.*?)\))){$this->escape_char}#iu", $raw, $funcs, PREG_SET_ORDER); + foreach($funcs as $f) + { + // Unquote the function + $raw = str_replace($f[0], $f[1], $raw); + + // Quote the inside identifiers + $raw = str_replace($f[3], $this->quote_ident($f[3]), $raw); + } + + return $raw; + } // -------------------------------------------------------------------------- diff --git a/docs/classes/BadConnectionException.html b/docs/classes/BadConnectionException.html index 9085c7d..8e86e5e 100644 --- a/docs/classes/BadConnectionException.html +++ b/docs/classes/BadConnectionException.html @@ -219,7 +219,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/BadDBDriverException.html b/docs/classes/BadDBDriverException.html index 1729ee2..89c7267 100644 --- a/docs/classes/BadDBDriverException.html +++ b/docs/classes/BadDBDriverException.html @@ -219,7 +219,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/DB_PDO.html b/docs/classes/DB_PDO.html index 4e29888..4b0cb8a 100644 --- a/docs/classes/DB_PDO.html +++ b/docs/classes/DB_PDO.html @@ -743,7 +743,7 @@ the connection/database
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/DB_Util.html b/docs/classes/DB_Util.html index a2559ef..6d9264b 100644 --- a/docs/classes/DB_Util.html +++ b/docs/classes/DB_Util.html @@ -210,7 +210,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/Firebird.html b/docs/classes/Firebird.html index cd2a8a6..afc1326 100644 --- a/docs/classes/Firebird.html +++ b/docs/classes/Firebird.html @@ -925,7 +925,7 @@ the last query executed
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/Firebird_Result.html b/docs/classes/Firebird_Result.html index ec63ecc..1a49b47 100644 --- a/docs/classes/Firebird_Result.html +++ b/docs/classes/Firebird_Result.html @@ -505,7 +505,7 @@ the query
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/Firebird_SQL.html b/docs/classes/Firebird_SQL.html index b274683..4b7822b 100644 --- a/docs/classes/Firebird_SQL.html +++ b/docs/classes/Firebird_SQL.html @@ -234,7 +234,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/Firebird_Util.html b/docs/classes/Firebird_Util.html index 529476f..9e7b629 100644 --- a/docs/classes/Firebird_Util.html +++ b/docs/classes/Firebird_Util.html @@ -213,7 +213,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/MySQL.html b/docs/classes/MySQL.html index ae96e5c..5027ea7 100644 --- a/docs/classes/MySQL.html +++ b/docs/classes/MySQL.html @@ -963,7 +963,7 @@ the connection/database
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/MySQL_SQL.html b/docs/classes/MySQL_SQL.html index 64ff136..7e06fe4 100644 --- a/docs/classes/MySQL_SQL.html +++ b/docs/classes/MySQL_SQL.html @@ -239,7 +239,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/MySQL_Util.html b/docs/classes/MySQL_Util.html index 064252b..70ae1e5 100644 --- a/docs/classes/MySQL_Util.html +++ b/docs/classes/MySQL_Util.html @@ -209,7 +209,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/ODBC.html b/docs/classes/ODBC.html index 1902b43..ce7948a 100644 --- a/docs/classes/ODBC.html +++ b/docs/classes/ODBC.html @@ -963,7 +963,7 @@ the connection/database
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/ODBC_SQL.html b/docs/classes/ODBC_SQL.html index e8d5e74..a1b72ae 100644 --- a/docs/classes/ODBC_SQL.html +++ b/docs/classes/ODBC_SQL.html @@ -234,7 +234,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/ODBC_Util.html b/docs/classes/ODBC_Util.html index 47b548b..114395e 100644 --- a/docs/classes/ODBC_Util.html +++ b/docs/classes/ODBC_Util.html @@ -204,7 +204,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/PgSQL.html b/docs/classes/PgSQL.html index 86fcd3f..397de51 100644 --- a/docs/classes/PgSQL.html +++ b/docs/classes/PgSQL.html @@ -965,7 +965,7 @@ the connection/database
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/PgSQL_SQL.html b/docs/classes/PgSQL_SQL.html index af8f54e..3e0d49d 100644 --- a/docs/classes/PgSQL_SQL.html +++ b/docs/classes/PgSQL_SQL.html @@ -234,7 +234,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/PgSQL_Util.html b/docs/classes/PgSQL_Util.html index 0293a10..e6ff280 100644 --- a/docs/classes/PgSQL_Util.html +++ b/docs/classes/PgSQL_Util.html @@ -209,7 +209,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/Query_Builder.html b/docs/classes/Query_Builder.html index 5c521f4..048f655 100644 --- a/docs/classes/Query_Builder.html +++ b/docs/classes/Query_Builder.html @@ -1361,7 +1361,7 @@ passed array with key / value pairs
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/Query_Parser.html b/docs/classes/Query_Parser.html index 8a7bfa1..92e5854 100644 --- a/docs/classes/Query_Parser.html +++ b/docs/classes/Query_Parser.html @@ -145,7 +145,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/SQLite.html b/docs/classes/SQLite.html index b7dc868..9ab42db 100644 --- a/docs/classes/SQLite.html +++ b/docs/classes/SQLite.html @@ -980,7 +980,7 @@ method if the database does not support 'TRUNCATE';
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/SQLite_SQL.html b/docs/classes/SQLite_SQL.html index 1e7f765..026bbcd 100644 --- a/docs/classes/SQLite_SQL.html +++ b/docs/classes/SQLite_SQL.html @@ -234,7 +234,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/SQLite_Util.html b/docs/classes/SQLite_Util.html index c708647..df4f60f 100644 --- a/docs/classes/SQLite_Util.html +++ b/docs/classes/SQLite_Util.html @@ -209,7 +209,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/iDB_SQL.html b/docs/classes/iDB_SQL.html index 320de39..471c415 100644 --- a/docs/classes/iDB_SQL.html +++ b/docs/classes/iDB_SQL.html @@ -244,7 +244,7 @@ specified table
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/classes/iQuery_Builder.html b/docs/classes/iQuery_Builder.html index 4c205d6..fea7a90 100644 --- a/docs/classes/iQuery_Builder.html +++ b/docs/classes/iQuery_Builder.html @@ -964,7 +964,7 @@ passed array with key / value pairs
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/deprecated.html b/docs/deprecated.html index f6c1461..497e9fd 100644 --- a/docs/deprecated.html +++ b/docs/deprecated.html @@ -68,7 +68,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/errors.html b/docs/errors.html index fff879c..9977fb8 100644 --- a/docs/errors.html +++ b/docs/errors.html @@ -237,7 +237,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/graph_class.html b/docs/graph_class.html index c5e7d6d..02ab063 100644 --- a/docs/graph_class.html +++ b/docs/graph_class.html @@ -65,7 +65,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/markers.html b/docs/markers.html index a81ac24..1e0358a 100644 --- a/docs/markers.html +++ b/docs/markers.html @@ -110,7 +110,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/namespaces/default.html b/docs/namespaces/default.html index f3cfd7d..61302cc 100644 --- a/docs/namespaces/default.html +++ b/docs/namespaces/default.html @@ -340,7 +340,7 @@ instantiates the specific db driver

+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/packages/.html b/docs/packages/.html index 730c09d..c3705ec 100644 --- a/docs/packages/.html +++ b/docs/packages/.html @@ -68,7 +68,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/packages/Default.html b/docs/packages/Default.html index 871e8b9..34d992d 100644 --- a/docs/packages/Default.html +++ b/docs/packages/Default.html @@ -95,7 +95,7 @@
+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/packages/Query.Drivers.html b/docs/packages/Query.Drivers.html index 9e99ff2..93aebbc 100644 --- a/docs/packages/Query.Drivers.html +++ b/docs/packages/Query.Drivers.html @@ -212,7 +212,7 @@ data-fetching methods

+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/packages/Query.Query.html b/docs/packages/Query.Query.html index 83849c1..c945f0f 100644 --- a/docs/packages/Query.Query.html +++ b/docs/packages/Query.Query.html @@ -150,7 +150,7 @@ instantiates the specific db driver

+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/packages/Query.html b/docs/packages/Query.html index b8d3533..ee51ce2 100644 --- a/docs/packages/Query.html +++ b/docs/packages/Query.html @@ -362,7 +362,7 @@ instantiates the specific db driver

+ generated on 2013-04-25T08:15:20-04:00.
diff --git a/docs/structure.xml b/docs/structure.xml index 4ec2f15..f8d336f 100644 --- a/docs/structure.xml +++ b/docs/structure.xml @@ -98,7 +98,7 @@ - + Free Query Builder / Database Abstraction Layer

]]>
@@ -350,228 +350,228 @@ - + _quote function - + - + mixed - + mixed - + $str - + 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 - + get_columns function - + - + string - + array - + $table - + get_types function - + - + array - + driver_query function - + - + string - + bool - + mixed - + $sql - + $filtered_index - + num_rows function - + - - + + int - + truncate function - + - + string - + void - + $table @@ -579,7 +579,7 @@ the connection/database]]>
- + Free Query Builder / Database Abstraction Layer

]]>
@@ -712,1347 +712,1347 @@ instantiates the specific db driver]]> - + select function - + - + string - + \$this - + $fields - + _select function - + - + string - + string - + string - + $field - + $as - + 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 - + $tblname - + _like function - + - + string - + mixed - + string - + string - + string - + \$this - + $field - + $val - + $pos - + $like - + $conj - + 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 - + string - + \$this - + $key - + $val - + $conj - + having function - + - + mixed - + mixed - + \$this - + $key - + $val - + or_having function - + - + mixed - + mixed - + \$this - + $key - + $val - + _where function - + - + mixed - + mixed - + array - + $key - + $val - + _where_string function - + - + mixed - + mixed - + string - + \$this - + $key - + $val - + $conj - + _where_in function - + - + mixed - + mixed - - - + + + \$this - + $key - + $val - + $in - + $conj - + where function - + - + mixed - + mixed - + \$this - + $key - + $val - + or_where function - + - + string - + mixed - + \$this - + $key - + $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 - + get_compiled_select function - + - + string - + bool - + string - + $table - + $reset - + get_compiled_insert function - + - + string - + bool - + string - + $table - + $reset - + get_compiled_update function - + - + string - + bool - + string - + $table - + $reset - + get_compiled_delete function - + - + string - + bool - + string - + $table - + $reset - + _get_compile function - + - + string - + string - - + + - + $type - + $table - + $reset - + reset_query function - + - + void - + _run function - + - + string - + string - + bool - + mixed - + $type - + $table - + $simple - + __call function - + - + string - + array - + mixed - + $name - + $params - + _compile function - + - + string - + string - + \$string - + $type - + $table diff --git a/tests/core/db_qb_test.php b/tests/core/db_qb_test.php index 0bba7fa..50a05b8 100644 --- a/tests/core/db_qb_test.php +++ b/tests/core/db_qb_test.php @@ -36,6 +36,22 @@ abstract class QBTest extends UnitTestCase { $this->assertReference($this->db, $db); } + // -------------------------------------------------------------------------- + + public function TestFunctionGet() + { + if (empty($this->db)) return; + + $query = $this->db->select('id, COUNT(id) as count') + ->from('test') + ->group_by('id') + ->get(); + + $this->assertIsA($query, 'PDOStatement'); + } + + // -------------------------------------------------------------------------- + public function TestGet() { if (empty($this->db)) return; diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index a7155a803c8660394ece15f1d0161e07ef8295dc..144d10b4f4b07bcccd9e64489a0c3bd675187fa6 100755 GIT binary patch delta 2487 zcmb7FO=wd=5T1R>OVezVY-`1z7HMtzN71HW6+zI8cqoVmMd(3Wsq|7BszQ%Vp7x<2 zdJtK`vmhQ+6s%XFg%%AZNYVIn_2N}Q4*_TPC-1dQTQgy^`7--v=6y4>lg|(3^FwDD z9M5L@ArQgy5rb$i_X2#w1>ms9UjWV@TkUdgvFSs3vAB_)AiH?Pz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