Browse Source

Functions to check database type

tags/v1.6.2
Adam Bukowski 7 years ago
parent
commit
784ab6b250
23 changed files with 57 additions and 47 deletions
  1. +2
    -2
      check.php
  2. +15
    -4
      include/database.php
  3. +1
    -1
      include/history.php
  4. +4
    -4
      include/module_manager.php
  5. +5
    -5
      include/session.php
  6. +1
    -1
      modules/Apps/ActivityReport/ActivityReport_0.php
  7. +1
    -1
      modules/Base/patches/20140210_extend_session_id_length.php
  8. +2
    -2
      modules/CRM/Meeting/patches/20130613_fix_old_events.php
  9. +1
    -1
      modules/CRM/Roundcube/RC/config/db.inc.php
  10. +3
    -3
      modules/CRM/Roundcube/RC/plugins/epesi_archive/epesi_archive.php
  11. +1
    -1
      modules/CRM/Roundcube/RoundcubeInstall.php
  12. +1
    -1
      modules/CRM/Roundcube/patches/20121009_update_082.php
  13. +1
    -1
      modules/CRM/Roundcube/patches/20131015_update_094.php
  14. +1
    -1
      modules/CRM/Roundcube/patches/20140724_collation.php
  15. +2
    -2
      modules/Utils/Attachment/patches/20140205_rb_rewrite.php
  16. +1
    -1
      modules/Utils/Messenger/MessengerCommon_0.php
  17. +1
    -1
      modules/Utils/Messenger/Messenger_0.php
  18. +2
    -3
      modules/Utils/RecordBrowser/RecordBrowserCommon_0.php
  19. +3
    -3
      modules/Utils/RecordBrowser/RecordBrowser_0.php
  20. +3
    -3
      modules/Utils/RecordBrowser/patches/20140826_change_words_index.php
  21. +2
    -2
      modules/Utils/RecordBrowser/patches/add_id_keys.php
  22. +3
    -3
      setup.php
  23. +1
    -1
      update.php

+ 2
- 2
check.php View File

