DB class updates, changed some SQL statements to heredoc form.

This commit is contained in:
Timothy Warren 2012-02-13 13:10:48 -05:00
parent 3d8382149e
commit 13ff38acb4
3 changed files with 61 additions and 8 deletions

View File

@ -7,6 +7,7 @@ Follow the CodeIgniter [Style Guide](https://github.com/timw4mail/CodeIgniter/bl
* Do not use `global`, `eval`
* Do not use the error suppressor `@`
* Add a docblock to every method
* Use [heredoc](http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) string syntax for SQL statements to minimize PHP escape characters
## PHP-Gtk Resources
* [Reference](http://gtk.php.net/manual/en/reference.php)

View File

@ -54,7 +54,11 @@ class pgSQL extends DB_PDO {
*/
function get_dbs()
{
$sql = "SELECT datname FROM pg_database WHERE datname NOT IN ('template0','template1') ORDER BY 1";
$sql = <<< SQL
SELECT "datname" FROM "pg_database"
WHERE "datname" NOT IN ('template0','template1')
ORDER BY 1
SQL;
$res = $this->query($sql);
$dbs = $res->fetchAll(PDO::FETCH_ASSOC);
@ -110,12 +114,16 @@ class pgSQL extends DB_PDO {
{
if($database === "")
{
$sql = 'SELECT DISTINCT "schemaname" FROM pg_tables
WHERE "schemaname" NOT LIKE \'pg\_%\'';
$sql = <<< SQL
SELECT DISTINCT "schemaname" FROM "pg_tables"
WHERE "schemaname" NOT LIKE 'pg\_%'
SQL;
}
$sql = 'SELECT "nspname" FROM pg_namespace
WHERE "nspname" NOT LIKE \'pg\_%\'';
$sql = <<< SQL
SELECT "nspname" FROM pg_namespace
WHERE "nspname" NOT LIKE 'pg\_%'
SQL;
$res = $this->query($sql);
$schemas = $res->fetchAll(PDO::FETCH_ASSOC);

View File

@ -42,7 +42,8 @@ class SQLite extends DB_PDO {
{
// SQLite has a TRUNCATE optimization,
// but no support for the actual command.
$sql = "DELETE FROM {$table}";
$sql = <<<SQL DELETE FROM "{$table}""
SQL;
$this->query($sql);
}
@ -54,7 +55,9 @@ class SQLite extends DB_PDO {
function get_tables()
{
$tables = array();
$res = $this->query("SELECT \"name\", \"sql\" FROM sqlite_master WHERE type='table'");
$sql = <<<SQL SELECT "name", "sql" FROM "sqlite_master" WHERE type='table'
SQL;
$res = $this->query($sql);
$result = $res->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $r)
@ -65,9 +68,50 @@ class SQLite extends DB_PDO {
return $tables;
}
/**
* List system tables for the current database
*
* @return array
*/
function get_system_tables()
{
$sql= <<< SQL
SELECT "name", "type"
FROM sqlite_master
WHERE "type" IN ('table', 'view')
AND "name" NOT LIKE 'sqlite?_%' escape '?'
SQL;
$res = $this->query($sql);
$result = $res->fetchAll(PDO::FETCH_ASSOC);
return $result;
}
/**
* Load a database for the current connection
*
* @param string $db
* @param string $name
*/
function load_database($db, $name)
{
$sql = <<< SQL
ATTACH DATABASE '{$db}' AS "{$name}"
SQL;
$this->query($sql);
}
/**
* Unload a database from the current connection
*
* @param string $name
*/
function unload_database($name)
{
$sql = <<< SQL DETACH DATABASE "{$name}""
SQL;
$this->query($sql);
}
/**