Created abstract base database manip class

This commit is contained in:
Timothy Warren 2012-02-07 15:53:46 -05:00
parent 4182776c21
commit 377c319bd2
7 changed files with 51 additions and 23 deletions

View File

@ -24,6 +24,9 @@ abstract class DB_PDO extends PDO {
function __construct($dsn, $username=NULL, $password=NULL, $driver_options=array()) function __construct($dsn, $username=NULL, $password=NULL, $driver_options=array())
{ {
parent::__construct($dsn, $username, $password, $driver_options); parent::__construct($dsn, $username, $password, $driver_options);
$class = __CLASS__.'_manip';
$this->manip = new $class;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@ -135,4 +138,24 @@ abstract class DB_PDO extends PDO {
*/ */
abstract function num_rows(); abstract function num_rows();
} }
// -------------------------------------------------------------------------
/**
* 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 function create_table($name, $columns, $constraints, $indexes);
}
// End of db_pdo.php // End of db_pdo.php

View File

@ -156,7 +156,21 @@ class firebird {
*/ */
function num_rows() function num_rows()
{ {
// TODO: Implement $count = 0;
if(isset($this->statement))
{
while($row = $this->fetch())
{
$count++;
}
}
else
{
return FALSE;
}
return $count;
} }
} }
// End of firebird.php // End of firebird.php

View File

@ -17,12 +17,7 @@
* *
* PDO-firebird isn't stable, so this is a wrapper of the ibase_ functions. * PDO-firebird isn't stable, so this is a wrapper of the ibase_ functions.
*/ */
class firebird_manip extends firebird { class firebird_manip extends db_manip{
function __construct($db, $user="sysdba", $pass="masterkey")
{
parent::__construct($db, $user, $pass);
}
function create_table($name, $fields, $constraints=array()) function create_table($name, $fields, $constraints=array())
{ {

View File

@ -15,11 +15,11 @@
/** /**
* MySQL Database manipulation class * MySQL Database manipulation class
*/ */
class MySQL_manip extends MySQL { class MySQL_manip extends db_manip{
function __construct($dsn, $user=null, $pass=null, $opt=array()) function create_table($name, $columns, $constraints, $indexes)
{ {
parent::__construct($dsn, $user, $pass, $opt); //TODO: implement
} }
} }
//End of mysqlL_manip.php //End of mysql_manip.php

View File

@ -17,11 +17,12 @@
* *
* @extends ODBC * @extends ODBC
*/ */
class ODBC_manip extends ODBC { class ODBC_manip extends db_manip {
function __construct($dsn, $username=null, $password=null, $options=array()) function create_table()
{ {
parent::__construct("odbc:$dsn", $username, $password, $options); //ODBC can't know how to create a table
return FALSE;
} }
} }
// End of odbc_manip.php // End of odbc_manip.php

View File

@ -17,11 +17,11 @@
* *
* @extends PgSQL * @extends PgSQL
*/ */
class pgSQL_manip extends pgSQL { class pgSQL_manip extends db_manip {
function __construct($dsn, $username=null, $password=null, $options=array()) function create_table($name, $columns, $constraints, $indexes)
{ {
parent::__construct($dsn, $username, $password, $options); //TODO: implement
} }
} }

View File

@ -15,12 +15,7 @@
/** /**
* SQLite Database manipulation class * SQLite Database manipulation class
*/ */
class SQLite_manip extends SQLite { class SQLite_manip extends db_manip {
function __construct($dsn)
{
parent::__construct($dsn);
}
/** /**
* Convenience function to create a new table * Convenience function to create a new table