aboutsummaryrefslogtreecommitdiffstats
path: root/include/dblayer/functions_pgsql.inc.php
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2010-01-28 11:30:36 +0000
committernikrou <nikrou@piwigo.org>2010-01-28 11:30:36 +0000
commit386864cd2612ac743e182253541bddfebed80606 (patch)
treef2c8a0d0f72bb919e28f751c8fc20544a919ba8e /include/dblayer/functions_pgsql.inc.php
parent22191d91a223c4e71399f32ff42cf61a53e9d19d (diff)
Feature 511 : add support for sqlite database engine
Using session_write_close function when session handler use database because write is called after object destruction. git-svn-id: http://piwigo.org/svn/trunk@4781 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/dblayer/functions_pgsql.inc.php')
-rw-r--r--include/dblayer/functions_pgsql.inc.php66
1 files changed, 14 insertions, 52 deletions
diff --git a/include/dblayer/functions_pgsql.inc.php b/include/dblayer/functions_pgsql.inc.php
index 9e51aef04..afbb635cd 100644
--- a/include/dblayer/functions_pgsql.inc.php
+++ b/include/dblayer/functions_pgsql.inc.php
@@ -70,8 +70,6 @@ function pwg_query($query)
{
global $conf,$page,$debug,$t2;
- // Log::getInstance()->debug($query);
-
$start = get_moment();
($result = pg_query($query)) or die($query."\n<br>".pg_last_error());
@@ -212,9 +210,9 @@ function mass_updates($tablename, $dbfields, $datas, $flags=0)
{
if (count($datas) == 0)
return;
- // depending on the MySQL version, we use the multi table update or N update queries
+
if (count($datas) < 10)
- { // MySQL is prior to version 4.0.4, multi table update feature is not available
+ {
foreach ($datas as $data)
{
$query = '
@@ -378,61 +376,26 @@ function do_maintenance_all_tables()
$all_tables = array();
// List all tables
- $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\'';
- $result = pwg_query($query);
- while ($row = pwg_db_fetch_assoc($result))
- {
- array_push($all_tables, $row[0]);
- }
-
- // Repair all tables
- $query = 'REPAIR TABLE '.implode(', ', $all_tables);
- $mysql_rc = pwg_query($query);
-
- // Re-Order all tables
- foreach ($all_tables as $table_name)
- {
- $all_primary_key = array();
-
- $query = 'DESC '.$table_name.';';
- $result = pwg_query($query);
- while ($row = pwg_db_fetch_assoc($result))
- {
- if ($row['Key'] == 'PRI')
- {
- array_push($all_primary_key, $row['Field']);
- }
- }
+ $query = 'SELECT tablename FROM pg_tables
+WHERE tablename like \''.$prefixeTable.'%\'';
- if (count($all_primary_key) != 0)
- {
- $query = 'ALTER TABLE '.$table_name.' ORDER BY '.implode(', ', $all_primary_key).';';
- $mysql_rc = $mysql_rc && pwg_query($query);
- }
- }
+ $all_tables = array_from_query($query, 'tablename');
// Optimize all tables
- $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables);
- $mysql_rc = $mysql_rc && pwg_query($query);
- if ($mysql_rc)
+ foreach ($all_tables as $table)
{
- array_push(
- $page['infos'],
- l10n('Optimizations completed')
- );
- }
- else
- {
- array_push(
- $page['errors'],
- l10n('Optimizations errors')
- );
+ $query = 'VACUUM FULL '.$table;
+ pwg_query($query);
}
+ array_push($page['infos'],
+ l10n('Optimizations completed')
+ );
}
-function pwg_db_concat_ws($string, $separaor)
+function pwg_db_concat_ws($array, $separator)
{
- return 'ARRAY_TO_STRING(ARRAY['.$string.'],\''.$separaor.'\')';
+ $string = implode($array, ',');
+ return 'ARRAY_TO_STRING(ARRAY['.$string.'],\''.$separator.'\')';
}
function pwg_db_cast_to_text($string)
@@ -449,7 +412,6 @@ function pwg_db_cast_to_text($string)
function get_enums($table, $field)
{
$typname = preg_replace('/'.$GLOBALS['prefixeTable'].'/', '', $table);
- Log::getInstance()->debug($typname);
$typname .= '_' . $field;
$query = 'SELECT