Update drivers with missing method

This commit is contained in:
Timothy Warren 2014-04-08 14:43:07 -04:00
parent d06a3eda0d
commit 85b804adaa
7 changed files with 145 additions and 30 deletions

View File

@ -54,6 +54,13 @@ class Firebird extends Abstract_Driver {
*/ */
protected $conn = NULL; protected $conn = NULL;
/**
* Reference to the service resource
*
* @var resource
*/
protected $service = NULL;
/** /**
* Open the link to the database * Open the link to the database
* *
@ -70,6 +77,7 @@ class Firebird extends Abstract_Driver {
: '\\fbird_connect'; : '\\fbird_connect';
$this->conn = $connect_function($dbpath, $user, $pass, 'utf-8', 0); $this->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 // Throw an exception to make this match other pdo classes
if ( ! \is_resource($this->conn)) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL); if ( ! \is_resource($this->conn)) throw new \PDOException(\fbird_errmsg(), \fbird_errcode(), NULL);
@ -90,6 +98,30 @@ class Firebird extends Abstract_Driver {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Cleanup some loose ends
* @codeCoverageIgnore
*/
public function __destruct()
{
fbird_service_detach($this->service);
fbird_close($this->conn);
}
// --------------------------------------------------------------------------
/**
* Return service handle
*
* @return resource
*/
public function get_service()
{
return $this->service;
}
// --------------------------------------------------------------------------
/** /**
* Empty a database table * Empty a database table
* *

View File

@ -254,8 +254,10 @@ class Firebird_Result extends \PDOStatement {
// Get the number of rows for the select query if you can // 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") if ($rows === 0 && \is_resource($this->statement) && \get_resource_type($this->statement) === "interbase result")
{ {
// @codeCoverageIgnoreStart
$rows = \count($this->result); $rows = \count($this->result);
} }
// @codeCoverageIgnoreEnd
return $rows; return $rows;
} }

View File

@ -297,6 +297,23 @@ SQL;
AND d1.RDB\$DEPENDED_ON_NAME <> d2.RDB\$DEPENDED_ON_NAME AND d1.RDB\$DEPENDED_ON_NAME <> d2.RDB\$DEPENDED_ON_NAME
AND d1.RDB\$FIELD_NAME <> d2.RDB\$FIELD_NAME AND d1.RDB\$FIELD_NAME <> d2.RDB\$FIELD_NAME
AND rc.RDB\$RELATION_NAME = '{$table}' -- table 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 <<<SQL
SELECT "RDB\$INDEX_NAME", "RDB\$UNIQUE_FLAG", "RDB\$FOREIGN_KEY"
FROM "RDB\$INDICES"
WHERE "RDB\$RELATION_NAME"='{$table}'
SQL; SQL;
} }
} }

View File

@ -87,12 +87,14 @@ class Firebird_Util extends Abstract_Util {
/** /**
* Create an SQL backup file for the current database's structure * Create an SQL backup file for the current database's structure
* @codeCoverageIgnore * @codeCoverageIgnore
* @param string $db_path
* @param string $new_file
* @return string * @return string
*/ */
public function backup_structure() public function backup_structure()
{ {
// TODO Implement Backup structure function list($db_path, $new_file) = func_get_args();
return ''; return ibase_backup($this->get_service(), $db_path, $new_file, IBASE_BKP_METADATA_ONLY);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -209,5 +209,18 @@ class MySQL_SQL extends Abstract_SQL {
WHERE `REFERENCED_TABLE_NAME` = '{$table}'; WHERE `REFERENCED_TABLE_NAME` = '{$table}';
SQL; SQL;
} }
// --------------------------------------------------------------------------
/**
* Get the list of indexes for the current table
*
* @param string $table
* @return array
*/
public function index_list($table)
{
return "SHOW INDEX IN {$table}";
}
} }
//End of mysql_sql.php //End of mysql_sql.php

View File

@ -232,32 +232,68 @@ SQL;
public function fk_list($table) public function fk_list($table)
{ {
return <<<SQL return <<<SQL
SELECT SELECT
"att2"."attname" AS "child_column", "att2"."attname" AS "child_column",
"cl"."relname" AS "parent_table", "cl"."relname" AS "parent_table",
"att"."attname" AS "parent_column" "att"."attname" AS "parent_column"
FROM FROM
(SELECT (SELECT
unnest(con1.conkey) AS "parent", unnest(con1.conkey) AS "parent",
unnest(con1.confkey) AS "child", unnest(con1.confkey) AS "child",
"con1"."confrelid", "con1"."confrelid",
"con1"."conrelid" "con1"."conrelid"
FROM "pg_class" "cl" FROM "pg_class" "cl"
JOIN "pg_namespace" "ns" ON "cl"."relnamespace" = "ns"."oid" JOIN "pg_namespace" "ns" ON "cl"."relnamespace" = "ns"."oid"
JOIN "pg_constraint" "con1" ON "con1"."conrelid" = "cl"."oid" JOIN "pg_constraint" "con1" ON "con1"."conrelid" = "cl"."oid"
WHERE "cl"."relname" = 'child_table' WHERE "cl"."relname" = 'child_table'
AND "ns"."nspname" = 'child_schema' AND "ns"."nspname" = 'child_schema'
AND "con1"."contype" = 'f' AND "con1"."contype" = 'f'
) )
"con" "con"
JOIN "pg_attribute" "att" ON JOIN "pg_attribute" "att" ON
"att"."attrelid" = "con"."confrelid" "att"."attrelid" = "con"."confrelid"
AND "att"."attnum" = "con"."child" AND "att"."attnum" = "con"."child"
JOIN "pg_class" "cl" ON JOIN "pg_class" "cl" ON
"cl"."oid" = "con"."confrelid" "cl"."oid" = "con"."confrelid"
JOIN "pg_attribute" "att2" ON JOIN "pg_attribute" "att2" ON
"att2"."attrelid" = "con"."conrelid" "att2"."attrelid" = "con"."conrelid"
AND "att2"."attnum" = "con"."parent" AND "att2"."attnum" = "con"."parent"
SQL;
}
// --------------------------------------------------------------------------
/**
* Get the list of indexes for the current table
*
* @param string $table
* @return array
*/
public function index_list($table)
{
return <<<SQL
SELECT
t.relname AS table_name,
i.relname AS index_name,
array_to_string(array_agg(a.attname), ', ') AS column_names
FROM
pg_class t,
pg_class i,
pg_index ix,
pg_attribute a
WHERE
t.oid = ix.indrelid
AND i.oid = ix.indexrelid
AND a.attrelid = t.oid
AND a.attnum = ANY(ix.indkey)
AND t.relkind = 'r'
AND t.relname = '{$table}'
GROUP BY
t.relname,
i.relname
ORDER BY
t.relname,
i.relname;
SQL; SQL;
} }
} }

View File

@ -55,7 +55,7 @@ class SQLite_SQL extends Abstract_SQL {
*/ */
public function db_list() public function db_list()
{ {
return NULL; return 'PRAGMA database_list';
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -185,7 +185,20 @@ SQL;
*/ */
public function fk_list($table) public function fk_list($table)
{ {
return NULL; return 'PRAGMA foreign_key_list("' . $table . '")';
}
// --------------------------------------------------------------------------
/**
* Get the list of indexes for the current table
*
* @param string $table
* @return array
*/
public function index_list($table)
{
return 'PRAGMA index_list("' . $table . '")';
} }
} }