-
+
@@ -188,20 +187,77 @@
+
+
+
+
+
+
+
+
+
@@ -210,14 +266,7 @@
+
@@ -226,11 +275,16 @@
@@ -362,7 +416,7 @@
Documentation is powered by phpDocumentor and authored
- on June 4th, 2015 at 15:15.
+ on July 17th, 2015 at 15:56.
diff --git a/docs/files/Query.SQL_Interface.php.html b/docs/files/Query.SQL_Interface.php.html
new file mode 100644
index 0000000..fa70c3a
--- /dev/null
+++ b/docs/files/Query.SQL_Interface.php.html
@@ -0,0 +1,427 @@
+
+
+
+
+
+
Query
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
QuerySQL_Interface.php
+
Query
+
Free Query Builder / Database Abstraction Layer
+
+
+
Interfaces
+
+
+ SQL_Interface |
+ parent for database manipulation subclasses |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/files/Query/Abstract_Driver.php.txt b/docs/files/Query/Abstract_Driver.php.txt
new file mode 100644
index 0000000..a665ad7
--- /dev/null
+++ b/docs/files/Query/Abstract_Driver.php.txt
@@ -0,0 +1,630 @@
+_load_sub_classes();
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Loads the subclasses for the driver
+ *
+ * @return void
+ */
+ protected function _load_sub_classes()
+ {
+ // Load the sql and util class for the driver
+ $this_class = get_class($this);
+ $ns_array = explode("\\", $this_class);
+ array_pop($ns_array);
+ $driver = array_pop($ns_array);
+ $sql_class = "\\Query\\Drivers\\{$driver}\\SQL";
+ $util_class = "\\Query\\Drivers\\{$driver}\\Util";
+
+ $this->sql = new $sql_class();
+ $this->util = new $util_class($this);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Allow invoke to work on table object
+ *
+ * @codeCoverageIgnore
+ * @param string $name
+ * @param array $args
+ * @return mixed
+ */
+ public function __call($name, $args = array())
+ {
+ if (
+ isset($this->$name)
+ && is_object($this->$name)
+ && method_exists($this->$name, '__invoke')
+ )
+ {
+ return call_user_func_array(array($this->$name, '__invoke'), $args);
+ }
+ }
+
+ // --------------------------------------------------------------------------
+ // ! Concrete functions that can be overridden in child classes
+ // --------------------------------------------------------------------------
+
+ /**
+ * Get the SQL class for the current driver
+ *
+ * @return SQL_Interface
+ */
+ public function get_sql()
+ {
+ return $this->sql;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Get the Util class for the current driver
+ *
+ * @return Abstract_Util
+ */
+ public function get_util()
+ {
+ return $this->util;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Simplifies prepared statements for database queries
+ *
+ * @param string $sql
+ * @param array $data
+ * @return \PDOStatement | FALSE
+ * @throws \InvalidArgumentException
+ */
+ public function prepare_query($sql, $data)
+ {
+ // Prepare the sql, save the statement for easy access later
+ $this->statement = $this->prepare($sql);
+
+ if( ! (is_array($data) || is_object($data)))
+ {
+ throw new \InvalidArgumentException("Invalid data argument");
+ }
+
+ // Bind the parameters
+ foreach($data as $k => $value)
+ {
+ // Parameters are 1-based, the data is 0-based
+ // So, if the key is numeric, add 1
+ if(is_numeric($k)) $k++;
+ $this->statement->bindValue($k, $value);
+ }
+
+ return $this->statement;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create and execute a prepared statement with the provided parameters
+ *
+ * @param string $sql
+ * @param array $params
+ * @return \PDOStatement
+ */
+ public function prepare_execute($sql, $params)
+ {
+ $this->statement = $this->prepare_query($sql, $params);
+ $this->statement->execute();
+
+ return $this->statement;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns number of rows affected by an INSERT, UPDATE, DELETE type query
+ *
+ * @return int
+ */
+ public function affected_rows()
+ {
+ // Return number of rows affected
+ return $this->statement->rowCount();
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Prefixes a table if it is not already prefixed
+ * @param string $table
+ * @return string
+ */
+ public function prefix_table($table)
+ {
+ // Add the prefix to the table name
+ // before quoting it
+ if ( ! empty($this->table_prefix))
+ {
+ // Split identifier by period, will split into:
+ // database.schema.table OR
+ // schema.table OR
+ // database.table OR
+ // table
+ $idents = explode('.', $table);
+ $segments = count($idents);
+
+ // Quote the last item, and add the database prefix
+ $idents[$segments - 1] = $this->_prefix(end($idents));
+
+ // Rejoin
+ $table = implode('.', $idents);
+ }
+
+ return $table;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Quote database table name, and set prefix
+ *
+ * @param string $table
+ * @return string
+ */
+ public function quote_table($table)
+ {
+ $table = $this->prefix_table($table);
+
+ // Finally, quote the table
+ return $this->quote_ident($table);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Surrounds the string with the databases identifier escape characters
+ *
+ * @param mixed $ident
+ * @return string
+ */
+ public function quote_ident($ident)
+ {
+ if (is_array($ident))
+ {
+ return array_map(array($this, __METHOD__), $ident);
+ }
+
+ // Handle comma-separated identifiers
+ if (strpos($ident, ',') !== FALSE)
+ {
+ $parts = array_map('mb_trim', explode(',', $ident));
+ $parts = array_map(array($this, __METHOD__), $parts);
+ $ident = implode(',', $parts);
+ }
+
+ // Split each identifier by the period
+ $hiers = explode('.', $ident);
+ $hiers = array_map('mb_trim', $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;
+
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return schemas for databases that list them
+ *
+ * @return array
+ */
+ public function get_schemas()
+ {
+ return NULL;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of tables for the current database
+ *
+ * @return array
+ */
+ public function get_tables()
+ {
+ $tables = $this->driver_query('table_list');
+ natsort($tables);
+ return $tables;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of dbs for the current connection, if possible
+ *
+ * @return array
+ */
+ public function get_dbs()
+ {
+ return $this->driver_query('db_list');
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of views for the current database
+ *
+ * @return array
+ */
+ public function get_views()
+ {
+ $views = $this->driver_query('view_list');
+ sort($views);
+ return $views;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of sequences for the current database, if they exist
+ *
+ * @return array
+ */
+ public function get_sequences()
+ {
+ return $this->driver_query('sequence_list');
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of functions for the current database
+ *
+ * @return array
+ */
+ public function get_functions()
+ {
+ return $this->driver_query('function_list', FALSE);
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of stored procedures for the current database
+ *
+ * @return array
+ */
+ public function get_procedures()
+ {
+ return $this->driver_query('procedure_list', FALSE);
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Return list of triggers for the current database
+ *
+ * @return array
+ */
+ public function get_triggers()
+ {
+ return $this->driver_query('trigger_list', FALSE);
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Retrieves an array of non-user-created tables for
+ * the connection/database
+ *
+ * @return array
+ */
+ public function get_system_tables()
+ {
+ return $this->driver_query('system_table_list');
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Retrieve column information for the current database table
+ *
+ * @param string $table
+ * @return array
+ */
+ public function get_columns($table)
+ {
+ return $this->driver_query($this->get_sql()->column_list($this->prefix_table($table)), FALSE);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Retrieve foreign keys for the table
+ *
+ * @param string $table
+ * @return array
+ */
+ public function get_fks($table)
+ {
+ return $this->driver_query($this->get_sql()->fk_list($table), FALSE);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Retrieve indexes for the table
+ *
+ * @param string $table
+ * @return array
+ */
+ public function get_indexes($table)
+ {
+ return $this->driver_query($this->get_sql()->index_list($this->prefix_table($table)), FALSE);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Retrieve list of data types for the database
+ *
+ * @return array
+ */
+ public function get_types()
+ {
+ return $this->driver_query('type_list', FALSE);
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Method to simplify retrieving db results for meta-data queries
+ *
+ * @param string|array|null $query
+ * @param bool $filtered_index
+ * @return array
+ */
+ public function driver_query($query, $filtered_index=TRUE)
+ {
+ // Call the appropriate method, if it exists
+ if (is_string($query) && method_exists($this->sql, $query))
+ {
+ $query = $this->get_sql()->$query();
+ }
+
+ // Return if the values are returned instead of a query,
+ // or if the query doesn't apply to the driver
+ if ( ! is_string($query)) return $query;
+
+ // Run the query!
+ $res = $this->query($query);
+
+ $flag = ($filtered_index) ? \PDO::FETCH_NUM : \PDO::FETCH_ASSOC;
+ $all = $res->fetchAll($flag);
+
+ return ($filtered_index) ? \db_filter($all, 0) : $all;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Return the number of rows returned for a SELECT query
+ *
+ * @see http://us3.php.net/manual/en/pdostatement.rowcount.php#87110
+ * @return int
+ */
+ public function num_rows()
+ {
+ $regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
+ $output = array();
+
+ if (preg_match($regex, $this->last_query, $output) > 0)
+ {
+ $stmt = $this->query("SELECT COUNT(*) FROM {$output[1]}");
+ return (int) $stmt->fetchColumn();
+ }
+
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create sql for batch insert
+ *
+ * @param string $table
+ * @param array $data
+ * @return array
+ */
+ public function insert_batch($table, $data=array())
+ {
+ $first_row = current($data);
+ if ( ! is_array($first_row)) return NULL;
+
+ // Values for insertion
+ $vals = array();
+ foreach($data as $group)
+ {
+ $vals = array_merge($vals, array_values($group));
+ }
+ $table = $this->quote_table($table);
+ $fields = array_keys($first_row);
+
+ $sql = "INSERT INTO {$table} ("
+ . implode(',', $this->quote_ident($fields))
+ . ") VALUES ";
+
+ // Create the placeholder groups
+ $params = array_fill(0, count($fields), '?');
+ $param_string = "(" . implode(',', $params) . ")";
+ $param_list = array_fill(0, count($data), $param_string);
+
+ // Append the placeholder groups to the query
+ $sql .= implode(',', $param_list);
+
+ return array($sql, $vals);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Helper method for quote_ident
+ *
+ * @param mixed $str
+ * @return mixed
+ */
+ public function _quote($str)
+ {
+ // Check that the current value is a string,
+ // and is not already quoted before quoting
+ // that value, otherwise, return the original value
+ return (
+ is_string($str)
+ && strpos($str, $this->escape_char) !== 0
+ && strrpos($str, $this->escape_char) !== 0
+ )
+ ? "{$this->escape_char}{$str}{$this->escape_char}"
+ : $str;
+
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Sets the table prefix on the passed string
+ *
+ * @param string $str
+ * @return string
+ */
+ protected function _prefix($str)
+ {
+ // Don't prefix an already prefixed table
+ if (strpos($str, $this->table_prefix) !== FALSE)
+ {
+ return $str;
+ }
+
+ return $this->table_prefix.$str;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * Empty the passed table
+ *
+ * @param string $table
+ * @return \PDOStatement
+ */
+ public function truncate($table)
+ {
+ $sql = ($this->has_truncate)
+ ? 'TRUNCATE '
+ : 'DELETE FROM ';
+
+ $sql .= $this->quote_table($table);
+
+ $this->statement = $this->query($sql);
+ return $this->statement;
+ }
+
+}
+// End of db_pdo.php
diff --git a/docs/files/Query/Abstract_Query_Builder.php.txt b/docs/files/Query/Abstract_Query_Builder.php.txt
index 2261b19..b60ddda 100644
--- a/docs/files/Query/Abstract_Query_Builder.php.txt
+++ b/docs/files/Query/Abstract_Query_Builder.php.txt
@@ -14,7 +14,6 @@
// --------------------------------------------------------------------------
namespace Query;
-use \Query\Driver\Driver_Interface;
// --------------------------------------------------------------------------
diff --git a/docs/files/Query/Abstract_SQL.php.txt b/docs/files/Query/Abstract_SQL.php.txt
new file mode 100644
index 0000000..62d33f1
--- /dev/null
+++ b/docs/files/Query/Abstract_SQL.php.txt
@@ -0,0 +1,47 @@
+conn = $conn;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Get the driver object for the current connection
+ *
+ * @return Driver_Interface
+ */
+ public function get_driver()
+ {
+ return $this->conn;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Convenience public function to generate sql for creating a db table
+ *
+ * @param string $name
+ * @param array $fields
+ * @param array $constraints
+ * @param bool $if_not_exists
+ * @return string
+ */
+ public function create_table($name, $fields, array $constraints=array(), $if_not_exists=TRUE)
+ {
+ $exists_str = ($if_not_exists) ? ' IF NOT EXISTS ' : ' ';
+
+ // Reorganize into an array indexed with column information
+ // Eg $column_array[$colname] = array(
+ // 'type' => ...,
+ // 'constraint' => ...,
+ // 'index' => ...,
+ // )
+ $column_array = \array_zipper(array(
+ 'type' => $fields,
+ 'constraint' => $constraints
+ ));
+
+ // Join column definitions together
+ $columns = array();
+ foreach($column_array as $n => $props)
+ {
+ $str = $this->get_driver()->quote_ident($n);
+ $str .= (isset($props['type'])) ? " {$props['type']}" : "";
+ $str .= (isset($props['constraint'])) ? " {$props['constraint']}" : "";
+
+ $columns[] = $str;
+ }
+
+ // Generate the sql for the creation of the table
+ $sql = 'CREATE TABLE'.$exists_str.$this->get_driver()->quote_table($name).' (';
+ $sql .= implode(', ', $columns);
+ $sql .= ')';
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Drop the selected table
+ *
+ * @param string $name
+ * @return string
+ */
+ public function delete_table($name)
+ {
+ return 'DROP TABLE IF EXISTS '.$this->get_driver()->quote_table($name);
+ }
+
+
+ // --------------------------------------------------------------------------
+ // ! Abstract Methods
+ // --------------------------------------------------------------------------
+
+ /**
+ * Return an SQL file with the database table structure
+ *
+ * @abstract
+ * @return string
+ */
+ abstract public function backup_structure();
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Return an SQL file with the database data as insert statements
+ *
+ * @abstract
+ * @return string
+ */
+ abstract public function backup_data();
+
+}
+// End of abstract_util.php
diff --git a/docs/files/Query/Connection_Manager.php.txt b/docs/files/Query/Connection_Manager.php.txt
index 914dad3..eb01f3c 100644
--- a/docs/files/Query/Connection_Manager.php.txt
+++ b/docs/files/Query/Connection_Manager.php.txt
@@ -121,7 +121,8 @@ final class Connection_Manager {
{
list($dsn, $dbtype, $params, $options) = $this->parse_params($params);
- $driver = "\\Query\\Driver\\{$dbtype}";
+ $dbtype = ucfirst($dbtype);
+ $driver = "\\Query\\Drivers\\{$dbtype}\\Driver";
// Create the database connection
$db = ( ! empty($params->user))
@@ -164,9 +165,10 @@ final class Connection_Manager {
{
$params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
+ $dbtype = ucfirst($dbtype);
// Make sure the class exists
- if ( ! class_exists("Query\\Driver\\{$dbtype}"))
+ if ( ! class_exists("\\Query\\Drivers\\{$dbtype}\\Driver"))
{
throw new BadDBDriverException('Database driver does not exist, or is not supported');
}
@@ -180,7 +182,19 @@ final class Connection_Manager {
}
// Create the dsn for the database to connect to
- $dsn = $this->create_dsn($dbtype, $params);
+ if (strtolower($dbtype) === 'firebird')
+ {
+ $dsn = "{$params->host}:{$params->file}";
+ }
+ else if(strtolower($dbtype === 'sqlite'))
+ {
+ $dsn = $params->file;
+ }
+ else
+ {
+ $dsn = $this->create_dsn($dbtype, $params);
+ }
+
return array($dsn, $dbtype, $params, $options);
}
@@ -196,35 +210,32 @@ final class Connection_Manager {
*/
private function create_dsn($dbtype, \stdClass $params)
{
- if ($dbtype === 'firebird') $dsn = "{$params->host}:{$params->file}";
- elseif ($dbtype === 'sqlite') $dsn = $params->file;
- else
+ if (strtolower($dbtype) === 'pdo_firebird') $dbtype = 'firebird';
+
+ $dsn = strtolower($dbtype) . ':';
+
+ if ( ! empty($params->database))
{
- $dsn = strtolower($dbtype) . ':';
+ $dsn .= "dbname={$params->database}";
+ }
- if ( ! empty($params->database))
+ $skip = array(
+ 'name' => 'name',
+ 'pass' => 'pass',
+ 'user' => 'user',
+ 'file' => 'file',
+ 'type' => 'type',
+ 'prefix' => 'prefix',
+ 'options' => 'options',
+ 'database' => 'database',
+ 'alias' => 'alias'
+ );
+
+ foreach($params as $key => $val)
+ {
+ if (( ! array_key_exists($key, $skip)) && ! empty($val))
{
- $dsn .= "dbname={$params->database}";
- }
-
- $skip = array(
- 'name' => 'name',
- 'pass' => 'pass',
- 'user' => 'user',
- 'file' => 'file',
- 'type' => 'type',
- 'prefix' => 'prefix',
- 'options' => 'options',
- 'database' => 'database',
- 'alias' => 'alias'
- );
-
- foreach($params as $key => $val)
- {
- if ( ! isset($skip[$key]))
- {
- $dsn .= ";{$key}={$val}";
- }
+ $dsn .= ";{$key}={$val}";
}
}
diff --git a/docs/files/Query/Driver_Interface.php.txt b/docs/files/Query/Driver_Interface.php.txt
new file mode 100644
index 0000000..e0a2d38
--- /dev/null
+++ b/docs/files/Query/Driver_Interface.php.txt
@@ -0,0 +1,275 @@
+conn = $connect_function($dbpath, $user, $pass, 'utf-8', 0);
+ $this->service = \fbird_service_attach('localhost', $user, $pass);
+
+ // Throw an exception to make this match other pdo classes
+ if ( ! \is_resource($this->conn)) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
+
+ // Load these classes here because this
+ // driver does not call the constructor
+ // of DB_PDO, which defines these
+ // class variables for the other drivers
+ $this->_load_sub_classes();
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Cleanup some loose ends
+ * @codeCoverageIgnore
+ */
+ public function __destruct()
+ {
+ \fbird_service_detach($this->service);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Return service handle
+ *
+ * @return resource
+ */
+ public function get_service()
+ {
+ return $this->service;
+ }
+
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Execute an sql statement and return number of affected rows
+ *
+ * @param string $sql
+ * @return int
+ */
+ public function exec($sql)
+ {
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Implement for compatibility with PDO
+ *
+ * @param int $attribute
+ * @return mixed
+ */
+ public function getAttribute($attribute)
+ {
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Return whether the current statement is in a transaction
+ *
+ * @return bool
+ */
+ public function inTransaction()
+ {
+ return ! is_null($this->trans);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Returns the last value of the specified generator
+ *
+ * @param string $name
+ * @return mixed
+ */
+ public function lastInsertId($name = NULL)
+ {
+ return \fbird_gen_id($name, 0, $this->conn);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Wrapper public function to better match PDO
+ *
+ * @param string $sql
+ * @return Firebird_Result
+ * @throws PDOException
+ */
+ public function query($sql = '')
+ {
+
+ if (empty($sql)) throw new \PDOException("Query method requires an sql query!", 0, NULL);
+
+ $this->statement_link = (isset($this->trans))
+ ? \fbird_query($this->trans, $sql)
+ : \fbird_query($this->conn, $sql);
+
+ // Throw the error as a exception
+ $err_string = \fbird_errmsg() . "Last query:" . $this->last_query;
+ if ($this->statement_link === FALSE) throw new \PDOException($err_string, \fbird_errcode(), NULL);
+
+ $this->statement = new Result($this->statement_link, $this);
+
+ return $this->statement;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Emulate PDO prepare
+ *
+ * @param string $query
+ * @param array $options
+ * @return Firebird_Result
+ * @throws \PDOException
+ */
+ public function prepare($query, $options=array())
+ {
+ $this->statement_link = \fbird_prepare($this->conn, $query);
+
+ // Throw the error as an exception
+ if ($this->statement_link === FALSE) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
+
+ $this->statement = new Result($this->statement_link, $this);
+
+ return $this->statement;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Start a database transaction
+ *
+ * @return boolean|null
+ */
+ public function beginTransaction()
+ {
+ return (($this->trans = \fbird_trans($this->conn)) !== NULL) ? TRUE : NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Commit a database transaction
+ *
+ * @return bool
+ */
+ public function commit()
+ {
+ $res = \fbird_commit($this->trans);
+ $this->trans = NULL;
+ return $res;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Rollback a transaction
+ *
+ * @return bool
+ */
+ public function rollBack()
+ {
+ $res = \fbird_rollback($this->trans);
+ $this->trans = NULL;
+ return $res;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Set a connection attribute
+ * @param int $attribute
+ * @param mixed $value
+ * @return bool
+ */
+ public function setAttribute($attribute, $value)
+ {
+ return FALSE;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Prepare and execute a query
+ *
+ * @param string $sql
+ * @param array $args
+ * @return Firebird_Result
+ */
+ public function prepare_execute($sql, $args)
+ {
+ $query = $this->prepare($sql);
+
+ // Set the statement in the class variable for easy later access
+ $this->statement_link =& $query;
+
+ return $query->execute($args);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Method to emulate PDO->quote
+ *
+ * @param string $str
+ * @param int $param_type
+ * @return string
+ */
+ public function quote($str, $param_type = \PDO::PARAM_STR)
+ {
+ if(is_numeric($str))
+ {
+ return $str;
+ }
+
+ return "'".str_replace("'", "''", $str)."'";
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Method to emulate PDO->errorInfo / PDOStatement->errorInfo
+ *
+ * @return array
+ */
+ public function errorInfo()
+ {
+ $code = \fbird_errcode();
+ $msg = \fbird_errmsg();
+
+ return array(0, $code, $msg);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Method to emulate PDO->errorCode
+ *
+ * @return array
+ */
+ public function errorCode()
+ {
+ return \fbird_errcode();
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Bind a prepared query with arguments for executing
+ *
+ * @param string $sql
+ * @param array $params
+ * @return NULL
+ */
+ public function prepare_query($sql, $params)
+ {
+ // You can't bind query statements before execution with
+ // the firebird database
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create sql for batch insert
+ *
+ * @param string $table
+ * @param array $data
+ * @return array
+ */
+ public function insert_batch($table, $data=array())
+ {
+ // Each member of the data array needs to be an array
+ if ( ! is_array(current($data))) return NULL;
+
+ // Start the block of sql statements
+ $sql = "EXECUTE BLOCK AS BEGIN\n";
+
+ $table = $this->quote_table($table);
+ $fields = \array_keys(\current($data));
+
+ $insert_template = "INSERT INTO {$table} ("
+ . implode(',', $this->quote_ident($fields))
+ . ") VALUES (";
+
+ foreach($data as $item)
+ {
+ // Quote string values
+ $vals = array_map(array($this, 'quote'), $item);
+
+ // Add the values in the sql
+ $sql .= $insert_template . implode(', ', $vals) . ");\n";
+ }
+
+ // End the block of SQL statements
+ $sql .= "END";
+
+ // Return a null array value so the query is run as it is,
+ // not as a prepared statement, because a prepared statement
+ // doesn't work for this type of query in Firebird.
+ return array($sql, NULL);
+ }
+}
+// End of firebird_driver.php
diff --git a/docs/files/Query/Drivers/Firebird/Result.php.txt b/docs/files/Query/Drivers/Firebird/Result.php.txt
new file mode 100644
index 0000000..bf6e565
--- /dev/null
+++ b/docs/files/Query/Drivers/Firebird/Result.php.txt
@@ -0,0 +1,299 @@
+db = $db;
+ $this->statement = $link;
+ $this->setFetchMode(\PDO::FETCH_ASSOC);
+ $this->row = -1;
+ $this->result = array();
+
+ // Create the result array, so that we can get row counts
+ // Check the resource type, because prepared statements are "interbase query"
+ // but we only want "interbase result" types when attempting to fetch data
+ if (\is_resource($link) && \get_resource_type($link) === "interbase result")
+ {
+ while($row = \fbird_fetch_assoc($link, \IBASE_FETCH_BLOBS))
+ {
+ $this->result[] = $row;
+ }
+
+ // Free the result resource
+ \fbird_free_result($link);
+ }
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Invalidate method for data consistency
+ *
+ * @param mixed $column
+ * @param mixed $param
+ * @param int $type
+ * @param mixed $maxlen
+ * @param array $driverdata
+ * @return NULL
+ */
+ public function bindColumn($column, &$param, $type=NULL, $maxlen=NULL, $driverdata=NULL)
+ {
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Invalidate method for data consistency
+ *
+ * @param mixed $parameter
+ * @param mixed $variable
+ * @param int $data_type
+ * @param mixed $maxlen
+ * @param array $driverdata
+ * @return NULL
+ */
+ public function bindParam($parameter, &$variable, $data_type=NULL, $maxlen=NULL, $driverdata=NULL)
+ {
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Invalidate method for data consistency
+ *
+ * @param mixed $parameter
+ * @param mixed $variable
+ * @param int $data_type
+ * @return NULL
+ */
+ public function bindValue($parameter, $variable, $data_type=NULL)
+ {
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Run a prepared statement query
+ *
+ * @param array $args
+ * @return Firebird_Result
+ */
+ public function execute($args = NULL)
+ {
+ //Add the prepared statement as the first parameter
+ \array_unshift($args, $this->statement);
+
+ // Let php do all the hard stuff in converting
+ // the array of arguments into a list of arguments
+ // Then pass the resource to the constructor
+ $this->__construct(\call_user_func_array('fbird_execute', $args));
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Emulate PDO fetch public function
+ *
+ * @param int $fetch_style
+ * @param mixed $cursor_orientation
+ * @param mixed $cursor_offset
+ * @return mixed
+ */
+ public function fetch($fetch_style=\PDO::FETCH_ASSOC, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset=NULL)
+ {
+ // If there is no result, continue
+ if (empty($this->result))
+ {
+ return NULL;
+ }
+
+ // Keep track of the current row being fetched
+ ++$this->row;
+
+ // return NULL if the next row doesn't exist
+ if ( ! isset($this->result[$this->row]))
+ {
+ return NULL;
+ }
+
+ switch($fetch_style)
+ {
+ case \PDO::FETCH_OBJ:
+ $row = (object) $this->result[$this->row];
+ break;
+
+ case \PDO::FETCH_NUM:
+ $row = \array_values($this->result[$this->row]);
+ break;
+
+ default:
+ $row = $this->result[$this->row];
+ break;
+ }
+
+ return $row;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Emulate PDO fetchAll public function
+ *
+ * @param int $fetch_style
+ * @param mixed $statement
+ * @param mixed $ctor_args
+ * @return mixed
+ */
+ public function fetchAll($fetch_style=\PDO::FETCH_ASSOC, $statement=NULL, $ctor_args=NULL)
+ {
+ $all = array();
+
+ while($row = $this->fetch($fetch_style, $statement))
+ {
+ $all[] = $row;
+ }
+
+ $this->result = $all;
+
+ return $all;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Emulate PDOStatement::fetchColumn
+ *
+ * @param int $column_num
+ * @return mixed
+ */
+ public function fetchColumn($column_num=0)
+ {
+ $row = $this->fetch(\PDO::FETCH_NUM);
+ return $row[$column_num];
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Emulate PDOStatement::fetchObject, but only for the default use
+ *
+ * @param string $class_name
+ * @param array $ctor_args
+ * @return stdClass
+ */
+ public function fetchObject($class_name='stdClass', $ctor_args=array())
+ {
+ return $this->fetch(\PDO::FETCH_OBJ);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Return the number of rows affected by the previous query
+ *
+ * @return int
+ */
+ public function rowCount()
+ {
+ $rows = \fbird_affected_rows();
+
+ // Get the number of rows for the select query if you can
+ if ($rows === 0 && \is_resource($this->statement) && \get_resource_type($this->statement) === "interbase result")
+ {
+ // @codeCoverageIgnoreStart
+ $rows = \count($this->result);
+ }
+ // @codeCoverageIgnoreEnd
+
+ return $rows;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Method to emulate PDOStatement->errorCode
+ *
+ * @return string
+ */
+ public function errorCode()
+ {
+ return $this->db->errorCode();
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Method to emulate PDO->errorInfo / PDOStatement->errorInfo
+ *
+ * @return array
+ */
+ public function errorInfo()
+ {
+ return $this->db->errorInfo();
+ }
+}
+// End of firebird_result.php
diff --git a/docs/files/Query/Drivers/Firebird/SQL.php.txt b/docs/files/Query/Drivers/Firebird/SQL.php.txt
new file mode 100644
index 0000000..4969b77
--- /dev/null
+++ b/docs/files/Query/Drivers/Firebird/SQL.php.txt
@@ -0,0 +1,319 @@
+ 0)
+ {
+ $sql .= ' SKIP '. (int) $offset;
+ }
+
+ $sql = preg_replace("`SELECT`i", "SELECT {$sql}", $orig_sql);
+
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Get the query plan for the sql query
+ *
+ * @param string $sql
+ * @return string
+ */
+ public function explain($sql)
+ {
+ return $sql;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Random ordering keyword
+ *
+ * @return string
+ */
+ public function random()
+ {
+ return NULL;
+ }
+
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Returns sql to list other databases
+ *
+ * @return NULL
+ */
+ public function db_list()
+ {
+ return NULL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Returns sql to list tables
+ *
+ * @return string
+ */
+ public function table_list()
+ {
+ return <<
d2.RDB\$DEPENDED_ON_NAME
+ AND d1.RDB\$FIELD_NAME <> d2.RDB\$FIELD_NAME
+ AND rc.RDB\$RELATION_NAME = '{$table}' -- table name
+SQL;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Get the list of indexes for the current table
+ *
+ * @param string $table
+ * @return array
+ */
+ public function index_list($table)
+ {
+ return <<get_driver()->quote_table($name);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create an SQL backup file for the current database's structure
+ * @codeCoverageIgnore
+ * @param string $db_path
+ * @param string $new_file
+ * @return string
+ */
+ public function backup_structure()
+ {
+ list($db_path, $new_file) = func_get_args();
+ return ibase_backup($this->get_driver()->get_service(), $db_path, $new_file, \IBASE_BKP_METADATA_ONLY);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create an SQL backup file for the current database's data
+ *
+ * @codeCoverageIgnore
+ * @param array $exclude
+ * @param bool $system_tables
+ * @return string
+ */
+ public function backup_data($exclude=array(), $system_tables=FALSE)
+ {
+ // Determine which tables to use
+ $tables = $this->get_driver()->get_tables();
+ if($system_tables == TRUE)
+ {
+ $tables = array_merge($tables, $this->get_driver()->get_system_tables());
+ }
+
+ // Filter out the tables you don't want
+ if( ! empty($exclude))
+ {
+ $tables = array_diff($tables, $exclude);
+ }
+
+ $output_sql = '';
+
+ // Get the data for each object
+ foreach($tables as $t)
+ {
+ $sql = 'SELECT * FROM "'.trim($t).'"';
+ $res = $this->get_driver()->query($sql);
+ $obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
+
+ // Don't add to the file if the table is empty
+ if (count($obj_res) < 1) continue;
+
+ // Nab the column names by getting the keys of the first row
+ $columns = @array_keys($obj_res[0]);
+
+ $insert_rows = array();
+
+ // Create the insert statements
+ foreach($obj_res as $row)
+ {
+ $row = array_values($row);
+
+ // Quote values as needed by type
+ if(stripos($t, 'RDB$') === FALSE)
+ {
+ $row = array_map(array($this->get_driver(), 'quote'), $row);
+ $row = array_map('trim', $row);
+ }
+
+ $row_string = 'INSERT INTO "'.trim($t).'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');';
+
+ $row = NULL;
+
+ $insert_rows[] = $row_string;
+ }
+
+ $output_sql .= "\n\nSET TRANSACTION;\n".implode("\n", $insert_rows)."\nCOMMIT;";
+ }
+
+ return $output_sql;
+ }
+}
+// End of firebird_util.php
diff --git a/docs/files/Query/Drivers/Mysql/Driver.php.txt b/docs/files/Query/Drivers/Mysql/Driver.php.txt
new file mode 100644
index 0000000..88b1040
--- /dev/null
+++ b/docs/files/Query/Drivers/Mysql/Driver.php.txt
@@ -0,0 +1,56 @@
+ "SET NAMES UTF-8 COLLATE 'UTF-8'",
+ ));
+ }
+
+ if (strpos($dsn, 'mysql') === FALSE) $dsn = 'mysql:'.$dsn;
+
+ parent::__construct($dsn, $username, $password, $options);
+ }
+}
+//End of mysql_driver.php
diff --git a/docs/files/Query/Drivers/Mysql/SQL.php.txt b/docs/files/Query/Drivers/Mysql/SQL.php.txt
new file mode 100644
index 0000000..69a83f8
--- /dev/null
+++ b/docs/files/Query/Drivers/Mysql/SQL.php.txt
@@ -0,0 +1,234 @@
+get_driver()->get_dbs();
+
+ foreach($dbs as &$d)
+ {
+ // Skip built-in dbs
+ if ($d == 'mysql') continue;
+
+ // Get the list of tables
+ $tables = $this->get_driver()->driver_query("SHOW TABLES FROM `{$d}`", TRUE);
+
+ foreach($tables as $table)
+ {
+ $array = $this->get_driver()->driver_query("SHOW CREATE TABLE `{$d}`.`{$table}`", FALSE);
+ $row = current($array);
+
+ if ( ! isset($row['Create Table'])) continue;
+
+
+ $string[] = $row['Create Table'];
+ }
+ }
+
+ return implode("\n\n", $string);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create an SQL backup file for the current database's data
+ *
+ * @param array $exclude
+ * @return string
+ */
+ public function backup_data($exclude=array())
+ {
+ $tables = $this->get_driver()->get_tables();
+
+ // Filter out the tables you don't want
+ if( ! empty($exclude))
+ {
+ $tables = array_diff($tables, $exclude);
+ }
+
+ $output_sql = '';
+
+ // Select the rows from each Table
+ foreach($tables as $t)
+ {
+ $sql = "SELECT * FROM `{$t}`";
+ $res = $this->get_driver()->query($sql);
+ $rows = $res->fetchAll(\PDO::FETCH_ASSOC);
+
+ // Skip empty tables
+ if (count($rows) < 1) continue;
+
+ // Nab the column names by getting the keys of the first row
+ $columns = @array_keys($rows[0]);
+
+ $insert_rows = array();
+
+ // Create the insert statements
+ foreach($rows as $row)
+ {
+ $row = array_values($row);
+
+ // Workaround for Quercus
+ foreach($row as &$r)
+ {
+ $r = $this->get_driver()->quote($r);
+ }
+ $row = array_map('trim', $row);
+
+ $row_string = 'INSERT INTO `'.trim($t).'` (`'.implode('`,`', $columns).'`) VALUES ('.implode(',', $row).');';
+
+ $row = NULL;
+
+ $insert_rows[] = $row_string;
+ }
+
+ $output_sql .= "\n\n".implode("\n", $insert_rows)."\n";
+ }
+
+ return $output_sql;
+ }
+}
+// End of mysql_util.php
+
diff --git a/docs/files/Query/Drivers/Pdo_firebird/Driver.php.txt b/docs/files/Query/Drivers/Pdo_firebird/Driver.php.txt
new file mode 100644
index 0000000..0c34e8d
--- /dev/null
+++ b/docs/files/Query/Drivers/Pdo_firebird/Driver.php.txt
@@ -0,0 +1,90 @@
+quote_table($table);
+ $fields = \array_keys(\current($data));
+
+ $insert_template = "INSERT INTO {$table} ("
+ . implode(',', $this->quote_ident($fields))
+ . ") VALUES (";
+
+ foreach($data as $item)
+ {
+ // Quote string values
+ $vals = array_map(array($this, 'quote'), $item);
+
+ // Add the values in the sql
+ $sql .= $insert_template . implode(', ', $vals) . ");\n";
+ }
+
+ // End the block of SQL statements
+ $sql .= "END";
+
+ // Return a null array value so the query is run as it is,
+ // not as a prepared statement, because a prepared statement
+ // doesn't work for this type of query in Firebird.
+ return array($sql, NULL);
+ }
+}
+//End of firebird_driver.php
diff --git a/docs/files/Query/Drivers/Pdo_firebird/SQL.php.txt b/docs/files/Query/Drivers/Pdo_firebird/SQL.php.txt
new file mode 100644
index 0000000..4171e8e
--- /dev/null
+++ b/docs/files/Query/Drivers/Pdo_firebird/SQL.php.txt
@@ -0,0 +1,25 @@
+driver_query($sql);
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Retrieve foreign keys for the table
+ *
+ * @param string $table
+ * @return array
+ */
+ public function get_fks($table)
+ {
+ $value_map = array(
+ 'c' => 'CASCADE',
+ 'r' => 'RESTRICT',
+ );
+
+ $keys = parent::get_fks($table);
+
+ foreach($keys as &$key)
+ {
+ foreach(array('update', 'delete') AS $type)
+ {
+ if ( ! isset($value_map[$key[$type]])) continue;
+
+ $key[$type] = $value_map[$key[$type]];
+ }
+ }
+
+ return $keys;
+ }
+}
+//End of pgsql_driver.php
diff --git a/docs/files/Query/Drivers/Pgsql/SQL.php.txt b/docs/files/Query/Drivers/Pgsql/SQL.php.txt
new file mode 100644
index 0000000..59a01b4
--- /dev/null
+++ b/docs/files/Query/Drivers/Pgsql/SQL.php.txt
@@ -0,0 +1,304 @@
+get_driver()->get_tables();
+
+ // Filter out the tables you don't want
+ if( ! empty($exclude))
+ {
+ $tables = array_diff($tables, $exclude);
+ }
+
+ $output_sql = '';
+
+ // Get the data for each object
+ foreach($tables as $t)
+ {
+ $sql = 'SELECT * FROM "'.trim($t).'"';
+ $res = $this->get_driver()->query($sql);
+ $obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
+
+ // Don't add to the file if the table is empty
+ if (count($obj_res) < 1) continue;
+
+ $res = NULL;
+
+ // Nab the column names by getting the keys of the first row
+ $columns = @array_keys($obj_res[0]);
+
+ $insert_rows = array();
+
+ // Create the insert statements
+ foreach($obj_res as $row)
+ {
+ $row = array_values($row);
+
+ // Quote values as needed by type
+ $row = array_map(array($this->get_driver(), 'quote'), $row);
+ $row = array_map('trim', $row);
+
+
+ $row_string = 'INSERT INTO "'.trim($t).'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');';
+
+ $row = NULL;
+
+ $insert_rows[] = $row_string;
+ }
+
+ $obj_res = NULL;
+
+ $output_sql .= "\n\n".implode("\n", $insert_rows)."\n";
+ }
+
+ return $output_sql;
+ }
+}
+// End of pgsql_util.php
+
diff --git a/docs/files/Query/Drivers/Sqlite/Driver.php.txt b/docs/files/Query/Drivers/Sqlite/Driver.php.txt
new file mode 100644
index 0000000..bc6a3b6
--- /dev/null
+++ b/docs/files/Query/Drivers/Sqlite/Driver.php.txt
@@ -0,0 +1,143 @@
+sql->table_list();
+ $res = $this->query($sql);
+ return db_filter($res->fetchAll(\PDO::FETCH_ASSOC), 'name');
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Retrieve foreign keys for the table
+ *
+ * @param string $table
+ * @return array
+ */
+ public function get_fks($table)
+ {
+ $return_rows = array();
+
+ foreach(parent::get_fks($table) as $row)
+ {
+ $return_rows[] = array(
+ 'child_column' => $row['from'],
+ 'parent_table' => $row['table'],
+ 'parent_column' => $row['to'],
+ 'update' => $row['on_update'],
+ 'delete' => $row['on_delete']
+ );
+ }
+
+ return $return_rows;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create sql for batch insert
+ *
+ * @codeCoverageIgnore
+ * @param string $table
+ * @param array $data
+ * @return string
+ */
+ public function insert_batch($table, $data=array())
+ {
+ // If greater than version 3.7.11, supports the same syntax as
+ // MySQL and Postgres
+ if (version_compare($this->getAttribute(\PDO::ATTR_SERVER_VERSION), '3.7.11', '>='))
+ {
+ return parent::insert_batch($table, $data);
+ }
+
+ // --------------------------------------------------------------------------
+ // Otherwise, do a union query as an analogue to a 'proper' batch insert
+ // --------------------------------------------------------------------------
+
+ // Each member of the data array needs to be an array
+ if ( ! is_array(current($data))) return NULL;
+
+ // Start the block of sql statements
+ $table = $this->quote_table($table);
+ $sql = "INSERT INTO {$table} \n";
+
+ // Create a key-value mapping for each field
+ $first = array_shift($data);
+ $cols = array();
+ foreach($first as $colname => $datum)
+ {
+ $cols[] = $this->_quote($datum) . ' AS ' . $this->quote_ident($colname);
+ }
+ $sql .= "SELECT " . implode(', ', $cols) . "\n";
+
+ foreach($data as $union)
+ {
+ $vals = array_map(array($this, 'quote'), $union);
+ $sql .= "UNION SELECT " . implode(',', $vals) . "\n";
+ }
+
+ return array($sql, NULL);
+ }
+}
+//End of sqlite_driver.php
diff --git a/docs/files/Query/Drivers/Sqlite/SQL.php.txt b/docs/files/Query/Drivers/Sqlite/SQL.php.txt
new file mode 100644
index 0000000..29af6d9
--- /dev/null
+++ b/docs/files/Query/Drivers/Sqlite/SQL.php.txt
@@ -0,0 +1,206 @@
+get_driver()->query($sql);
+ $result = $res->fetchAll(\PDO::FETCH_ASSOC);
+
+ unset($res);
+
+ $output_sql = '';
+
+ // Get the data for each object
+ foreach($result as $r)
+ {
+ $sql = 'SELECT * FROM "'.$r['name'].'"';
+ $res = $this->get_driver()->query($sql);
+ $obj_res = $res->fetchAll(\PDO::FETCH_ASSOC);
+
+ unset($res);
+
+ // If the row is empty, continue;
+ if (empty($obj_res)) continue;
+
+ // Nab the column names by getting the keys of the first row
+ $columns = array_keys(current($obj_res));
+
+ $insert_rows = array();
+
+ // Create the insert statements
+ foreach($obj_res as $row)
+ {
+ $row = array_values($row);
+
+ // Quote values as needed by type
+ for($i=0, $icount=count($row); $i<$icount; $i++)
+ {
+ $row[$i] = (is_numeric($row[$i])) ? $row[$i] : $this->get_driver()->quote($row[$i]);
+ }
+
+ $row_string = 'INSERT INTO "'.$r['name'].'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');';
+
+ unset($row);
+
+ $insert_rows[] = $row_string;
+ }
+
+ unset($obj_res);
+
+ $output_sql .= "\n\n".implode("\n", $insert_rows);
+ }
+
+ return $output_sql;
+ }
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * Create an SQL backup file for the current database's structure
+ *
+ * @return string
+ */
+ public function backup_structure()
+ {
+ // Fairly easy for SQLite...just query the master table
+ $sql = 'SELECT "sql" FROM "sqlite_master"';
+ $res = $this->get_driver()->query($sql);
+ $result = $res->fetchAll(\PDO::FETCH_ASSOC);
+
+ $sql_array = array();
+
+ foreach($result as $r)
+ {
+ $sql_array[] = $r['sql'];
+ }
+
+ $sql_structure = implode(";\n", $sql_array) . ";";
+
+ return $sql_structure;
+ }
+}
+// End of sqlite_util.php
diff --git a/docs/files/Query/Query_Builder.php.txt b/docs/files/Query/Query_Builder.php.txt
index c80ceef..fcfbee3 100644
--- a/docs/files/Query/Query_Builder.php.txt
+++ b/docs/files/Query/Query_Builder.php.txt
@@ -14,7 +14,6 @@
// --------------------------------------------------------------------------
namespace Query;
-use Query\Driver\Driver_Interface;
// --------------------------------------------------------------------------
@@ -164,13 +163,13 @@ class Query_Builder extends Abstract_Query_Builder implements Query_Builder_Inte
/**
* Alias to driver util class
- * @var \Query\Driver\Util\Abstract_Util
+ * @var Abstract_Util
*/
public $util;
/**
* Alias to driver sql class
- * @var \Query\Driver\SQL\SQL_Interface
+ * @var SQL_Interface
*/
public $sql;
@@ -212,7 +211,7 @@ class Query_Builder extends Abstract_Query_Builder implements Query_Builder_Inte
/**
* Constructor
*
- * @param \Query\Driver\Driver_Interface $db
+ * @param Driver_Interface $db
* @param Query_Parser $parser
*/
public function __construct(Driver_Interface $db, Query_Parser $parser)
diff --git a/docs/files/Query/Query_Parser.php.txt b/docs/files/Query/Query_Parser.php.txt
index 1760136..675d517 100644
--- a/docs/files/Query/Query_Parser.php.txt
+++ b/docs/files/Query/Query_Parser.php.txt
@@ -26,7 +26,7 @@ class Query_Parser {
/**
* DB Driver
*
- * @var \Query\Driver\Driver_Interface
+ * @var Driver_Interface
*/
private $db;
@@ -58,7 +58,7 @@ class Query_Parser {
*
* @param Driver\Driver_Interface $db
*/
- public function __construct(Driver\Driver_Interface $db)
+ public function __construct(Driver_Interface $db)
{
$this->db = $db;
}
@@ -84,7 +84,7 @@ class Query_Parser {
// Go through the matches, and get the most relevant matches
$this->matches = array_map(array($this, 'filter_array'), $this->matches);
-
+
return $this->matches;
}
diff --git a/docs/files/Query/SQL_Interface.php.txt b/docs/files/Query/SQL_Interface.php.txt
new file mode 100644
index 0000000..a77f419
--- /dev/null
+++ b/docs/files/Query/SQL_Interface.php.txt
@@ -0,0 +1,141 @@
+
- Errors 0
+ Errors 0
- Markers 1
+ Markers 1
@@ -139,46 +139,45 @@
-
+
-
+
-
+
-
+
@@ -188,20 +187,77 @@
+
+
+
+
+
+
+
+
+
@@ -210,14 +266,7 @@
+
@@ -226,11 +275,16 @@
@@ -434,7 +488,7 @@
Documentation is powered by phpDocumentor and authored
- on June 4th, 2015 at 15:15.
+ on July 17th, 2015 at 15:56.
diff --git a/docs/files/autoload.php.txt b/docs/files/autoload.php.txt
index 0177b2b..9227b42 100644
--- a/docs/files/autoload.php.txt
+++ b/docs/files/autoload.php.txt
@@ -39,7 +39,7 @@ require(QBASE_PATH.'common.php');
// Load Query Classes
spl_autoload_register(function ($class)
{
- $class_segments = explode('\\', $class);
+ /*$class_segments = explode('\\', $class);
$driver_class = strtolower(array_pop($class_segments));
// Load DB Driver classes
@@ -49,15 +49,12 @@ spl_autoload_register(function ($class)
// Firebird is a special case, since it's not a PDO driver
// @codeCoverageIgnoreStart
- if (
- in_array($driver_class, \PDO::getAvailableDrivers())
- || function_exists('\\fbird_connect') && $driver_class === 'firebird'
- )
+ if (function_exists('\\fbird_connect') && $driver_class === 'firebird')
{
array_map('\\do_include', glob("{$driver_path}/*.php"));
}
// @codeCoverageIgnoreEnd
- }
+ }*/
// Load other classes
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
diff --git a/docs/files/common.php.html b/docs/files/common.php.html
index d630d02..80369d2 100644
--- a/docs/files/common.php.html
+++ b/docs/files/common.php.html
@@ -114,12 +114,12 @@
@@ -139,46 +139,45 @@
-
+
-
+
-
+
-
+
@@ -188,20 +187,77 @@
+
+
+
+
+
+
+
+
+
@@ -210,14 +266,7 @@
+
@@ -226,11 +275,16 @@
@@ -343,6 +397,14 @@ with array_map and glob
Tags
+
+ codeCoverageIgnore
+ |
+
+
+ |
+
+
subpackage
|
@@ -784,7 +846,7 @@ connection created.
Documentation is powered by phpDocumentor and authored
- on June 4th, 2015 at 15:15.
+ on July 17th, 2015 at 15:56.
diff --git a/docs/files/common.php.txt b/docs/files/common.php.txt
index c4e56d4..677a502 100644
--- a/docs/files/common.php.txt
+++ b/docs/files/common.php.txt
@@ -26,6 +26,7 @@ if ( ! function_exists('do_include'))
* Bulk directory loading workaround for use
* with array_map and glob
*
+ * @codeCoverageIgnore
* @param string $path
* @return void
*/
diff --git a/docs/graphs/class.html b/docs/graphs/class.html
index 60ca9c8..ca9cd51 100644
--- a/docs/graphs/class.html
+++ b/docs/graphs/class.html
@@ -91,12 +91,12 @@
@@ -156,7 +156,7 @@
Documentation is powered by phpDocumentor and authored
- on June 4th, 2015 at 15:15.
+ on July 17th, 2015 at 15:56.
diff --git a/docs/graphs/classes.svg b/docs/graphs/classes.svg
index c4d0e11..5530291 100644
--- a/docs/graphs/classes.svg
+++ b/docs/graphs/classes.svg
@@ -4,299 +4,360 @@
-