mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-10-09 18:42:56 +00:00
new method hasTable(), beautify some sql statements
This commit is contained in:
parent
24db93eb36
commit
40adb027db
|
@ -118,10 +118,10 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
function TableList() { /* {{{ */
|
function TableList() { /* {{{ */
|
||||||
switch($this->_driver) {
|
switch($this->_driver) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
$sql = "select TABLE_NAME as name from information_schema.tables where TABLE_SCHEMA='".$this->_database."' and TABLE_TYPE='BASE TABLE'";
|
$sql = "SELECT `TABLE_NAME` AS `name` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA`='".$this->_database."' AND `TABLE_TYPE`='BASE TABLE'";
|
||||||
break;
|
break;
|
||||||
case 'sqlite':
|
case 'sqlite':
|
||||||
$sql = "select tbl_name as name from sqlite_master where type='table'";
|
$sql = "SELECT tbl_name AS name FROM sqlite_master WHERE type='table'";
|
||||||
break;
|
break;
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
$sql = "select tablename as name from pg_catalog.pg_tables where schemaname='public'";
|
$sql = "select tablename as name from pg_catalog.pg_tables where schemaname='public'";
|
||||||
|
@ -136,6 +136,33 @@ class SeedDMS_Core_DatabaseAccess {
|
||||||
return $res;
|
return $res;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if database has a table
|
||||||
|
*
|
||||||
|
* This function will check if the database has a table with the given table name
|
||||||
|
*
|
||||||
|
* @return bool true if table exists, otherwise false
|
||||||
|
*/
|
||||||
|
function hasTable($name) { /* {{{ */
|
||||||
|
switch($this->_driver) {
|
||||||
|
case 'mysql':
|
||||||
|
$sql = "SELECT `TABLE_NAME` AS `name` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA`='".$this->_database."' AND `TABLE_TYPE`='BASE TABLE' AND `TABLE_NAME`=".$this->qstr($name);
|
||||||
|
break;
|
||||||
|
case 'sqlite':
|
||||||
|
$sql = "SELECT tbl_name AS name FROM sqlite_master WHERE type='table' AND `tbl_name`=".$this->qstr($name);
|
||||||
|
break;
|
||||||
|
case 'pgsql':
|
||||||
|
$sql = "SELECT tablename AS name FROM pg_catalog.pg_tables WHERE schemaname='public' AND tablename=".$this->qstr($name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$arr = $this->getResultArray($sql);
|
||||||
|
if($arr)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of all database views
|
* Return list of all database views
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user