diff --git a/classes/db_pdo.php b/classes/db_pdo.php index a24279f..2e048ce 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -25,21 +25,29 @@ abstract class DB_PDO extends PDO { /** * Reference to the last executed query + * + * @var mixed */ protected $statement; /** * Character to escape identifiers + * + * @var string */ protected $escape_char = '"'; /** * Reference to sql sub class + * + * @var Object */ public $sql; /** * Reference to util sub class + * + * @var Object */ public $util; diff --git a/classes/query_builder.php b/classes/query_builder.php index 292a57f..1ea6534 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -147,10 +147,6 @@ class Query_Builder { * @var string */ public $conn_name = ""; - - // -------------------------------------------------------------------------- - // ! Start of methods - // -------------------------------------------------------------------------- /** * Constructor @@ -277,13 +273,13 @@ class Query_Builder { // -------------------------------------------------------------------------- /** - * Selects the maximum value of a field from a query + * Method to simplify select_ methods * * @param string $field * @param string $as - * @return $this + * @return string */ - public function select_max($field, $as=FALSE) + private function _select($field, $as = FALSE) { // Escape the identifiers $field = $this->quote_ident($field); @@ -292,9 +288,22 @@ class Query_Builder { ? $this->quote_ident($as) : $field; + return "({$field}) AS {$as} "; + } + + // -------------------------------------------------------------------------- + + /** + * Selects the maximum value of a field from a query + * + * @param string $field + * @param string $as + * @return $this + */ + public function select_max($field, $as=FALSE) + { // Create the select string - $this->select_string .= $this->sql->max()."({$field}) AS {$as} "; - + $this->select_string .= $this->sql->max().$this->_select($field, $as); return $this; } @@ -308,17 +317,9 @@ class Query_Builder { * @return $this */ public function select_min($field, $as=FALSE) - { - // Escape the identifiers - $field = $this->quote_ident($field); - - $as = ($as !== FALSE) - ? $this->quote_ident($as) - : $field; - + { // Create the select string - $this->select_string .= $this->sql->min()."({$field}) AS {$as} "; - + $this->select_string .= $this->sql->min().$this->_select($field, $as); return $this; } @@ -333,16 +334,8 @@ class Query_Builder { */ public function select_avg($field, $as=FALSE) { - // Escape the identifiers - $field = $this->quote_ident($field); - - $as = ($as !== FALSE) - ? $this->quote_ident($as) - : $field; - // Create the select string - $this->select_string .= $this->sql->avg()."({$field}) AS {$as} "; - + $this->select_string .= $this->sql->avg().$this->_select($field, $as); return $this; } @@ -357,16 +350,8 @@ class Query_Builder { */ public function select_sum($field, $as=FALSE) { - // Escape the identifiers - $field = $this->quote_ident($field); - - $as = ($as !== FALSE) - ? $this->quote_ident($as) - : $field; - // Create the select string - $this->select_string .= $this->sql->sum()."({$field}) AS {$as} "; - + $this->select_string .= $this->sql->sum().$this->_select($field, $as); return $this; } @@ -381,7 +366,6 @@ class Query_Builder { { // Prepend the keyword to the select string $this->select_string = $this->sql->distinct() . $this->select_string; - return $this; } @@ -898,6 +882,8 @@ class Query_Builder { */ public function join($table, $condition, $type='') { + // @todo make able to handle operators without spaces + $table = implode(" ", array_map(array($this->db, 'quote_ident'), explode(' ', trim($table)))); //$condition = preg_replace('`(\W)`', " $1 ", $condition); $cond_array = explode(' ', trim($condition)); @@ -1304,12 +1290,10 @@ class Query_Builder { foreach($this as $name => $var) { // Skip properties that are needed for every query - $save_properties = array( + if (in_array($name, array( 'db', 'sql' - ); - - if (in_array($name, $save_properties)) + ))) { continue; } @@ -1341,11 +1325,13 @@ class Query_Builder { private function _compile($type='', $table='') { $sql = ''; + + $table = $this->quote_ident($table); switch($type) { default: - $sql = 'SELECT * FROM '.$this->from_string; + $sql = "SELECT * FROM {$this->from_string}"; // Set the select string if ( ! empty($this->select_string)) @@ -1394,13 +1380,13 @@ class Query_Builder { case "insert": $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) . + $sql = "INSERT INTO {$table} (" + . implode(', ', $this->set_array_keys) . ') VALUES ('.implode(', ', $params).')'; break; case "update": - $sql = 'UPDATE '.$this->quote_ident($table). ' SET '. $this->set_string; + $sql = "UPDATE {$table} SET {$this->set_string}"; // Set the where string if ( ! empty($this->query_map)) @@ -1413,7 +1399,7 @@ class Query_Builder { break; case "delete": - $sql = 'DELETE FROM '.$this->quote_ident($table); + $sql = "DELETE FROM {$table}"; // Set the where string if ( ! empty($this->query_map)) diff --git a/docs/classes/DB_PDO.html b/docs/classes/DB_PDO.html index 0fc2526..2ff2dde 100644 --- a/docs/classes/DB_PDO.html +++ b/docs/classes/DB_PDO.html @@ -633,25 +633,25 @@ the connection/database  Properties  

Reference to sql sub class

-
$sql 
+
$sql : Object

 

Reference to util sub class

-
$util 
+
$util : Object

 

Character to escape identifiers

-
$escape_char 
+
$escape_char : string

 

Reference to the last executed query

-
$statement 
+
$statement : mixed

@@ -662,7 +662,7 @@ the connection/database
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/DB_Reg.html b/docs/classes/DB_Reg.html index d7230ca..0b01bb4 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-30T15:29:34-04:00.
diff --git a/docs/classes/DB_SQL.html b/docs/classes/DB_SQL.html index 61e9d27..490968b 100644 --- a/docs/classes/DB_SQL.html +++ b/docs/classes/DB_SQL.html @@ -268,7 +268,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/DB_Util.html b/docs/classes/DB_Util.html index 5d99ae1..e5d70c7 100644 --- a/docs/classes/DB_Util.html +++ b/docs/classes/DB_Util.html @@ -208,7 +208,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/Firebird.html b/docs/classes/Firebird.html index 45057b9..3de3c56 100644 --- a/docs/classes/Firebird.html +++ b/docs/classes/Firebird.html @@ -746,7 +746,7 @@ the connection/database  Properties  

Reference to sql sub class

-
$sql 
+
$sql : Object
Inherited

@@ -758,7 +758,7 @@ the connection/database
 

Reference to util sub class

-
$util 
+
$util : Object
Inherited

@@ -776,7 +776,7 @@ the connection/database
 

Character to escape identifiers

-
$escape_char 
+
$escape_char : string
Inherited

@@ -812,7 +812,7 @@ the last query executed
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/Firebird_Result.html b/docs/classes/Firebird_Result.html index 792e2b2..990238b 100644 --- a/docs/classes/Firebird_Result.html +++ b/docs/classes/Firebird_Result.html @@ -503,7 +503,7 @@ the query
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/Firebird_SQL.html b/docs/classes/Firebird_SQL.html index bbf0800..128ef87 100644 --- a/docs/classes/Firebird_SQL.html +++ b/docs/classes/Firebird_SQL.html @@ -296,7 +296,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/Firebird_Util.html b/docs/classes/Firebird_Util.html index de9382a..e30c95b 100644 --- a/docs/classes/Firebird_Util.html +++ b/docs/classes/Firebird_Util.html @@ -211,7 +211,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/MySQL.html b/docs/classes/MySQL.html index c4dfbfe..3a04d8a 100644 --- a/docs/classes/MySQL.html +++ b/docs/classes/MySQL.html @@ -801,7 +801,7 @@ the connection/database  Properties  

Reference to sql sub class

-
$sql 
+
$sql : Object
Inherited

@@ -813,7 +813,7 @@ the connection/database
 

Reference to util sub class

-
$util 
+
$util : Object
Inherited

@@ -831,7 +831,7 @@ the connection/database
 

Reference to the last executed query

-
$statement 
+
$statement : mixed
Inherited

@@ -848,7 +848,7 @@ the connection/database
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/MySQL_SQL.html b/docs/classes/MySQL_SQL.html index a644134..b9f6c84 100644 --- a/docs/classes/MySQL_SQL.html +++ b/docs/classes/MySQL_SQL.html @@ -280,7 +280,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/MySQL_Util.html b/docs/classes/MySQL_Util.html index 47e10be..2a07160 100644 --- a/docs/classes/MySQL_Util.html +++ b/docs/classes/MySQL_Util.html @@ -207,7 +207,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/ODBC.html b/docs/classes/ODBC.html index 925baaa..7a29de0 100644 --- a/docs/classes/ODBC.html +++ b/docs/classes/ODBC.html @@ -803,7 +803,7 @@ the connection/database  Properties  

Reference to sql sub class

-
$sql 
+
$sql : Object
Inherited

@@ -815,7 +815,7 @@ the connection/database
 

Reference to util sub class

-
$util 
+
$util : Object
Inherited

@@ -827,13 +827,13 @@ the connection/database
 

Don't define the escape char - or define it in sub-drivers in a refactor

-
$escape_char 
+
$escape_char : string

 

Reference to the last executed query

-
$statement 
+
$statement : mixed
Inherited

@@ -850,7 +850,7 @@ the connection/database
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/ODBC_SQL.html b/docs/classes/ODBC_SQL.html index 7c88283..85d526d 100644 --- a/docs/classes/ODBC_SQL.html +++ b/docs/classes/ODBC_SQL.html @@ -280,7 +280,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/ODBC_Util.html b/docs/classes/ODBC_Util.html index 2b79b1f..10e6a26 100644 --- a/docs/classes/ODBC_Util.html +++ b/docs/classes/ODBC_Util.html @@ -202,7 +202,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/PgSQL.html b/docs/classes/PgSQL.html index 1624b70..3a92011 100644 --- a/docs/classes/PgSQL.html +++ b/docs/classes/PgSQL.html @@ -797,7 +797,7 @@ the connection/database  Properties  

Reference to sql sub class

-
$sql 
+
$sql : Object
Inherited

@@ -809,7 +809,7 @@ the connection/database
 

Reference to util sub class

-
$util 
+
$util : Object
Inherited

@@ -821,7 +821,7 @@ the connection/database
 

Character to escape identifiers

-
$escape_char 
+
$escape_char : string
Inherited

@@ -833,7 +833,7 @@ the connection/database
 

Reference to the last executed query

-
$statement 
+
$statement : mixed
Inherited

@@ -850,7 +850,7 @@ the connection/database
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/PgSQL_SQL.html b/docs/classes/PgSQL_SQL.html index f6940e3..3426273 100644 --- a/docs/classes/PgSQL_SQL.html +++ b/docs/classes/PgSQL_SQL.html @@ -296,7 +296,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/PgSQL_Util.html b/docs/classes/PgSQL_Util.html index c6fd18f..584ece8 100644 --- a/docs/classes/PgSQL_Util.html +++ b/docs/classes/PgSQL_Util.html @@ -207,7 +207,7 @@
+ generated on 2012-04-30T15:29:34-04:00.
diff --git a/docs/classes/Query_Builder.html b/docs/classes/Query_Builder.html index 51ae102..a6d3e0c 100644 --- a/docs/classes/Query_Builder.html +++ b/docs/classes/Query_Builder.html @@ -108,6 +108,7 @@ passed array with key / value pairs
where()
  • String together the sql statements for sending to the db
    _compile()
  • Clear out the class variables, so the next query can be run
    _reset()
  • +
  • Method to simplify select_ methods
    _select()
  • Do all the repeditive stuff for where/having type methods
    _where()
  • @@ -954,6 +955,25 @@ passed array with key / value pairs

    +
    +

    Method to simplify select_ methods

    +
    _select(string $field, string $as) : string
    +
    +
    +

    +

    Parameters

    +
    +

    $field

    +string +
    +
    +

    $as

    +string +
    +

    Returns

    +
    string
    +
    +

    Do all the repeditive stuff for where/having type methods

    _where(mixed $key, mixed $val) : array
    @@ -1079,7 +1099,7 @@ for complex select queries
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/classes/SQLite.html b/docs/classes/SQLite.html index 0c10746..0a919a4 100644 --- a/docs/classes/SQLite.html +++ b/docs/classes/SQLite.html @@ -818,7 +818,7 @@ method if the database does not support 'TRUNCATE';  Properties  

    Reference to sql sub class

    -
    $sql 
    +
    $sql : Object
    Inherited

    @@ -830,7 +830,7 @@ method if the database does not support 'TRUNCATE';
     

    Reference to util sub class

    -
    $util 
    +
    $util : Object
    Inherited

    @@ -842,7 +842,7 @@ method if the database does not support 'TRUNCATE';
     

    Character to escape identifiers

    -
    $escape_char 
    +
    $escape_char : string
    Inherited

    @@ -865,7 +865,7 @@ method if the database does not support 'TRUNCATE';
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/classes/SQLite_SQL.html b/docs/classes/SQLite_SQL.html index f14b7cb..34c84e2 100644 --- a/docs/classes/SQLite_SQL.html +++ b/docs/classes/SQLite_SQL.html @@ -280,7 +280,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/classes/SQLite_Util.html b/docs/classes/SQLite_Util.html index 85c1697..9403fc3 100644 --- a/docs/classes/SQLite_Util.html +++ b/docs/classes/SQLite_Util.html @@ -207,7 +207,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/classes/Settings.html b/docs/classes/Settings.html index c66f2f8..e90e3a8 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-30T15:29:34-04:00.
    diff --git a/docs/deprecated.html b/docs/deprecated.html index d280714..1043183 100644 --- a/docs/deprecated.html +++ b/docs/deprecated.html @@ -66,7 +66,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/errors.html b/docs/errors.html index decfd00..3ec6cc0 100644 --- a/docs/errors.html +++ b/docs/errors.html @@ -92,7 +92,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/graph_class.html b/docs/graph_class.html index 58cfb20..8c13093 100644 --- a/docs/graph_class.html +++ b/docs/graph_class.html @@ -63,7 +63,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/markers.html b/docs/markers.html index 1347451..3749b1d 100644 --- a/docs/markers.html +++ b/docs/markers.html @@ -68,7 +68,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/namespaces/default.html b/docs/namespaces/default.html index 7ee131e..6ad7e83 100644 --- a/docs/namespaces/default.html +++ b/docs/namespaces/default.html @@ -282,7 +282,7 @@ instantiates the specific db driver

    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/packages/.html b/docs/packages/.html index fa3b93e..b2444e8 100644 --- a/docs/packages/.html +++ b/docs/packages/.html @@ -66,7 +66,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/packages/Default.html b/docs/packages/Default.html index aec5f18..6a92425 100644 --- a/docs/packages/Default.html +++ b/docs/packages/Default.html @@ -93,7 +93,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/packages/Query.Drivers.html b/docs/packages/Query.Drivers.html index aeaaf70..f25ba68 100644 --- a/docs/packages/Query.Drivers.html +++ b/docs/packages/Query.Drivers.html @@ -210,7 +210,7 @@ data-fetching methods

    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/packages/Query.Helper Classes.html b/docs/packages/Query.Helper Classes.html index dfc4edc..bd54869 100644 --- a/docs/packages/Query.Helper Classes.html +++ b/docs/packages/Query.Helper Classes.html @@ -96,7 +96,7 @@
    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/packages/Query.Query.html b/docs/packages/Query.Query.html index 67f87f3..6298c6b 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-30T15:29:34-04:00.
    diff --git a/docs/packages/Query.html b/docs/packages/Query.html index c3bef02..b760c47 100644 --- a/docs/packages/Query.html +++ b/docs/packages/Query.html @@ -315,7 +315,7 @@ instantiates the specific db driver

    + generated on 2012-04-30T15:29:34-04:00.
    diff --git a/docs/structure.xml b/docs/structure.xml index 9a68f7a..a86d8f6 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

    ]]>
    @@ -530,391 +530,403 @@ directly - the settings should be safe!]]>
    - + $statement + + mixed + - + $escape_char - + + + string + - + $sql - + + + Object + - + $util - + + + Object + - + __construct function - + - + string - + string - + string - + array - + $dsn - + $username - + $password - + $driver_options - + prepare_query function - + - + string - + array - + mixed - + $sql - + $data - + prepare_execute function - + - + string - + array - + \PDOStatement - + $sql - + $params - + get_query_data function - + - + \PDOStatement - + array - + $statement - + affected_rows function - + - + \PDOStatement - + int - + $statement - + get_last_error function - + - + string - + quote_ident function - + - + mixed - + string - + $ident - + 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 +934,7 @@ the connection/database]]>
    - + Free Query Builder / Database Abstraction Layer

    ]]>
    @@ -1115,999 +1127,1026 @@ for complex select queries]]>
    - + __construct function - + - + object - + $params - + 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 - + $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/phpdoc.dist.xml b/phpdoc.dist.xml index 34a0008..5552b46 100644 --- a/phpdoc.dist.xml +++ b/phpdoc.dist.xml @@ -3,10 +3,6 @@ Query docs - docs diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 109d0c1..59d46e8 100644 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