mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +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() { /* {{{ */
|
||||
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'";
|
||||
$sql = "SELECT `TABLE_NAME` AS `name` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA`='".$this->_database."' AND `TABLE_TYPE`='BASE TABLE'";
|
||||
break;
|
||||
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;
|
||||
case 'pgsql':
|
||||
$sql = "select tablename as name from pg_catalog.pg_tables where schemaname='public'";
|
||||
|
@ -136,6 +136,33 @@ class SeedDMS_Core_DatabaseAccess {
|
|||
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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user