From f10f3f13f48dcf236d499e5df693e10bfc24f29b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 28 Feb 2012 14:58:52 -0500 Subject: [PATCH] Removed source folder --- src/LICENSE => LICENSE | 0 common/db_pdo.php | 217 ++++++++++++++++++ {src/common => common}/settings.php | 0 {src/databases => databases}/firebird.php | 0 .../firebird_manip.php | 0 {src/databases => databases}/mysql.php | 0 {src/databases => databases}/mysql_manip.php | 0 {src/databases => databases}/odbc.php | 0 {src/databases => databases}/odbc_manip.php | 0 {src/databases => databases}/pgsql.php | 0 {src/databases => databases}/pgsql_manip.php | 0 {src/databases => databases}/sqlite.php | 0 {src/databases => databases}/sqlite_manip.php | 0 {src/images => images}/firebird-logo-32.png | Bin {src/images => images}/mysql-logo-32.png | Bin {src/images => images}/postgresql-logo-32.png | Bin {src/images => images}/sqlite-logo-32.png | Bin src/index.php => index.php | 0 tests/index.php | 4 +- tests/test_dbs/test_sqlite.db | Bin 4096 -> 4096 bytes {src/windows => windows}/add_db.php | 0 {src/windows => windows}/main.php | 0 .../widgets/connection_sidebar.php | 0 {src/windows => windows}/widgets/datagrid.php | 0 .../widgets/db_info_widget.php | 0 25 files changed, 219 insertions(+), 2 deletions(-) rename src/LICENSE => LICENSE (100%) create mode 100644 common/db_pdo.php rename {src/common => common}/settings.php (100%) rename {src/databases => databases}/firebird.php (100%) rename {src/databases => databases}/firebird_manip.php (100%) rename {src/databases => databases}/mysql.php (100%) rename {src/databases => databases}/mysql_manip.php (100%) rename {src/databases => databases}/odbc.php (100%) rename {src/databases => databases}/odbc_manip.php (100%) rename {src/databases => databases}/pgsql.php (100%) rename {src/databases => databases}/pgsql_manip.php (100%) rename {src/databases => databases}/sqlite.php (100%) rename {src/databases => databases}/sqlite_manip.php (100%) rename {src/images => images}/firebird-logo-32.png (100%) rename {src/images => images}/mysql-logo-32.png (100%) rename {src/images => images}/postgresql-logo-32.png (100%) rename {src/images => images}/sqlite-logo-32.png (100%) rename src/index.php => index.php (100%) rename {src/windows => windows}/add_db.php (100%) rename {src/windows => windows}/main.php (100%) rename {src/windows => windows}/widgets/connection_sidebar.php (100%) rename {src/windows => windows}/widgets/datagrid.php (100%) rename {src/windows => windows}/widgets/db_info_widget.php (100%) diff --git a/src/LICENSE b/LICENSE similarity index 100% rename from src/LICENSE rename to LICENSE diff --git a/common/db_pdo.php b/common/db_pdo.php new file mode 100644 index 0000000..ea6c102 --- /dev/null +++ b/common/db_pdo.php @@ -0,0 +1,217 @@ +prepare($sql); + + if( ! (is_object($query) || is_resource($query))) + { + $this->get_last_error(); + return FALSE; + } + + // Set the statement in the class variable for easy later access + $this->statement =& $query; + + + if( ! (is_array($data) || is_object($data))) + { + trigger_error("Invalid data argument"); + return FALSE; + } + + // Bind the parameters + foreach($data as $k => $value) + { + if(is_numeric($k)) + { + $k++; + } + + $res = $query->bindValue($k, $value); + + if( ! $res) + { + trigger_error("Parameter not successfully bound"); + return FALSE; + } + } + + return $query; + + } + + // ------------------------------------------------------------------------- + + /** + * 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; + } + + // ------------------------------------------------------------------------- + + /** + * Retreives the data from a select query + * + * @param PDOStatement $statement + * @return array + */ + public function get_query_data($statement) + { + $this->statement = $statement; + + // Execute the query + $this->statement->execute(); + + // Return the data array fetched + return $this->statement->fetchAll(PDO::FETCH_ASSOC); + } + + // ------------------------------------------------------------------------- + + /** + * Returns number of rows affected by an INSERT, UPDATE, DELETE type query + * + * @param PDOStatement $statement + * @return int + */ + public function affected_rows($statement) + { + $this->statement = $statement; + + // Execute the query + $this->statement->execute(); + + // Return number of rows affected + return $this->statement->rowCount; + } + + // -------------------------------------------------------------------------- + + /** + * Return the last error for the current database connection + * + * @return string + */ + public function get_last_error() + { + $info = $this->errorInfo(); + + echo "Error:
{$info[0]}:{$info[1]}\n{$info[2]}
"; + } + + // ------------------------------------------------------------------------- + + /** + * Abstract public functions to override in child classes + */ + + /** + * Return list of tables for the current database + * + * @return array + */ + abstract public function get_tables(); + + /** + * Empty the passed table + * + * @param string $table + * + * @return void + */ + abstract public function truncate($table); + + /** + * Return the number of rows for the last SELECT query + * + * @return int + */ + abstract public function num_rows(); + + /** + * Retreives an array of non-user-created tables for + * the connection/database + * + * @return array + */ + abstract public function get_system_tables(); + +} + +// ------------------------------------------------------------------------- + +/** + * Abstract parent for database manipulation subclasses + */ +abstract class db_manip { + + /** + * Get database-specific sql to create a new table + * + * @param string $name + * @param array $columns + * @param array $constraints + * @param array $indexes + * + * @return string + */ + abstract public function create_table($name, $columns, $constraints=array(), $indexes=array()); + + /** + * Get database-specific sql to drop a table + * + * @param string $name + * + * @return string + */ + abstract public function delete_table($name); +} +// End of db_pdo.php \ No newline at end of file diff --git a/src/common/settings.php b/common/settings.php similarity index 100% rename from src/common/settings.php rename to common/settings.php diff --git a/src/databases/firebird.php b/databases/firebird.php similarity index 100% rename from src/databases/firebird.php rename to databases/firebird.php diff --git a/src/databases/firebird_manip.php b/databases/firebird_manip.php similarity index 100% rename from src/databases/firebird_manip.php rename to databases/firebird_manip.php diff --git a/src/databases/mysql.php b/databases/mysql.php similarity index 100% rename from src/databases/mysql.php rename to databases/mysql.php diff --git a/src/databases/mysql_manip.php b/databases/mysql_manip.php similarity index 100% rename from src/databases/mysql_manip.php rename to databases/mysql_manip.php diff --git a/src/databases/odbc.php b/databases/odbc.php similarity index 100% rename from src/databases/odbc.php rename to databases/odbc.php diff --git a/src/databases/odbc_manip.php b/databases/odbc_manip.php similarity index 100% rename from src/databases/odbc_manip.php rename to databases/odbc_manip.php diff --git a/src/databases/pgsql.php b/databases/pgsql.php similarity index 100% rename from src/databases/pgsql.php rename to databases/pgsql.php diff --git a/src/databases/pgsql_manip.php b/databases/pgsql_manip.php similarity index 100% rename from src/databases/pgsql_manip.php rename to databases/pgsql_manip.php diff --git a/src/databases/sqlite.php b/databases/sqlite.php similarity index 100% rename from src/databases/sqlite.php rename to databases/sqlite.php diff --git a/src/databases/sqlite_manip.php b/databases/sqlite_manip.php similarity index 100% rename from src/databases/sqlite_manip.php rename to databases/sqlite_manip.php diff --git a/src/images/firebird-logo-32.png b/images/firebird-logo-32.png similarity index 100% rename from src/images/firebird-logo-32.png rename to images/firebird-logo-32.png diff --git a/src/images/mysql-logo-32.png b/images/mysql-logo-32.png similarity index 100% rename from src/images/mysql-logo-32.png rename to images/mysql-logo-32.png diff --git a/src/images/postgresql-logo-32.png b/images/postgresql-logo-32.png similarity index 100% rename from src/images/postgresql-logo-32.png rename to images/postgresql-logo-32.png diff --git a/src/images/sqlite-logo-32.png b/images/sqlite-logo-32.png similarity index 100% rename from src/images/sqlite-logo-32.png rename to images/sqlite-logo-32.png diff --git a/src/index.php b/index.php similarity index 100% rename from src/index.php rename to index.php diff --git a/tests/index.php b/tests/index.php index 8584e85..fbb70a6 100644 --- a/tests/index.php +++ b/tests/index.php @@ -31,11 +31,11 @@ function do_include($path) // Include core tests require_once("core.php"); -require_once("../src/common/db_pdo.php"); +require_once("../common/db_pdo.php"); // Include db tests // Load db classes based on capability -$src_path = "../src/databases/"; +$src_path = "../databases/"; $test_path = "./databases/"; foreach(pdo_drivers() as $d) diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index 199ca0582c203573e83b8ff758a0e5250fb27f78..af74dbce18c6e150dd73e6cbb4c782953927d824 100755 GIT binary patch delta 53 zcmZorXi%6SE%=gwfq?~xnSq!Ih#ybXF=lP^5ylYov}s zc506rT&bJp}WMPmNPs-0vPc15TFUl`21^_6wK(GJ+ diff --git a/src/windows/add_db.php b/windows/add_db.php similarity index 100% rename from src/windows/add_db.php rename to windows/add_db.php diff --git a/src/windows/main.php b/windows/main.php similarity index 100% rename from src/windows/main.php rename to windows/main.php diff --git a/src/windows/widgets/connection_sidebar.php b/windows/widgets/connection_sidebar.php similarity index 100% rename from src/windows/widgets/connection_sidebar.php rename to windows/widgets/connection_sidebar.php diff --git a/src/windows/widgets/datagrid.php b/windows/widgets/datagrid.php similarity index 100% rename from src/windows/widgets/datagrid.php rename to windows/widgets/datagrid.php diff --git a/src/windows/widgets/db_info_widget.php b/windows/widgets/db_info_widget.php similarity index 100% rename from src/windows/widgets/db_info_widget.php rename to windows/widgets/db_info_widget.php