diff --git a/api/Api.php b/api/Api.php index c471152..49f3e6b 100644 --- a/api/Api.php +++ b/api/Api.php @@ -42,7 +42,7 @@ class Api { private $m_verifyclass = null; private $m_apiclass = null; - public function __construct(\SYSTEM\verifyclass $VerifyClass, \SYSTEM\API\apiclass $ApiClass,$DBInfo = null){ + public function __construct(\SYSTEM\verifyclass $VerifyClass, \SYSTEM\API\apiclass $ApiClass,$DBInfo = null){ $this->m_dbinfo = $DBInfo == null ? \SYSTEM\system::getSystemDBInfo() : $DBInfo; $this->m_verifyclass = $VerifyClass; $this->m_apiclass = $ApiClass; @@ -139,7 +139,7 @@ class Api { private function getApiTree(){ $con = new \SYSTEM\DB\Connection($this->m_dbinfo); - $res = $con->query('SELECT * FROM '.\SYSTEM\DBD\APITable::NAME.' ORDER BY "'.\SYSTEM\DBD\APITable::FIELD_ID.'"'); + $res = $con->query('SELECT * FROM '.(\SYSTEM\system::isSystemDbInfoPG() ? \SYSTEM\DBD\APITable::NAME_PG : \SYSTEM\DBD\APITable::NAME_MYS).' ORDER BY "'.\SYSTEM\DBD\APITable::FIELD_ID.'"'); unset($con); if(!$res){ diff --git a/dbd/tbl/APITable.php b/dbd/tbl/APITable.php index 0c37825..881e54d 100644 --- a/dbd/tbl/APITable.php +++ b/dbd/tbl/APITable.php @@ -4,7 +4,8 @@ namespace SYSTEM\DBD; class APITable { - const NAME = 'system_api_calls'; + const NAME_PG = 'system.api_calls'; + const NAME_MYS = 'system_api_calls'; const FIELD_ID = 'ID'; const FIELD_FLAG = 'flag'; diff --git a/dbd/tbl/PAGETable.php b/dbd/tbl/PAGETable.php index 576de6e..2d4567b 100644 --- a/dbd/tbl/PAGETable.php +++ b/dbd/tbl/PAGETable.php @@ -4,7 +4,8 @@ namespace SYSTEM\DBD; class PAGETable { - const NAME = 'system_page_calls'; + const NAME_PG = 'system.page_calls'; + const NAME_MYS = 'system_page_calls'; const FIELD_ID = 'ID'; const FIELD_FLAG = 'flag'; diff --git a/dbd/tbl/locale_string.php b/dbd/tbl/locale_string.php index f35c8a9..f034a08 100644 --- a/dbd/tbl/locale_string.php +++ b/dbd/tbl/locale_string.php @@ -3,7 +3,8 @@ namespace SYSTEM\DBD; class locale_string { - const NAME = 'system_locale_string'; + const NAME_PG = 'system.locale_string'; + const NAME_MYS = 'system_locale_string'; const FIELD_ID = 'id'; const FIELD_CATEGORY = 'category'; diff --git a/page/PageApi.php b/page/PageApi.php index 2b7ecbc..7b6ad3d 100644 --- a/page/PageApi.php +++ b/page/PageApi.php @@ -119,7 +119,7 @@ class PageApi { private function getPageTree(){ $con = new \SYSTEM\DB\Connection($this->m_dbinfo); - $res = $con->query('SELECT * FROM '.\SYSTEM\DBD\PAGETable::NAME.' ORDER BY "'.\SYSTEM\DBD\PAGETable::FIELD_ID.'"'); + $res = $con->query('SELECT * FROM '.(\SYSTEM\system::isSystemDbInfoPG() ? \SYSTEM\DBD\PAGETable::NAME_PG : \SYSTEM\DBD\PAGETable::NAME_MYS).' ORDER BY "'.\SYSTEM\DBD\PAGETable::FIELD_ID.'"'); if(!$res){ throw new \SYSTEM\LOG\ERROR("Database Error ". pg_last_error());} diff --git a/system/locale.php b/system/locale.php index cb02ea5..eca1dcf 100644 --- a/system/locale.php +++ b/system/locale.php @@ -52,29 +52,29 @@ class locale { foreach($request as $strid){ if(!\preg_match("^[a-zA-Z0-9_]+$^", $strid) != 0){ throw new \Exception("Requested id contains inpropper symbols: ".$strid);} - $where .= 'OR "'.\DBD\SYSTEM\locale_string::FIELD_ID.'" = $1 '; + $where .= 'OR "'.\SYSTEM\DBD\locale_string::FIELD_ID.'" = $1 '; } $where = substr($where,2); - $con = new \SYSTEM\DB\Connection(new \DBD\dasensePostgres()); - $res = $con->prepare( 'localeArrStmt', 'SELECT "'.$lang.'","'.\DBD\SYSTEM\locale_string::FIELD_ID.'" FROM '.\DBD\SYSTEM\locale_string::NAME.' WHERE '.$where, + $con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo()); + $res = $con->prepare( 'localeArrStmt', 'SELECT "'.$lang.'","'.\SYSTEM\DBD\locale_string::FIELD_ID.'" FROM '.(\SYSTEM\system::isSystemDbInfoPG() ? \SYSTEM\DBD\locale_string::NAME_PG : \SYSTEM\DBD\locale_string::NAME_MYS).' WHERE '.$where, $request); $result = array(); while($r = $res->next()){ - $result[$r[\DBD\SYSTEM\locale_string::FIELD_ID]] = $r[$lang];} + $result[$r[\SYSTEM\DBD\locale_string::FIELD_ID]] = $r[$lang];} return $result; } else if(\intval($request)){ $cat = \intval($request); $con = new \SYSTEM\DB\Connection(new \DBD\dasensePostgres()); - $res = $con->prepare( 'localeStmt', 'SELECT "'.$lang.'","'.\DBD\SYSTEM\locale_string::FIELD_ID.'" FROM '.\DBD\SYSTEM\locale_string::NAME.' WHERE '.\DBD\SYSTEM\locale_string::FIELD_CATEGORY.' = $1;', + $res = $con->prepare( 'localeStmt', 'SELECT "'.$lang.'","'.\SYSTEM\DBD\locale_string::FIELD_ID.'" FROM '.(\SYSTEM\system::isSystemDbInfoPG() ? \SYSTEM\DBD\locale_string::NAME_PG : \SYSTEM\DBD\locale_string::NAME_MYS).' WHERE '.\SYSTEM\DBD\locale_string::FIELD_CATEGORY.' = $1;', array($cat)); $result = array(); while($r = $res->next()){ - $result[$r[\DBD\SYSTEM\locale_string::FIELD_ID]] = $r[$lang];} + $result[$r[\SYSTEM\DBD\locale_string::FIELD_ID]] = $r[$lang];} return $result; } diff --git a/system/system.php b/system/system.php index 1083fa0..d06120f 100644 --- a/system/system.php +++ b/system/system.php @@ -31,4 +31,7 @@ class system { \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DB_PORT)); } } + + public static function isSystemDbInfoPG(){ + return (\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DB_TYPE) == \SYSTEM\CONFIG\config_ids::SYS_CONFIG_DB_TYPE_PG);} } \ No newline at end of file