diff --git a/src/common/db_pdo.php b/src/common/db_pdo.php index bf2c8b6..100c505 100644 --- a/src/common/db_pdo.php +++ b/src/common/db_pdo.php @@ -61,6 +61,11 @@ abstract class DB_PDO extends PDO { // Bind the parameters foreach($data as $k => $value) { + if(is_numeric($k)) + { + $k++; + } + $res = $query->bindValue($k, $value); if( ! $res) @@ -83,7 +88,7 @@ abstract class DB_PDO extends PDO { */ public function prepare_execute($sql, $params) { - $this->prepare_query($sql, $params); + $this->statement =& $this->prepare_query($sql, $params); $this->statement->execute(); return $this->statement; @@ -126,6 +131,20 @@ abstract class DB_PDO extends PDO { // 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]}
"; + } // ------------------------------------------------------------------------- diff --git a/src/databases/sqlite.php b/src/databases/sqlite.php index 2b56ed0..49cb114 100644 --- a/src/databases/sqlite.php +++ b/src/databases/sqlite.php @@ -26,10 +26,10 @@ class SQLite extends DB_PDO { * * @param string $dsn */ - public function __construct($dsn) + public function __construct($dsn, $user=NULL, $pass=NULL) { // DSN is simply `sqlite:/path/to/db` - parent::__construct("sqlite:{$dsn}"); + parent::__construct("sqlite:{$dsn}", $user, $pass); $class = __CLASS__."_manip"; $this->manip = new $class; diff --git a/src/databases/sqlite_manip.php b/src/databases/sqlite_manip.php index 8048c9c..b3cedd3 100644 --- a/src/databases/sqlite_manip.php +++ b/src/databases/sqlite_manip.php @@ -68,7 +68,7 @@ class SQLite_manip extends db_manip { // Generate the sql for the creation of the table $sql = "CREATE TABLE \"{$name}\" ("; - $sql .= implode(",", $columns); + $sql .= implode(", ", $columns); $sql .= ")"; return $sql; diff --git a/tests/databases/sqlite.php b/tests/databases/sqlite.php index f4c5a53..4c417d6 100644 --- a/tests/databases/sqlite.php +++ b/tests/databases/sqlite.php @@ -53,14 +53,47 @@ class SQLiteTest extends UnitTestCase { function TestCreateTable() { //Attempt to create the table - $sql = $this->db->manip->create_table('create_test', array('id' => 'INTEGER'), array('id' => 'PRIMARY KEY')); + $sql = $this->db->manip->create_table('create_test', + array( + 'id' => 'INTEGER', + 'key' => 'TEXT', + 'val' => 'TEXT', + ), + array( + 'id' => 'PRIMARY KEY' + ) + ); $this->db->query($sql); //Check $dbs = $this->db->get_tables(); - $this->assertEqual($dbs['create_test'], 'CREATE TABLE "create_test" (id INTEGER PRIMARY KEY)'); + $this->assertEqual($dbs['create_test'], 'CREATE TABLE "create_test" (id INTEGER PRIMARY KEY, key TEXT , val TEXT )'); } + + function TestPreparedStatements() + { + $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); + + $statement->execute(); + } + + function TestPrepareExecute() + { + $sql = <<db->prepare_execute($sql, array( + 2, "works", 'also?' + )); + + } + function TestDeleteTable() { //Make sure the table exists to delete @@ -75,4 +108,5 @@ class SQLiteTest extends UnitTestCase { $dbs = $this->db->get_tables(); $this->assertTrue(empty($dbs['create_test'])); } + } \ No newline at end of file diff --git a/tests/test_dbs/FB_TEST_DB.FDB b/tests/test_dbs/FB_TEST_DB.FDB index 8687efd..111bfce 100755 Binary files a/tests/test_dbs/FB_TEST_DB.FDB and b/tests/test_dbs/FB_TEST_DB.FDB differ diff --git a/tests/test_dbs/test_sqlite.db b/tests/test_dbs/test_sqlite.db index 1b2cd50..199ca05 100755 Binary files a/tests/test_dbs/test_sqlite.db and b/tests/test_dbs/test_sqlite.db differ