Rearrange Firebird driver
This commit is contained in:
parent
bdd78328a8
commit
5b39bdc179
@ -134,9 +134,6 @@ abstract class DB_PDO extends PDO {
|
||||
$this->statement = $statement;
|
||||
}
|
||||
|
||||
// Execute the query
|
||||
//$this->statement->execute();
|
||||
|
||||
// Return number of rows affected
|
||||
return $this->statement->rowCount();
|
||||
}
|
||||
@ -210,24 +207,24 @@ abstract class DB_PDO extends PDO {
|
||||
* Method to simplify retreiving db results for meta-data queries
|
||||
*
|
||||
* @param string $sql
|
||||
* @param string $filtered_index
|
||||
* @param bool $filtered_index
|
||||
* @return mixed
|
||||
*/
|
||||
protected function driver_query($sql, $filtered_index="")
|
||||
protected function driver_query($sql, $filtered_index=TRUE)
|
||||
{
|
||||
$res = $this->query($sql);
|
||||
$all = $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ( ! empty($filtered_index))
|
||||
if ($sql === FALSE)
|
||||
{
|
||||
return db_filter($all, $filtered_index);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $all;
|
||||
$res = $this->query($sql);
|
||||
|
||||
$flag = ($filtered_index) ? PDO::FETCH_NUM : PDO::FETCH_ASSOC;
|
||||
$all = $res->fetchAll($flag);
|
||||
|
||||
return ($filtered_index) ? db_filter($all, 0) : $all;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ! Abstract public functions to override in child classes
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -235,49 +232,100 @@ abstract class DB_PDO extends PDO {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_tables();
|
||||
public function get_tables()
|
||||
{
|
||||
return $this->driver_query($this->sql->table_list());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of dbs for the current connection, if possible
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_dbs();
|
||||
public function get_dbs()
|
||||
{
|
||||
return $this->driver_query($this->sql->db_list());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of views for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_views();
|
||||
public function get_views()
|
||||
{
|
||||
return $this->driver_query($this->sql->view_list());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of sequences for the current database, if they exist
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_sequences();
|
||||
public function get_sequences()
|
||||
{
|
||||
return $this->driver_query($this->sql->sequence_list());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of function for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_functions();
|
||||
public function get_functions()
|
||||
{
|
||||
return $this->driver_query($this->sql->function_list(), FALSE);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of stored procedures for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_procedures();
|
||||
public function get_procedures()
|
||||
{
|
||||
return $this->driver_query($this->sql->procedure_list(), FALSE);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of triggers for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_triggers();
|
||||
public function get_triggers()
|
||||
{
|
||||
return $this->driver_query($this->sql->trigger_list(), FALSE);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Retreives an array of non-user-created tables for
|
||||
* the connection/database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_system_tables()
|
||||
{
|
||||
return $this->driver_query($this->sql->system_table_list());
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ! Abstract public functions to override in child classes
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Empty the passed table
|
||||
@ -295,14 +343,6 @@ abstract class DB_PDO extends PDO {
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Connect to a different database
|
||||
*
|
||||
|
@ -60,6 +60,7 @@ abstract class DB_SQL {
|
||||
/**
|
||||
* Return an SQL file with the database table structure
|
||||
*
|
||||
* @abstract
|
||||
* @return string
|
||||
*/
|
||||
abstract public function backup_structure();
|
||||
@ -67,6 +68,7 @@ abstract class DB_SQL {
|
||||
/**
|
||||
* Return an SQL file with the database data as insert statements
|
||||
*
|
||||
* @abstract
|
||||
* @return string
|
||||
*/
|
||||
abstract public function backup_data();
|
||||
|
@ -128,166 +128,6 @@ class firebird extends DB_PDO {
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List tables for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_tables()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
|
||||
WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
|
||||
AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
|
||||
AND "RDB\$VIEW_BLR" IS NOT NULL
|
||||
ORDER BY "RDB\$RELATION_NAME" ASC
|
||||
SQL;
|
||||
|
||||
$this->statement = $this->query($sql);
|
||||
|
||||
$tables = array();
|
||||
|
||||
while($row = $this->statement->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
$tables[] = $row['RDB$RELATION_NAME'];
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get list of views for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_views()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT "RDB\$RELATION_NAME"
|
||||
FROM "RDB\$RELATIONS"
|
||||
WHERE "RDB\$VIEW_BLR" IS NOT NULL
|
||||
AND ("RDB\$SYSTEM_FLAG" IS NULL OR "RDB\$SYSTEM_FLAG" = 0)
|
||||
SQL;
|
||||
$res = $this->query($sql);
|
||||
|
||||
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'RDB$RELATION_NAME');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get list of sequences for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sequences()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT "RDB\$GENERATOR_NAME"
|
||||
FROM "RDB\$GENERATORS"
|
||||
WHERE "RDB\$SYSTEM_FLAG" = 0
|
||||
SQL;
|
||||
$res = $this->query($sql);
|
||||
|
||||
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'RDB$GENERATOR_NAME');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of custom functions for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_functions()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT * FROM "RDB\$TRIGGERS"
|
||||
WHERE "RDB\$SYSTEM_FLAG" = 0
|
||||
SQL;
|
||||
$res = $this->query($sql);
|
||||
|
||||
return $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Retrun list of stored procedures for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_procedures()
|
||||
{
|
||||
$sql = 'SELECT * FROM "RDB$PROCEDURES"';
|
||||
|
||||
$res = $this->query($sql);
|
||||
|
||||
return $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return list of triggers for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_triggers()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT * FROM "RDB\$FUNCTIONS"
|
||||
WHERE "RDB\$SYSTEM_FLAG" = 0
|
||||
SQL;
|
||||
$res = $this->query($sql);
|
||||
|
||||
return $res->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Not applicable to firebird
|
||||
*
|
||||
* @return FALSE
|
||||
*/
|
||||
public function get_dbs()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List system tables for the current database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_system_tables()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
|
||||
WHERE "RDB\$RELATION_NAME" LIKE 'RDB$%'
|
||||
OR "RDB\$RELATION_NAME" LIKE 'MON$%';
|
||||
SQL;
|
||||
|
||||
$this->statement = $this->query($sql);
|
||||
|
||||
$tables = array();
|
||||
|
||||
while($row = $this->statement->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
$tables[] = $row['RDB$RELATION_NAME'];
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the number of rows returned for a SELECT query
|
||||
*
|
||||
|
@ -209,5 +209,126 @@ class Firebird_SQL extends DB_SQL {
|
||||
|
||||
return $output_sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns sql to list other databases
|
||||
*
|
||||
* @return FALSE
|
||||
*/
|
||||
public function db_list()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns sql to list tables
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function table_list()
|
||||
{
|
||||
return <<<SQL
|
||||
SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
|
||||
WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
|
||||
AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
|
||||
AND "RDB\$VIEW_BLR" IS NOT NULL
|
||||
ORDER BY "RDB\$RELATION_NAME" ASC
|
||||
SQL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns sql to list system tables
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function system_table_list()
|
||||
{
|
||||
return <<<SQL
|
||||
SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
|
||||
WHERE "RDB\$RELATION_NAME" LIKE 'RDB$%'
|
||||
OR "RDB\$RELATION_NAME" LIKE 'MON$%';
|
||||
SQL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns sql to list views
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function view_list()
|
||||
{
|
||||
return <<<SQL
|
||||
SELECT "RDB\$RELATION_NAME"
|
||||
FROM "RDB\$RELATIONS"
|
||||
WHERE "RDB\$VIEW_BLR" IS NOT NULL
|
||||
AND ("RDB\$SYSTEM_FLAG" IS NULL OR "RDB\$SYSTEM_FLAG" = 0)
|
||||
SQL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns sql to list triggers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function trigger_list()
|
||||
{
|
||||
return <<<SQL
|
||||
SELECT * FROM "RDB\$FUNCTIONS"
|
||||
WHERE "RDB\$SYSTEM_FLAG" = 0
|
||||
SQL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return sql to list functions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function function_list()
|
||||
{
|
||||
return <<<SQL
|
||||
SELECT * FROM "RDB\$FUNCTIONS"
|
||||
WHERE "RDB\$SYSTEM_FLAG" = 0
|
||||
SQL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return sql to list stored procedures
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function procedure_list()
|
||||
{
|
||||
return 'SELECT * FROM "RDB$PROCEDURES"';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return sql to list sequences
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sequence_list()
|
||||
{
|
||||
return <<<SQL
|
||||
SELECT "RDB\$GENERATOR_NAME"
|
||||
FROM "RDB\$GENERATORS"
|
||||
WHERE "RDB\$SYSTEM_FLAG" = 0
|
||||
SQL;
|
||||
}
|
||||
}
|
||||
//End of firebird_sql.php
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user