diff --git a/classes/db_pdo.php b/classes/db_pdo.php index c724670..f8a1aaa 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -61,6 +61,7 @@ abstract class DB_PDO extends PDO { $class = get_class($this)."_util"; $this->util = new $class($this); + // Set PDO to display errors as exceptions $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set additional driver options, if they exist @@ -92,7 +93,7 @@ abstract class DB_PDO extends PDO { if( ! (is_object($query) || is_resource($query))) { $this->get_last_error(); - return FALSE; + return NULL; } // Set the statement in the class variable for easy later access @@ -102,7 +103,7 @@ abstract class DB_PDO extends PDO { if( ! (is_array($data) || is_object($data))) { trigger_error("Invalid data argument"); - return FALSE; + return NULL; } // Bind the parameters @@ -118,7 +119,7 @@ abstract class DB_PDO extends PDO { if( ! $res) { trigger_error("Parameter not successfully bound"); - return FALSE; + return NULL; } } @@ -348,7 +349,7 @@ abstract class DB_PDO extends PDO { */ public function get_schemas() { - return FALSE; + return NULL; } // ------------------------------------------------------------------------- @@ -485,9 +486,9 @@ abstract class DB_PDO extends PDO { public function driver_query($sql, $filtered_index=TRUE) { // Return if the query doesn't apply to the driver - if ($sql === FALSE) + if ($sql === NULL) { - return FALSE; + return NULL; } // Return predefined data @@ -523,7 +524,7 @@ abstract class DB_PDO extends PDO { return $stmt->fetchColumn(); } - return FALSE; + return NULL; } // ------------------------------------------------------------------------- diff --git a/classes/idb_sql.php b/classes/idb_sql.php index dde779e..9fd1d04 100644 --- a/classes/idb_sql.php +++ b/classes/idb_sql.php @@ -78,7 +78,7 @@ interface iDB_SQL { /** * Return sql to list functions * - * @return FALSE + * @return NULL */ public function function_list(); @@ -111,5 +111,6 @@ interface iDB_SQL { * @return string */ public function column_list($table); + } // End of db_sql.php \ No newline at end of file diff --git a/classes/iquery_builder.php b/classes/iquery_builder.php index 077f924..cd5f2f8 100644 --- a/classes/iquery_builder.php +++ b/classes/iquery_builder.php @@ -32,7 +32,7 @@ interface iQuery_Builder { * @return $this */ public function select($fields); - + // -------------------------------------------------------------------------- /** @@ -252,7 +252,7 @@ interface iQuery_Builder { * @return $this */ public function set($key, $val = NULL); - + // -------------------------------------------------------------------------- /** @@ -385,7 +385,7 @@ interface iQuery_Builder { * @return int */ public function count_all_results($table=''); - + // -------------------------------------------------------------------------- /** @@ -399,6 +399,17 @@ interface iQuery_Builder { // -------------------------------------------------------------------------- + /** + * Creates a batch insert clause, and executes it + * + * @param string $table + * @param mixed $data + * @return mixed + */ + public function insert_batch($table, $data=array()); + + // -------------------------------------------------------------------------- + /** * Creates an update clause, and executes it * diff --git a/classes/query_builder.php b/classes/query_builder.php index 4c28c0d..55b9997 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -1019,6 +1019,41 @@ class Query_Builder implements iQuery_Builder { // -------------------------------------------------------------------------- + /** + * Creates a batch insert clause and executes it + * + * @param string $table + * @param mixed $data + * @return mixed + */ + public function insert_batch($table, $data=array()) + { + // Bail out on Firebird and ODBC + $driver = str_replace('_sql', '', mb_strtolower(get_class($this->sql))); + + if ($driver == 'firebird' || $driver == 'odbc') + { + return NULL; + } + + // Can't use normal set, because it doesn't handle multidimensional arrays + foreach($data as $key => $arr) + { + foreach($arr as $k => $v) + { + $this->set_array_keys[$key][] = $k; + $this->values[] = $v; + } + + // Escape the field names + $this->set_array_keys[$key] = $this->db->quote_ident($this->set_array_keys[$key]); + } + + return $this->_run("insert_batch", $table); + } + + // -------------------------------------------------------------------------- + /** * Creates an update clause, and executes it * @@ -1192,6 +1227,15 @@ class Query_Builder implements iQuery_Builder { $sql = $this->_compile($type, $table); $vals = array_merge($this->values, (array) $this->where_values); + // Add quotes to 'string' values + foreach($vals as &$v) + { + if ( ! is_numeric($v)) + { + $v = "'{$v}'"; + } + } + $start_time = microtime(TRUE); $res = ($simple) @@ -1217,6 +1261,7 @@ class Query_Builder implements iQuery_Builder { // Set the last query to get rowcounts properly $this->db->last_query = $sql; + // Reset class state for next query $this->reset_query(); return $res; @@ -1277,6 +1322,25 @@ class Query_Builder implements iQuery_Builder { . implode(',', $this->set_array_keys) . ') VALUES ('.implode(',', $params).')'; break; + + case "insert_batch": + $param_count = count($this->set_array_keys[0]); + $params = array_fill(0, $param_count, '?'); + $sql = "INSERT INTO {$table} (" + . implode(',', $this->set_array_keys[0]) + . ') VALUES ( ' + . implode(',', $params) . ')'; + + // Remove the first set from the array + array_shift($this->set_array_keys); + + // Add another set of placeholders for each batch group + foreach($this->set_array_keys as $group) + { + $sql .= ',('.implode(',', $params).')'; + } + + break; case "update": $sql = "UPDATE {$table} SET {$this->set_string}"; diff --git a/docs/classes/BadConnectionException.html b/docs/classes/BadConnectionException.html index 8e86e5e..fc4f633 100644 --- a/docs/classes/BadConnectionException.html +++ b/docs/classes/BadConnectionException.html @@ -219,7 +219,7 @@
+ generated on 2013-05-01T15:58:51-04:00.