@@ -63,7 +63,7 @@ if ($config) {
} else $alter = $create = null;
$insert = @DB::Execute('INSERT INTO test (id) VALUES (1)');
$update = @DB::Execute('UPDATE test SET id=1 WHERE id=1');
if(DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
$lock = DB::GetOne('SELECT GET_LOCK(%s,%d)',array('test',ini_get('max_execution_time')));
$lock &= !DB::GetOne('SELECT IS_FREE_LOCK(%s)',array('test'));
$end_lock = DB::GetOne('SELECT RELEASE_LOCK(%s)',array('test'));
@@ -82,7 +82,7 @@ if ($config) {
$db_tests[] = array('label'=>'ALTER permission', 'status'=>$alter?'OK':'Failed', 'severity'=>$alter?0:2);
$db_tests[] = array('label'=>'INSERT permission', 'status'=>$insert?'OK':'Failed', 'severity'=>$insert?0:2);
$db_tests[] = array('label'=>'UPDATE permission', 'status'=>$update?'OK':'Failed', 'severity'=>$update?0:2);
if(DATABASE_DRIVER=='mysqlt')
if(DB::is_mysql())
$db_tests[] = array('label'=>'LOCK permission', 'status'=>$lock?'OK':'Failed', 'severity'=>$lock?0:2);
$db_tests[] = array('label'=>'DELETE permission', 'status'=>$delete?'OK':'Failed', 'severity'=>$delete?0:2);
$db_tests[] = array('label'=>'DROP permission', 'status'=>$drop?'OK':'Failed', 'severity'=>$drop?0:2);


+ 15
- 4
include/database.php View File

@@ -43,10 +43,10 @@ class DB {
die("Connect to database failed");
$new = self::$ado;
}
if(strcasecmp(DATABASE_DRIVER,"postgres")!==0) {
if (self::is_mysql()) {
// For MySQL
$new->Execute('SET NAMES "utf8"');
} else {
} elseif (self::is_postgresql()) {
// For PostgreSQL
@$new->Execute('SET bytea_output = "escape";');
}
@@ -61,6 +61,17 @@ class DB {
self::$ado = null;
}

public static function is_postgresql()
{
$ret = stripos(DATABASE_DRIVER, 'postgre') !== false;
return $ret;
}

public static function is_mysql()
{
$ret = stripos(DATABASE_DRIVER, 'mysql') !== false;
return $ret;
}

/**
* Statistics only. Get number of queries till now.
@@ -184,7 +195,7 @@ class DB {
}
public static function ifelse($a,$b,$c) {
if(strcasecmp(DATABASE_DRIVER,"postgres")===0)
if(self::is_postgresql())
return '(CASE WHEN '.$a.' THEN '.$b.' ELSE '.$c.' END)';
return 'IF('.$a.','.$b.','.$c.')';
}
@@ -944,7 +955,7 @@ return $ret;
public static function like() {
static $like = null;
if ($like===null) {
if(strcasecmp(DATABASE_DRIVER,"postgres")!==0) $like = 'LIKE';
if(!DB::is_postgresql()) $like = 'LIKE';
else $like = 'ILIKE';
}
return $like;


+ 1
- 1
include/history.php View File

@@ -48,7 +48,7 @@ class History {
if(!isset($_SESSION['client']['__history_id__'])) $_SESSION['client']['__history_id__']=0;
$data = serialize($_SESSION['client']['__module_vars__']);
if(GZIP_HISTORY && function_exists('gzcompress')) $data = gzcompress($data);
if(DATABASE_DRIVER=='postgres') $data = '\''.DB::BlobEncode($data).'\'';
if(DB::is_postgresql()) $data = '\''.DB::BlobEncode($data).'\'';
else $data = DB::qstr($data);
DB::StartTrans();
DB::Replace('history',array('data'=>$data,'page_id'=>$_SESSION['client']['__history_id__'], 'session_name'=>DB::qstr(self::session_id()), 'client_id'=>CID),array('session_name','page_id'));


+ 4
- 4
include/module_manager.php View File

@@ -533,7 +533,7 @@ class ModuleManager {
}
$debug .= '<b>' . $module_class_name . '</b>' . ': calling install method<br>';
if(preg_match('/^mysql/i',DATABASE_DRIVER))
if(DB::is_mysql())
DB::Execute('SET FOREIGN_KEY_CHECKS = 0');
//call install script and fill database
if(!call_user_func(array (
@@ -547,11 +547,11 @@ class ModuleManager {
));
self::remove_data_dir($module_class_name);
print($debug.'<b>' . $module_class_name . '</b>' . ': uninstalled<br>');
if(preg_match('/^mysql/i',DATABASE_DRIVER))
if(DB::is_mysql())
DB::Execute('SET FOREIGN_KEY_CHECKS = 1');
return false;
}
if(preg_match('/^mysql/i',DATABASE_DRIVER))
if(DB::is_mysql())
DB::Execute('SET FOREIGN_KEY_CHECKS = 1');
$debug .= '<b>' . $module_class_name . '</b>' . ': registering<br>';
@@ -602,7 +602,7 @@ class ModuleManager {
* @return bool true if uninstallation success, false otherwise
*/
public static final function uninstall($module) {
$module_to_uninstall = self::get_module_class_name($module);
$module_to_uninstall = self::get_module_class_name($module);
$installed_version = self::is_installed($module_to_uninstall);
if ($installed_version<0) {
print($module_to_uninstall . ' module not installed<br>');


+ 5
- 5
include/session.php View File

@@ -54,7 +54,7 @@ class DBSession {

public static function read($name) {
$name = self::truncated_session_id($name);
if(DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
if(!READ_ONLY_SESSION && !DB::GetOne('SELECT GET_LOCK(%s,%d)',array($name,ini_get('max_execution_time'))))
trigger_error('Unable to get lock on session name='.$name,E_USER_ERROR);
}
@@ -80,7 +80,7 @@ class DBSession {
$sess_file = rtrim(FILE_SESSION_DIR,'\\/').'/'.FILE_SESSION_TOKEN.$name.'_'.CID;
if(file_exists($sess_file))
$_SESSION['client'] = @unserialize(file_get_contents($sess_file));
} elseif(DATABASE_DRIVER=='postgres') {
} elseif(DB::is_postgresql()) {
//code below need testing on postgresql - concurrent epesi execution with session blocking
if(READ_ONLY_SESSION) {
self::$ado = DB::$ado;
@@ -129,7 +129,7 @@ class DBSession {
if(!file_exists(FILE_SESSION_DIR)) mkdir(FILE_SESSION_DIR);
file_put_contents($sess_file,serialize($_SESSION['client']));
chmod($sess_file, 0600);
} elseif(DATABASE_DRIVER=='postgres') {
} elseif(DB::is_postgresql()) {
//code below need testing on postgresql - concurrent epesi execution with session blocking
$data = '\''.self::$ado->BlobEncode($data).'\'';
$ret &= self::$ado->Replace('session_client',array('data'=>$data,'session_name'=>self::$ado->qstr($name),'client_id'=>CID),array('session_name','client_id'));
@@ -145,10 +145,10 @@ class DBSession {
}
if(isset($_SESSION['client'])) unset($_SESSION['client']);
$data = serialize($_SESSION);
if(DATABASE_DRIVER=='postgres') $data = '\''.DB::BlobEncode($data).'\'';
if(DB::is_postgresql()) $data = '\''.DB::BlobEncode($data).'\'';
else $data = DB::qstr($data);
$ret &= @DB::Replace('session',array('expires'=>time(),'data'=>$data,'name'=>DB::qstr($name)),'name');
if(DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
DB::Execute('SELECT RELEASE_LOCK(%s)',array($name));
}
return ($ret>0)?true:false;


+ 1
- 1
modules/Apps/ActivityReport/ActivityReport_0.php View File

@@ -116,7 +116,7 @@ class Apps_ActivityReport extends Module {
else $e_where = '';
if ($c_where) $c_where = ' WHERE'.$c_where;

$postgre_cast_type = DATABASE_DRIVER == 'postgres' ? '::varchar' : '';
$postgre_cast_type = DB::is_postgresql() ? '::varchar' : '';
// **** files ****
if (isset($filters['file']))
$tables[] = 'SELECT uaf.id AS id,uaf.created_on AS edited_on,uaf.created_by AS edited_by, ual.local AS r_id, '.DB::qstr('').' AS tab, '.DB::qstr('file').' AS action FROM utils_attachment_file uaf INNER JOIN utils_attachment_data_1 ua ON uaf.attach_id=ua.id INNER JOIN utils_attachment_local ual ON ua.id=ual.attachment WHERE original!='.DB::qstr('').' AND '.$af_where;


+ 1
- 1
modules/Base/patches/20140210_extend_session_id_length.php View File

@@ -1,6 +1,6 @@
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
$mysql = (DATABASE_DRIVER=='mysqli' || DATABASE_DRIVER=='mysqlt');
$mysql = DB::is_mysql();

if ($mysql) {
// remove foregin keys


+ 2
- 2
modules/CRM/Meeting/patches/20130613_fix_old_events.php View File

@@ -8,13 +8,13 @@ $substr_func = 'substr';

$time_field = 'f_time';
$date_field = 'f_date';
if (DATABASE_DRIVER == 'postgres') {
if (DB::is_postgresql()) {
// apply types cast required by postgres
$time_field .= '::text';
$date_field .= '::text';
}
$new_time_sql = DB::Concat($date_field, DB::qstr(' '), "$substr_func($time_field,12)");
if (DATABASE_DRIVER == 'postgres') {
if (DB::is_postgresql()) {
// apply type cast again for postgres
$new_time_sql = "cast($new_time_sql as timestamp)";
}


+ 1
- 1
modules/CRM/Roundcube/RC/config/db.inc.php View File

@@ -18,7 +18,7 @@ $rcmail_config = array();
// For examples see http://pear.php.net/manual/en/package.database.mdb2.intro-dsn.php
// currently supported db_providers: mysql, mysqli, pgsql, sqlite, mssql or sqlsrv

$rcmail_config['db_dsnw'] = (DATABASE_DRIVER=='mysqlt'?'mysql':'pgsql').'://'.DATABASE_USER.':'.DATABASE_PASSWORD.'@'.DATABASE_HOST.'/'.DATABASE_NAME;
$rcmail_config['db_dsnw'] = (DB::is_mysql()?'mysql':'pgsql').'://'.DATABASE_USER.':'.DATABASE_PASSWORD.'@'.DATABASE_HOST.'/'.DATABASE_NAME;
// postgres example: 'pgsql://roundcube:pass@localhost/roundcubemail';
// Warning: for SQLite use absolute path in DSN:
// sqlite example: 'sqlite:////full/path/to/sqlite.db?mode=0646';


+ 3
- 3
modules/CRM/Roundcube/RC/plugins/epesi_archive/epesi_archive.php View File

@@ -275,7 +275,7 @@ class epesi_archive extends rcube_plugin
//$rcmail->output->command('delete_messages');
global $E_SESSION_ID;
$lifetime = ini_get("session.gc_maxlifetime");
if(DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
if(!DB::GetOne('SELECT GET_LOCK(%s,%d)',array($E_SESSION_ID,ini_get('max_execution_time'))))
trigger_error('Unable to get lock on session name='.$E_SESSION_ID,E_USER_ERROR);
}
@@ -284,10 +284,10 @@ class epesi_archive extends rcube_plugin
$ret = unserialize($ret);
$ret['rc_mails_cp'] = $epesi_mails;
$data = serialize($ret);
if(DATABASE_DRIVER=='postgres') $data = '\''.DB::BlobEncode($data).'\'';
if(DB::is_postgresql()) $data = '\''.DB::BlobEncode($data).'\'';
else $data = DB::qstr($data);
$ret &= DB::Replace('session',array('expires'=>time(),'data'=>$data,'name'=>DB::qstr($E_SESSION_ID)),'name');
if(DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
DB::Execute('SELECT RELEASE_LOCK(%s)',array($E_SESSION_ID));
}
}


+ 1
- 1
modules/CRM/Roundcube/RoundcubeInstall.php View File

@@ -29,7 +29,7 @@ class CRM_RoundcubeInstall extends ModuleInstall {

$this->drop_all_rc_tables();

if(DATABASE_DRIVER=='mysqlt' || DATABASE_DRIVER=='mysqli')
if(DB::is_mysql())
$f = file_get_contents('modules/CRM/Roundcube/RC/SQL/mysql.initial.sql');
else
$f = file_get_contents('modules/CRM/Roundcube/RC/SQL/postgres.initial.sql');


+ 1
- 1
modules/CRM/Roundcube/patches/20121009_update_082.php View File

@@ -1,6 +1,6 @@
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
if(DATABASE_DRIVER=='mysqlt' || DATABASE_DRIVER=='mysqli')
if(DB::is_mysql())
$f = file_get_contents('modules/CRM/Roundcube/RC/SQL/mysql.update.sql');
else
$f = file_get_contents('modules/CRM/Roundcube/RC/SQL/postgres.update.sql');


+ 1
- 1
modules/CRM/Roundcube/patches/20131015_update_094.php View File

@@ -1,6 +1,6 @@
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
if(DATABASE_DRIVER=='mysqlt' || DATABASE_DRIVER=='mysqli')
if(DB::is_mysql())
$f = file_get_contents('modules/CRM/Roundcube/RC/SQL/mysql.update2.sql');
else
$f = file_get_contents('modules/CRM/Roundcube/RC/SQL/postgres.update2.sql');


+ 1
- 1
modules/CRM/Roundcube/patches/20140724_collation.php View File

@@ -1,7 +1,7 @@
<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');

if(DATABASE_DRIVER=='mysqli' || DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
@DB::Execute('ALTER DATABASE '.DATABASE_NAME.' CHARACTER SET utf8 COLLATE utf8_general_ci');
$tabs = array('rc_cache','rc_cache_index','rc_cache_messages','rc_cache_thread','rc_contactgroupmembers','rc_contactgroups','rc_contacts','rc_dictionary','rc_identities','rc_searches','rc_session','rc_system','rc_users');
foreach($tabs as $t) {


+ 2
- 2
modules/Utils/Attachment/patches/20140205_rb_rewrite.php View File

@@ -132,7 +132,7 @@ $delete_old_fk_checkpoint = Patch::checkpoint('delete_old_fk');
if (!$delete_old_fk_checkpoint->is_done()) {
Patch::require_time(5);

if(DATABASE_DRIVER=='mysqli' || DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
$a = DB::GetRow('SHOW CREATE TABLE utils_attachment_file');
if(preg_match('/CONSTRAINT (.+) FOREIGN KEY .*attach_id/',$a[1],$m))
DB::Execute('alter table `utils_attachment_file` drop foreign key '.$m[1]);
@@ -215,7 +215,7 @@ $new_fk_checkpoint = Patch::checkpoint('create_new_fk');
if (!$new_fk_checkpoint->is_done()) {
Patch::require_time(5);

if(DATABASE_DRIVER=='mysqli' || DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
DB::Execute('ALTER TABLE utils_attachment_file ADD FOREIGN KEY (attach_id) REFERENCES utils_attachment_data_1(id)');
} else {
DB::Execute('ALTER TABLE utils_attachment_file ADD CONSTRAINT attach_id_fk FOREIGN KEY (attach_id) REFERENCES utils_attachment_data_1');


+ 1
- 1
modules/Utils/Messenger/MessengerCommon_0.php View File

@@ -93,7 +93,7 @@ class Utils_MessengerCommon extends ModuleCommon {
}

public static function cron2() {
$interval = DATABASE_DRIVER == 'postgres' ? DB::qstr('4 minute') : '4 minute';
$interval = DB::is_postgresql() ? DB::qstr('4 minute') : '4 minute';
$arr = DB::GetAll('SELECT m.*,u.* FROM utils_messenger_message m INNER JOIN utils_messenger_users u ON u.message_id=m.id WHERE u.follow=0 AND m.alert_on+INTERVAL ' . $interval . ' <%T',array(time()));
foreach($arr as $row) {
Acl::set_user($row['user_login_id']);


+ 1
- 1
modules/Utils/Messenger/Messenger_0.php View File

@@ -214,7 +214,7 @@ class Utils_Messenger extends Module {

$t = time();
// postgres compatible interval with type cast
$interval = DATABASE_DRIVER == 'postgres' ? '::timestamp - interval \'1 hour\'' : '-INTERVAL 1 hour';
$interval = DB::is_postgresql() ? '::timestamp - interval \'1 hour\'' : '-INTERVAL 1 hour';
$ret = DB::Execute('(SELECT u.done,m.* FROM utils_messenger_message m INNER JOIN utils_messenger_users u ON u.message_id=m.id WHERE u.user_login_id=%d AND u.done=0 AND m.alert_on<%T)'.
' UNION '.
'(SELECT u.done,m.* FROM utils_messenger_message m INNER JOIN utils_messenger_users u ON u.message_id=m.id WHERE u.user_login_id=%d AND m.alert_on<%T AND u.done_on>=%T'.$interval.' AND u.done=1 ORDER BY m.alert_on DESC LIMIT 3)'.


+ 2
- 3
modules/Utils/RecordBrowser/RecordBrowserCommon_0.php View File

@@ -1114,14 +1114,13 @@ class Utils_RecordBrowserCommon extends ModuleCommon {
return $a;
}
public static function build_query( $tab, $crits = null, $admin = false, $order = array()) {
$PG = (DATABASE_DRIVER == "postgres");
if (!is_array($order)) $order = array();
$cache_key=$tab.'__'.serialize($crits).'__'.$admin.'__'.serialize($order);
static $cache = array();
self::init($tab, $admin);
if (isset($cache[$cache_key])) return $cache[$cache_key];
if (!$tab) return false;
$postgre = (strcasecmp(DATABASE_DRIVER,"postgres")===0);
$postgre = DB::is_postgresql();
$having = '';
$fields = '';
$final_tab = $tab.'_data_1 AS r';
@@ -1235,7 +1234,7 @@ class Utils_RecordBrowserCommon extends ModuleCommon {
$col2m = array();
$conv = '';
if ($PG) $conv = '::varchar';
if ($postgre) $conv = '::varchar';
foreach ($col2 as $c) {
if (self::$table_rows[self::$hash[$c]]['type']=='multiselect')
$col2m[] = $c.$conv;


+ 3
- 3
modules/Utils/RecordBrowser/RecordBrowser_0.php View File

@@ -2177,7 +2177,7 @@ class Utils_RecordBrowser extends Module {
if ($data['text_length']<$row['param']) trigger_error('Invalid field length', E_USER_ERROR);
$param = $data['text_length'];
if ($data['text_length']!=$row['param']) {
if(DATABASE_DRIVER=='postgres')
if(DB::is_postgresql())
DB::Execute('ALTER TABLE '.$this->tab.'_data_1 ALTER COLUMN f_'.$id.' TYPE VARCHAR('.$param.')');
else
DB::Execute('ALTER TABLE '.$this->tab.'_data_1 MODIFY f_'.$id.' VARCHAR('.$param.')');
@@ -2221,7 +2221,7 @@ class Utils_RecordBrowser extends Module {
}
}
if (isset($row) && isset($row['type']) && $row['type']!='multiselect' && $data['select_type']=='multiselect') {
if(DATABASE_DRIVER=='postgres')
if(DB::is_postgresql())
DB::Execute('ALTER TABLE '.$this->tab.'_data_1 ALTER COLUMN f_'.$id.' TYPE TEXT');
else
DB::Execute('ALTER TABLE '.$this->tab.'_data_1 MODIFY f_'.$id.' TEXT');
@@ -2258,7 +2258,7 @@ class Utils_RecordBrowser extends Module {
DB::StartTrans();
if ($id!=$new_id) {
Utils_RecordBrowserCommon::check_table_name($this->tab);
if(DATABASE_DRIVER=='postgres')
if(DB::is_postgresql())
DB::Execute('ALTER TABLE '.$this->tab.'_data_1 RENAME COLUMN f_'.$id.' TO f_'.$new_id);
else {
$old_param = DB::GetOne('SELECT param FROM '.$this->tab.'_field WHERE field=%s', array($field));


+ 3
- 3
modules/Utils/RecordBrowser/patches/20140826_change_words_index.php View File

@@ -26,7 +26,7 @@ if(!$tab_id_col_checkpoint->is_done()) {

PatchUtil::db_add_column('recordbrowser_words_map', 'tab_id', 'I2');
PatchUtil::db_add_column('recordbrowser_words_map', 'field_id', 'I2');
if(DATABASE_DRIVER=='postgres') {
if(DB::is_postgresql()) {
DB::Execute('ALTER TABLE recordbrowser_words_map ADD CONSTRAINT tab_id_fk FOREIGN KEY (tab_id) REFERENCES recordbrowser_table_properties');
} else {
DB::Execute('ALTER TABLE recordbrowser_words_map ADD FOREIGN KEY (tab_id) REFERENCES recordbrowser_table_properties(id)');
@@ -38,7 +38,7 @@ $remove_idx_checkpoint = Patch::checkpoint('remove_idx');
if(!$remove_idx_checkpoint->is_done()) {
Patch::require_time(20);

if(DATABASE_DRIVER=='mysqli' || DATABASE_DRIVER=='mysqlt') {
if(DB::is_mysql()) {
$a = DB::GetRow('SHOW CREATE TABLE recordbrowser_words_map');
if(preg_match('/CONSTRAINT (.+) FOREIGN KEY .*word_id/',$a[1],$m))
DB::Execute('alter table `recordbrowser_words_map` drop foreign key '.$m[1]);
@@ -73,7 +73,7 @@ if(!$finalize_checkpoint->is_done()) {
PatchUtil::db_drop_column('recordbrowser_words_map', 'tab');
PatchUtil::db_drop_column('recordbrowser_words_map', 'field_name');

if(DATABASE_DRIVER=='postgres') {
if(DB::is_postgresql()) {
DB::Execute('ALTER TABLE recordbrowser_words_map ADD CONSTRAINT word_id_fk FOREIGN KEY (word_id) REFERENCES recordbrowser_words_index');
} else {
DB::Execute('ALTER TABLE recordbrowser_words_map ADD FOREIGN KEY (word_id) REFERENCES recordbrowser_words_index(id)');


+ 2
- 2
modules/Utils/RecordBrowser/patches/add_id_keys.php View File

@@ -16,7 +16,7 @@ if (!isset($columns['ID'])) {
if(!$tab_ids_checkpoint->is_done()) {
Patch::require_time(20);

if(DATABASE_DRIVER=='postgres') {
if(DB::is_postgresql()) {
DB::Execute('ALTER TABLE recordbrowser_table_properties DROP CONSTRAINT recordbrowser_table_properties_pkey');
DB::Execute('ALTER TABLE recordbrowser_table_properties ADD COLUMN id SERIAL PRIMARY KEY');
} else {
@@ -37,7 +37,7 @@ if(!$field_ids_checkpoint->is_done()) {
$tab_f = $tab . "_field";
$columns = DB::MetaColumnNames($tab_f);
if (!isset($columns['ID'])) {
if(DATABASE_DRIVER=='postgres') {
if(DB::is_postgresql()) {
@DB::Execute('ALTER TABLE '.$tab_f.' DROP CONSTRAINT '.$tab_f.'_pkey');
DB::Execute('ALTER TABLE '.$tab_f.' ADD COLUMN id SERIAL PRIMARY KEY');
} else {


+ 3
- 3
setup.php View File

@@ -548,9 +548,9 @@ function clean_database() {
require_once('include/database.php');
$tables_db = DB::MetaTables();
$tables = array();
if(DATABASE_DRIVER=='mysqlt' || DATABASE_DRIVER=='mysqli')
if(DB::is_mysql())
DB::Execute('SET FOREIGN_KEY_CHECKS=0');
if(DATABASE_DRIVER=='postgres' && strpos(DB::GetOne('SELECT version()'),'PostgreSQL 8.2')!==false) {
if(DB::is_postgresql() && strpos(DB::GetOne('SELECT version()'),'PostgreSQL 8.2')!==false) {
foreach ($tables_db as $t) {
$idxs = DB::Execute('SELECT t.tgargs as args FROM pg_trigger t,pg_class c,pg_proc p WHERE t.tgenabled AND t.tgrelid = c.oid AND t.tgfoid = p.oid AND p.proname = \'RI_FKey_check_ins\' AND c.relname = \''.strtolower($t).'\' ORDER BY t.tgrelid');
$matches = array(1=>array());
@@ -566,7 +566,7 @@ function clean_database() {
foreach($tables_db as $t) {
DB::DropTable($t);
}
if(DATABASE_DRIVER=='mysqlt' || DATABASE_DRIVER=='mysqli')
if(DB::is_mysql())
DB::Execute('SET FOREIGN_KEY_CHECKS=1');
}



+ 1
- 1
update.php View File

@@ -271,7 +271,7 @@ class EpesiUpdate
{
$this->turn_on_maintenance_mode();
//restore innodb tables in case of db reimport
if (strcasecmp(DATABASE_DRIVER, "postgres") !== 0) {
if (DB::is_mysql()) {
$tbls = DB::MetaTables('TABLE', true);
foreach ($tbls as $t) {
$tbl = DB::GetRow('SHOW CREATE TABLE ' . $t);


Loading…
Cancel
Save