diff options
author | plegall <plg@piwigo.org> | 2012-03-02 21:44:53 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2012-03-02 21:44:53 +0000 |
commit | a7114b00c2199a4baa2635ddfad0ff2c29c2c4e7 (patch) | |
tree | edf91db9a183dbb37792bc2db9de3a704f6ecdb6 | |
parent | 63c5934de22932e6a7209d6c87f5d08a694b03fc (diff) |
remove files related to database engines other than MySQL
git-svn-id: http://piwigo.org/svn/trunk@13465 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | include/dblayer/functions_pdo-sqlite.inc.php | 713 | ||||
-rw-r--r-- | include/dblayer/functions_pgsql.inc.php | 796 | ||||
-rw-r--r-- | include/dblayer/functions_sqlite.inc.php | 724 | ||||
-rw-r--r-- | install/piwigo_structure-pdo-sqlite.sql | 541 | ||||
-rw-r--r-- | install/piwigo_structure-pgsql.sql | 656 | ||||
-rw-r--r-- | install/piwigo_structure-sqlite.sql | 541 |
6 files changed, 0 insertions, 3971 deletions
diff --git a/include/dblayer/functions_pdo-sqlite.inc.php b/include/dblayer/functions_pdo-sqlite.inc.php deleted file mode 100644 index c14137c7f..000000000 --- a/include/dblayer/functions_pdo-sqlite.inc.php +++ /dev/null @@ -1,713 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | Piwigo - a PHP based photo gallery | -// +-----------------------------------------------------------------------+ -// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | -// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | -// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | -// +-----------------------------------------------------------------------+ -// | This program is free software; you can redistribute it and/or modify | -// | it under the terms of the GNU General Public License as published by | -// | the Free Software Foundation | -// | | -// | This program is distributed in the hope that it will be useful, but | -// | WITHOUT ANY WARRANTY; without even the implied warranty of | -// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | -// | General Public License for more details. | -// | | -// | You should have received a copy of the GNU General Public License | -// | along with this program; if not, write to the Free Software | -// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | -// | USA. | -// +-----------------------------------------------------------------------+ - -define('REQUIRED_PDO_SQLITE_VERSION', '3.0.0'); -define('DB_ENGINE', 'SQLite'); - -define('DB_REGEX_OPERATOR', 'REGEXP'); -define('DB_RANDOM_FUNCTION', 'RANDOM'); - -/** - * - * simple functions - * - */ - -function pwg_db_connect($host, $user, $password, $database) -{ - global $conf; - - $db_file = sprintf('sqlite:%s/%s.db', PHPWG_ROOT_PATH.$conf['data_location'], $database); - - $link = new PDO($db_file); - if (!$link) - { - throw new Exception('Connection to server succeed, but it was impossible to connect to database'); - } - - $link->sqliteCreateFunction('now', 'pwg_now', 0); - $link->sqliteCreateFunction('unix_timestamp', 'pwg_unix_timestamp', 0); - $link->sqliteCreateFunction('md5', 'md5', 1); - $link->sqliteCreateFunction('if', 'pwg_if', 3); - - $link->sqliteCreateFunction('regexp', 'pwg_regexp', 2); - - return $link; -} - -function pwg_db_check_version() -{ - $current_version = pwg_get_db_version(); - if (version_compare($current_version, REQUIRED_PDO_SQLITE_VERSION, '<')) - { - fatal_error( - sprintf( - 'your database version is too old, you have "%s" and you need at least "%s"', - $current_version, - REQUIRED_PDO_SQLITE_VERSION - ) - ); - } -} - -function pwg_db_check_charset() -{ - return true; -} - -function pwg_get_db_version() -{ - global $pwg_db_link; - - return $pwg_db_link->getAttribute(PDO::ATTR_SERVER_VERSION); -} - -function pwg_query($query) -{ - global $conf,$page,$debug,$t2,$pwg_db_link; - - $start = get_moment(); - - $truncate_pattern = '`truncate(.*)`i'; - $insert_pattern = '`(INSERT INTO [^)]*\)\s*VALUES)(\([^)]*\))\s*,\s*(.*)`mi'; - - if (preg_match($truncate_pattern, $query, $matches)) - { - $query = str_replace('TRUNCATE TABLE', 'DELETE FROM', $query); - $truncate_query = true; - ($result = $pwg_db_link->exec($query)) or die($query."\n<br>".$pwg_db_link->errorInfo()); - } - elseif (preg_match($insert_pattern, $query, $matches)) - { - $base_query = substr($query, 0, strlen($matches[1])+1); - $values_pattern = '`\)\s*,\s*\(`'; - $values = preg_split($values_pattern, substr($query, strlen($matches[1])+1)); - $values[0] = substr($values[0], 1); - $values[count($values)-1] = substr($values[count($values)-1], - 0, - strlen($values[count($values)-1])-1 - ); - for ($n=0;$n<count($values);$n++) - { - $query = $base_query . '('. $values[$n] . ")\n;"; - ($result = $pwg_db_link->query($query)) - or die($query."\n<br>".$pwg_db_link->lastErrorMsg()); - } - } - else - { - ($result = $pwg_db_link->query($query)) - or die($query."\n<br>".$pwg_db_link->errorInfo()); - } - - $time = get_moment() - $start; - - if (!isset($page['count_queries'])) - { - $page['count_queries'] = 0; - $page['queries_time'] = 0; - } - - $page['count_queries']++; - $page['queries_time']+= $time; - - if ($conf['show_queries']) - { - $output = ''; - $output.= '<pre>['.$page['count_queries'].'] '; - $output.= "\n".$query; - $output.= "\n".'(this query time : '; - $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>'; - $output.= "\n".'(total SQL time : '; - $output.= number_format($page['queries_time'], 3, '.', ' ').' s)'; - $output.= "\n".'(total time : '; - $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)'; - if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) ) - { - $output.= "\n".'(num rows : '; - $output.= pwg_db_num_rows($result).' )'; - } - elseif ( $result!=null - and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query) - and !isset($truncate_query)) - { - $output.= "\n".'(affected rows : '; - $output.= pwg_db_changes($result).' )'; - } - $output.= "</pre>\n"; - - $debug .= $output; - } - - return $result; -} - -function pwg_db_nextval($column, $table) -{ - $query = ' -SELECT MAX('.$column.')+1 - FROM '.$table; - list($next) = pwg_db_fetch_row(pwg_query($query)); - if (is_null($next)) - { - $next = 1; - } - return $next; -} - -/** - * - * complex functions - * - */ - -function pwg_db_changes(PDOStatement $result=null) -{ - return $result->rowCount(); -} - -function pwg_db_num_rows(PDOStatement $result) -{ - return $result->rowCount(); -} - -function pwg_db_fetch_assoc($result) -{ - return $result->fetch(PDO::FETCH_ASSOC); -} - -function pwg_db_fetch_row($result) -{ - return $result->fetch(PDO::FETCH_NUM); -} - -function pwg_db_fetch_object($result) -{ - return $result; -} - -function pwg_db_free_result($result) -{ -} - -function pwg_db_real_escape_string($s) -{ - global $pwg_db_link; - - return trim($pwg_db_link->quote($s), "'"); -} - -function pwg_db_insert_id($table=null, $column='id') -{ - global $pwg_db_link; - - return $pwg_db_link->lastInsertRowID(); -} - -/** - * - * complex functions - * - */ - -/** - * creates an array based on a query, this function is a very common pattern - * used here - * - * @param string $query - * @param string $fieldname - * @return array - */ -function array_from_query($query, $fieldname) -{ - $array = array(); - - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - array_push($array, $row[$fieldname]); - } - - return $array; -} - -define('MASS_UPDATES_SKIP_EMPTY', 1); -/** - * updates multiple lines in a table - * - * @param string table_name - * @param array dbfields - * @param array datas - * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones - * @return void - */ -function mass_updates($tablename, $dbfields, $datas, $flags=0) -{ - if (count($datas) == 0) - return; - - foreach ($datas as $data) - { - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($dbfields['update'] as $key) - { - $separator = $is_first ? '' : ",\n "; - - if (isset($data[$key]) and $data[$key] != '') - { - $query.= $separator.$key.' = \''.$data[$key].'\''; - } - else - { - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - continue; // next field - $query.= "$separator$key = NULL"; - } - $is_first = false; - } - if (!$is_first) - {// only if one field at least updated - $query.= ' - WHERE '; - $is_first = true; - foreach ($dbfields['primary'] as $key) - { - if (!$is_first) - { - $query.= ' AND '; - } - if ( isset($data[$key]) ) - { - $query.= $key.' = \''.$data[$key].'\''; - } - else - { - $query.= $key.' IS NULL'; - } - $is_first = false; - } - pwg_query($query); - } - } -} - -/** - * updates one line in a table - * - * @param string table_name - * @param array set_fields - * @param array where_fields - * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones - * @return void - */ -function single_update($tablename, $set_fields, $where_fields, $flags=0) -{ - if (count($set_fields) == 0) - { - return; - } - - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($set_fields as $key => $value) - { - $separator = $is_first ? '' : ",\n "; - - if (isset($value) and $value != '') - { - $query.= $separator.$key.' = \''.$value.'\''; - } - else - { - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - continue; // next field - $query.= "$separator$key = NULL"; - } - $is_first = false; - } - if (!$is_first) - {// only if one field at least updated - $query.= ' - WHERE '; - $is_first = true; - foreach ($where_fields as $key => $value) - { - if (!$is_first) - { - $query.= ' AND '; - } - if ( isset($value) ) - { - $query.= $key.' = \''.$value.'\''; - } - else - { - $query.= $key.' IS NULL'; - } - $is_first = false; - } - pwg_query($query); - } -} - -/** - * inserts multiple lines in a table - * - * @param string table_name - * @param array dbfields - * @param array inserts - * @return void - */ -function mass_inserts($table_name, $dbfields, $datas) -{ - if (count($datas) != 0) - { - $first = true; - - $packet_size = 16777216; - $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/ - $query = ''; - - foreach ($datas as $insert) - { - if (strlen($query) >= $packet_size) - { - pwg_query($query); - $first = true; - } - - if ($first) - { - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', $dbfields).') - VALUES'; - $first = false; - } - else - { - $query .= ' - , '; - } - - $query .= '('; - foreach ($dbfields as $field_id => $dbfield) - { - if ($field_id > 0) - { - $query .= ','; - } - - if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') - { - $query .= 'NULL'; - } - else - { - $query .= "'".$insert[$dbfield]."'"; - } - } - $query .= ')'; - } - pwg_query($query); - } -} - -/** - * inserts one line in a table - * - * @param string table_name - * @param array dbfields - * @param array insert - * @return void - */ -function single_insert($table_name, $data) -{ - if (count($data) != 0) - { - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', array_keys($data)).') - VALUES'; - - $query .= '('; - $is_first = true; - foreach ($data as $key => $value) - { - if (!$is_first) - { - $query .= ','; - } - else - { - $is_first = false; - } - - if ($value === '') - { - $query .= 'NULL'; - } - else - { - $query .= "'".$value."'"; - } - } - $query .= ')'; - - pwg_query($query); - } -} - -/** - * Do maintenance on all PWG tables - * - * @return none - */ -function do_maintenance_all_tables() -{ - global $prefixeTable, $page; - - $all_tables = array(); - - // List all tables - $query = 'SELECT name FROM SQLITE_MASTER -WHERE name LIKE \''.$prefixeTable.'%\''; - - $all_tables = array_from_query($query, 'name'); - foreach ($all_tables as $table_name) - { - $query = 'VACUUM '.$table_name.';'; - $result = pwg_query($query); - } - - array_push($page['infos'], - l10n('All optimizations have been successfully completed.') - ); -} - -function pwg_db_concat($array) -{ - return implode($array, ' || '); -} - -function pwg_db_concat_ws($array, $separator) -{ - return implode($array, ' || \''.$separator.'\' || '); -} - -function pwg_db_cast_to_text($string) -{ - return $string; -} - -/** - * returns an array containing the possible values of an enum field - * - * @param string tablename - * @param string fieldname - */ -function get_enums($table, $field) -{ - $Enums['categories']['status'] = array('public', 'private'); - $Enums['history']['section'] = array('categories','tags','search','list','favorites','most_visited','best_rated','recent_pics','recent_cats'); - $Enums['user_infos']['status'] = array('webmaster','admin','normal','generic','guest'); - $Enums['image']['type'] = array('picture','high','other'); - $Enums['plugins']['state'] = array('active', 'inactive'); - $Enums['user_cache_image']['access_type'] = array('NOT IN','IN'); - - $table = str_replace($GLOBALS['prefixeTable'], '', $table); - if (isset($Enums[$table][$field])) { - return $Enums[$table][$field]; - } else { - return array(); - } -} - -// get_boolean transforms a string to a boolean value. If the string is -// "false" (case insensitive), then the boolean value false is returned. In -// any other case, true is returned. -function get_boolean( $string ) -{ - $boolean = true; - if ('f' === $string || 'false' === $string) - { - $boolean = false; - } - return $boolean; -} - -/** - * returns boolean string 'true' or 'false' if the given var is boolean - * - * @param mixed $var - * @return mixed - */ -function boolean_to_string($var) -{ - if (is_bool($var)) - { - return $var ? 'true' : 'false'; - } - else - { - return $var; - } -} - -/** - * - * interval and date functions - * - */ - -function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE') -{ - if ($date!='CURRENT_DATE') - { - $date = '\''.$date.'\''; - } - - return 'date('.$date.',\''.-$period.' DAY\')'; -} - -function pwg_db_get_recent_period($period, $date='CURRENT_DATE') -{ - $query = 'select '.pwg_db_get_recent_period_expression($period, $date); - list($d) = pwg_db_fetch_row(pwg_query($query)); - - return $d; -} - -function pwg_db_get_flood_period_expression($seconds) -{ - return 'datetime(\'now\', \'localtime\', \''.-$seconds.' seconds\')'; -} - -function pwg_db_get_hour($date) -{ - return 'strftime(\'%H\', '.$date.')'; -} - - -function pwg_db_get_date_YYYYMM($date) -{ - return 'strftime(\'%Y%m\','.$date.')'; -} - -function pwg_db_get_date_MMDD($date) -{ - return 'strftime(\'%m%d\','.$date.')'; -} - -function pwg_db_get_year($date) -{ - return 'strftime(\'%Y\','.$date.')'; -} - -function pwg_db_get_month($date) -{ - return 'strftime(\'%m\','.$date.')'; -} - -function pwg_db_get_week($date, $mode=null) -{ - return 'strftime(\'%W\','.$date.')'; -} - -function pwg_db_get_dayofmonth($date) -{ - return 'strftime(\'%d\','.$date.')'; -} - -function pwg_db_get_dayofweek($date) -{ - return 'strftime(\'%w\','.$date.')'; -} - -function pwg_db_get_weekday($date) -{ - return 'strftime(\'%w\',date('.$date.',\'-1 DAY\'))'; -} - -function pwg_db_date_to_ts($date) -{ - return 'UNIX_TIMESTAMP('.$date.')'; -} - -// my_error returns (or send to standard output) the message concerning the -// error occured for the last mysql query. -function my_error($header, $die) -{ - global $pwg_db_link; - - $error = ''; - if (isset($pwg_db_link)) - { - $error .= '[sqlite error]'.$pwg_db_link->errorInfo()."\n"; - } - - $error .= $header; - - if ($die) - { - fatal_error($error); - } - echo("<pre>"); - trigger_error($error, E_USER_WARNING); - echo("</pre>"); -} - -// sqlite create functions -function pwg_now() -{ - return date('Y-m-d H:i:s'); -} - -function pwg_unix_timestamp() -{ - return time(); -} - -function pwg_if($expression, $value1, $value2) -{ - if ($expression) - { - return $value1; - } - else - { - return $value2; - } -} - -function pwg_regexp($pattern, $string) -{ - $pattern = sprintf('`%s`', $pattern); - return preg_match($pattern, $string); -} -?> diff --git a/include/dblayer/functions_pgsql.inc.php b/include/dblayer/functions_pgsql.inc.php deleted file mode 100644 index ac560d6b2..000000000 --- a/include/dblayer/functions_pgsql.inc.php +++ /dev/null @@ -1,796 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | Piwigo - a PHP based photo gallery | -// +-----------------------------------------------------------------------+ -// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | -// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | -// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | -// +-----------------------------------------------------------------------+ -// | This program is free software; you can redistribute it and/or modify | -// | it under the terms of the GNU General Public License as published by | -// | the Free Software Foundation | -// | | -// | This program is distributed in the hope that it will be useful, but | -// | WITHOUT ANY WARRANTY; without even the implied warranty of | -// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | -// | General Public License for more details. | -// | | -// | You should have received a copy of the GNU General Public License | -// | along with this program; if not, write to the Free Software | -// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | -// | USA. | -// +-----------------------------------------------------------------------+ - -define('REQUIRED_PGSQL_VERSION', '8.0'); -define('DB_ENGINE', 'PostgreSQL'); - -define('DB_REGEX_OPERATOR', '~'); -define('DB_RANDOM_FUNCTION', 'RANDOM'); - -/** - * - * simple functions - * - */ - -function pwg_db_connect($host, $user, $password, $database) -{ - $connection_string = ''; - if (strpos($host,':') !== false) - { - list($host, $port) = explode(':', $host); - } - $connection_string = sprintf('host=%s', $host); - if (!empty($port)) - { - $connection_string .= sprintf(' port=%d', $port); - } - $connection_string .= sprintf(' user=%s password=%s dbname=%s', - $user, - $password, - $database); - $link = @pg_connect($connection_string); - if (!$link) - { - throw new Exception("Can't connect to server"); - } - else - { - return $link; - } -} - -function pwg_db_check_version() -{ - $current_version = pwg_get_db_version(); - if (version_compare($current_version, REQUIRED_PGSQL_VERSION, '<')) - { - fatal_error( - sprintf( - 'your database version is too old, you have "%s" and you need at least "%s"', - $current_version, - REQUIRED_PGSQL_VERSION - ) - ); - } -} - -function pwg_db_check_charset() -{ - return true; -} - -function pwg_get_db_version() -{ - list($pg_version) = pwg_db_fetch_row(pwg_query('SHOW SERVER_VERSION;')); - - return $pg_version; -} - -function pwg_query($query) -{ - global $conf,$page,$debug,$t2; - - $replace_pattern = '`REPLACE INTO\s(\S*)\s*([^)]*\))\s*VALUES\(([^,]*),(.*)\)\s*`mi'; - $select_distinct_pattern = '/SELECT\s+DISTINCT\s*(\S[^;]*\S)\s*(FROM[^(;]+WHERE[^;]+)\s+ORDER\s+BY\s+([^;]*\S)\s*;?/i'; - - $start = get_moment(); - - if (preg_match($replace_pattern, $query, $matches) - && $matches[1]==SESSIONS_TABLE) - { - $select_query = ' -SELECT id FROM '.$matches[1].' - WHERE id='.$matches[3]; - ( $result = pg_query($select_query)) or die($query."\n<br>".pg_last_error()); - if (pwg_db_num_rows($result)==1) - { - $query = ' -UPDATE '.$matches[1].' - SET expiration=now() - WHERE id='.$matches[3]; - } - else - { - $query = ' -INSERT INTO '.$matches[1].' - '.$matches[2].' VALUES('.$matches[3].','.$matches[4].')'; - } - ( $result = pg_query($query)) or die($query."\n<br>".pg_last_error()); - } - elseif (preg_match($select_distinct_pattern, $query, $matches)) - { - $select_fields_string=''; - $distinct_fields_string=''; - $orderby_fields_string=''; - - foreach (preg_split( '/\s*,\s*/', $matches[1]) as $field) - { - $split_field = preg_split( '/\s*AS\s*/i', $field); - if (isset($split_field[1])) - { - $distinct_fields[ $split_field[1] ] = $field; - } - else - { - $distinct_fields[ $field ] = $field; - } - } - - foreach (preg_split( '/\s*,\s*/', $matches[3]) as $field) - { - $kv = preg_split( '/\s+/', $field ); - $orderby_fields[ $kv[0] ] = $kv[1]; - } - - foreach ($distinct_fields as $as_field => $field) - { - if ($distinct_fields_string) - { - $distinct_fields_string=$distinct_fields_string.', '; - } - - $distinct_fields_string=$distinct_fields_string.$as_field; - - if ($select_fields_string) - { - $select_fields_string=$select_fields_string.', '; - } - - $select_fields_string=$select_fields_string.$field; - - if ($orderby_fields_string) - { - $orderby_fields_string=$orderby_fields_string.', '; - } - - $orderby_fields_string=$orderby_fields_string.$as_field.' '; - - if (isset($orderby_fields[$as_field])) - { - $orderby_fields_string=$orderby_fields_string.$orderby_fields[$as_field]; - unset($orderby_fields[$as_field]); - } - else - { - $orderby_fields_string=$orderby_fields_string.'ASC'; - } - } - - foreach ($orderby_fields as $field => $order) - { - $orderby_fields_string=$orderby_fields_string.', '.$field.' '.$order; - } - - $query = ' -SELECT DISTINCT ON ('.$distinct_fields_string.') '.$select_fields_string.' - '.$matches[2].' - ORDER BY '.$orderby_fields_string; - ($result = pg_query($query)) or die($query."\n<br>".pg_last_error()); - } - else - { - ($result = pg_query($query)) or die($query."\n<br>".pg_last_error()); - } - - $time = get_moment() - $start; - - if (!isset($page['count_queries'])) - { - $page['count_queries'] = 0; - $page['queries_time'] = 0; - } - - $page['count_queries']++; - $page['queries_time']+= $time; - - if ($conf['show_queries']) - { - $output = ''; - $output.= '<pre>['.$page['count_queries'].'] '; - $output.= "\n".$query; - $output.= "\n".'(this query time : '; - $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>'; - $output.= "\n".'(total SQL time : '; - $output.= number_format($page['queries_time'], 3, '.', ' ').' s)'; - $output.= "\n".'(total time : '; - $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)'; - if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) ) - { - $output.= "\n".'(num rows : '; - $output.= pwg_db_num_rows($result).' )'; - } - elseif ( $result!=null - and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query) ) - { - $output.= "\n".'(affected rows : '; - $output.= pwg_db_changes($result).' )'; - } - $output.= "</pre>\n"; - - $debug .= $output; - } - - return $result; -} - -function pwg_db_nextval($column, $table) -{ - $query = ' -SELECT nextval(\''.$table.'_'.$column.'_seq\')'; - list($next) = pwg_db_fetch_row(pwg_query($query)); - - return $next; -} - -/** - * - * complex functions - * - */ - -function pwg_db_changes($result) -{ - return pg_affected_rows($result); -} - -function pwg_db_num_rows($result) -{ - return pg_num_rows($result); -} - -function pwg_db_fetch_assoc($result) -{ - return pg_fetch_assoc($result); -} - -function pwg_db_fetch_row($result) -{ - return pg_fetch_row($result); -} - -function pwg_db_fetch_object($result) -{ - return pg_fetch_object($result); -} - -function pwg_db_free_result($result) -{ - return pg_free_result($result); -} - -function pwg_db_real_escape_string($s) -{ - return pg_escape_string($s); -} - -function pwg_db_insert_id($table=null, $column='id') -{ - $sequence = sprintf('%s_%s_seq', strtolower($table), $column); - $query = ' -SELECT CURRVAL(\''.$sequence.'\');'; - - list($id) = pwg_db_fetch_row(pwg_query($query)); - - return $id; -} - -/** - * - * complex functions - * - */ - -/** - * creates an array based on a query, this function is a very common pattern - * used here - * - * @param string $query - * @param string $fieldname - * @return array - */ -function array_from_query($query, $fieldname) -{ - $array = array(); - - $result = pwg_query($query); - while ($row = pg_fetch_assoc($result)) - { - array_push($array, $row[$fieldname]); - } - - return $array; -} - -define('MASS_UPDATES_SKIP_EMPTY', 1); -/** - * updates multiple lines in a table - * - * @param string table_name - * @param array dbfields - * @param array datas - * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones - * @return void - */ -function mass_updates($tablename, $dbfields, $datas, $flags=0) -{ - if (count($datas) == 0) - return; - - if (count($datas) < 10) - { - foreach ($datas as $data) - { - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($dbfields['update'] as $key) - { - $separator = $is_first ? '' : ",\n "; - - if (isset($data[$key]) and $data[$key] != '') - { - $query.= $separator.$key.' = \''.$data[$key].'\''; - } - else - { - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - continue; // next field - $query.= "$separator$key = NULL"; - } - $is_first = false; - } - if (!$is_first) - {// only if one field at least updated - $query.= ' - WHERE '; - $is_first = true; - foreach ($dbfields['primary'] as $key) - { - if (!$is_first) - { - $query.= ' AND '; - } - if ( isset($data[$key]) ) - { - $query.= $key.' = \''.$data[$key].'\''; - } - else - { - $query.= $key.' IS NULL'; - } - $is_first = false; - } - pwg_query($query); - } - } // foreach update - } - else - { - $all_fields = array_merge($dbfields['primary'], $dbfields['update']); - $temporary_tablename = $tablename.'_'.micro_seconds(); - $query = ' -CREATE TABLE '.$temporary_tablename.' - AS SELECT * FROM '.$tablename.' WHERE 1=2'; - - pwg_query($query); - mass_inserts($temporary_tablename, $all_fields, $datas); - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - $func_set = create_function('$s', 'return "$s = NULLIF(t2.$s, '.$tablename.'.$s)";'); - else - $func_set = create_function('$s', 'return "$s = t2.$s";'); - - // update of images table by joining with temporary table - $query = ' -UPDATE '.$tablename.' - SET '. - implode( - "\n , ", - array_map($func_set, $dbfields['update']) - ).' -FROM '.$temporary_tablename.' AS t2 - WHERE '. - implode( - "\n AND ", - array_map( - create_function('$s', 'return "'.$tablename.'.$s = t2.$s";'), - $dbfields['primary'] - ) - ); - pwg_query($query); - $query = ' -DROP TABLE '.$temporary_tablename; - pwg_query($query); - } -} - -/** - * updates one line in a table - * - * @param string table_name - * @param array set_fields - * @param array where_fields - * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones - * @return void - */ -function single_update($tablename, $set_fields, $where_fields, $flags=0) -{ - if (count($set_fields) == 0) - { - return; - } - - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($set_fields as $key => $value) - { - $separator = $is_first ? '' : ",\n "; - - if (isset($value) and $value != '') - { - $query.= $separator.$key.' = \''.$value.'\''; - } - else - { - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - continue; // next field - $query.= "$separator$key = NULL"; - } - $is_first = false; - } - if (!$is_first) - {// only if one field at least updated - $query.= ' - WHERE '; - $is_first = true; - foreach ($where_fields as $key => $value) - { - if (!$is_first) - { - $query.= ' AND '; - } - if ( isset($value) ) - { - $query.= $key.' = \''.$value.'\''; - } - else - { - $query.= $key.' IS NULL'; - } - $is_first = false; - } - pwg_query($query); - } -} - -/** - * inserts multiple lines in a table - * - * @param string table_name - * @param array dbfields - * @param array inserts - * @return void - */ -function mass_inserts($table_name, $dbfields, $datas) -{ - if (count($datas) != 0) - { - $first = true; - - $packet_size = 16777216; - $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/ - $query = ''; - - foreach ($datas as $insert) - { - if (strlen($query) >= $packet_size) - { - pwg_query($query); - $first = true; - } - - if ($first) - { - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', $dbfields).') - VALUES'; - $first = false; - } - else - { - $query .= ' - , '; - } - - $query .= '('; - foreach ($dbfields as $field_id => $dbfield) - { - if ($field_id > 0) - { - $query .= ','; - } - - if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') - { - $query .= 'NULL'; - } - else - { - $query .= "'".$insert[$dbfield]."'"; - } - } - $query .= ')'; - } - pwg_query($query); - } -} - -/** - * inserts one line in a table - * - * @param string table_name - * @param array dbfields - * @param array insert - * @return void - */ -function single_insert($table_name, $data) -{ - if (count($data) != 0) - { - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', array_keys($data)).') - VALUES'; - - $query .= '('; - $is_first = true; - foreach ($data as $key => $value) - { - if (!$is_first) - { - $query .= ','; - } - else - { - $is_first = false; - } - - if ($value === '') - { - $query .= 'NULL'; - } - else - { - $query .= "'".$value."'"; - } - } - $query .= ')'; - - pwg_query($query); - } -} - -/** - * Do maintenance on all PWG tables - * - * @return none - */ -function do_maintenance_all_tables() -{ - global $prefixeTable, $page; - - $all_tables = array(); - - // List all tables - $query = 'SELECT tablename FROM pg_tables -WHERE tablename like \''.$prefixeTable.'%\''; - - $all_tables = array_from_query($query, 'tablename'); - - // Optimize all tables - foreach ($all_tables as $table) - { - $query = 'VACUUM FULL '.$table; - pwg_query($query); - } - array_push($page['infos'], - l10n('All optimizations have been successfully completed.') - ); -} - -function pwg_db_concat($array) -{ - return implode($array, ' || '); -} - -function pwg_db_concat_ws($array, $separator) -{ - return implode($array, ' || \''.$separator.'\' || '); -} - -function pwg_db_cast_to_text($string) -{ - return 'CAST('.$string.' AS TEXT)'; -} - -/** - * returns an array containing the possible values of an enum field - * - * @param string tablename - * @param string fieldname - */ -function get_enums($table, $field) -{ - $typname = preg_replace('/'.$GLOBALS['prefixeTable'].'/', '', $table); - $typname .= '_' . $field; - - $query = 'SELECT -enumlabel FROM pg_enum JOIN pg_type - ON pg_enum.enumtypid=pg_type.oid - WHERE typname=\''.$typname.'\' -'; - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $options[] = $row['enumlabel']; - } - - return $options; -} - -// get_boolean transforms a string to a boolean value. If the string is -// "false" (case insensitive), then the boolean value false is returned. In -// any other case, true is returned. -function get_boolean( $string ) -{ - $boolean = true; - if ('f' == $string || 'false' == $string) - { - $boolean = false; - } - return $boolean; -} - -/** - * returns boolean string 'true' or 'false' if the given var is boolean - * - * @param mixed $var - * @return mixed - */ -function boolean_to_string($var) -{ - if (is_bool($var)) - { - return $var ? 'true' : 'false'; - } - elseif ($var=='t' || $var=='f') - { - return ($var=='t') ? 'true' : 'false'; - } - else - { - return $var; - } -} - -/** - * - * interval and date functions - * - */ - -function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE') -{ - if ($date!='CURRENT_DATE') - { - $date = '\''.$date.'\'::date'; - } - - return '('.$date.' - \''.$period.' DAY\'::interval)::date'; -} - -function pwg_db_get_recent_period($period, $date='CURRENT_DATE') -{ - $query = 'select '.pwg_db_get_recent_period_expression($period, $date); - list($d) = pwg_db_fetch_row(pwg_query($query)); - - return $d; -} - -function pwg_db_get_flood_period_expression($seconds) -{ - return 'now() - \''.$seconds.' SECOND\'::interval'; -} - -function pwg_db_get_hour($date) -{ - return 'EXTRACT(HOUR FROM '.$date.')'; -} - -function pwg_db_get_date_YYYYMM($date) -{ - return 'TO_CHAR('.$date.', \'YYYYMM\')'; -} - -function pwg_db_get_date_MMDD($date) -{ - return 'TO_CHAR('.$date.', \'MMDD\')'; -} - -function pwg_db_get_year($date) -{ - return 'EXTRACT(YEAR FROM '.$date.')'; -} - -function pwg_db_get_month($date) -{ - return 'EXTRACT(MONTH FROM '.$date.')'; -} - -function pwg_db_get_week($date, $mode=null) -{ - return 'EXTRACT(WEEK FROM '.$date.')'; -} - -function pwg_db_get_dayofmonth($date) -{ - return 'EXTRACT(DAY FROM '.$date.')'; -} - -function pwg_db_get_dayofweek($date) -{ - return 'EXTRACT(DOW FROM '.$date.')::INTEGER - 1'; -} - -function pwg_db_get_weekday($date) -{ - return 'EXTRACT(ISODOW FROM '.$date.')::INTEGER - 1'; -} - -function pwg_db_date_to_ts($date) -{ - return 'EXTRACT(EPOCH FROM '.$date.')'; -} - -// my_error returns (or send to standard output) the message concerning the -// error occured for the last pgsql query. -function my_error($header, $die) -{ - $error = '[pgsql error]'.pg_last_error()."\n"; - $error .= $header; - - if ($die) - { - fatal_error($error); - } - echo("<pre>"); - trigger_error($error, E_USER_WARNING); - echo("</pre>"); -} - - -?>
\ No newline at end of file diff --git a/include/dblayer/functions_sqlite.inc.php b/include/dblayer/functions_sqlite.inc.php deleted file mode 100644 index 360cbee2c..000000000 --- a/include/dblayer/functions_sqlite.inc.php +++ /dev/null @@ -1,724 +0,0 @@ -<?php -// +-----------------------------------------------------------------------+ -// | Piwigo - a PHP based photo gallery | -// +-----------------------------------------------------------------------+ -// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | -// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | -// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | -// +-----------------------------------------------------------------------+ -// | This program is free software; you can redistribute it and/or modify | -// | it under the terms of the GNU General Public License as published by | -// | the Free Software Foundation | -// | | -// | This program is distributed in the hope that it will be useful, but | -// | WITHOUT ANY WARRANTY; without even the implied warranty of | -// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | -// | General Public License for more details. | -// | | -// | You should have received a copy of the GNU General Public License | -// | along with this program; if not, write to the Free Software | -// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | -// | USA. | -// +-----------------------------------------------------------------------+ - -define('REQUIRED_SQLITE_VERSION', '3.0.0'); -define('DB_ENGINE', 'SQLite'); - -define('DB_REGEX_OPERATOR', 'REGEXP'); -define('DB_RANDOM_FUNCTION', 'RANDOM'); - -/** - * - * simple functions - * - */ - -function pwg_db_connect($host, $user, $password, $database) -{ - global $conf; - - $db_file = sprintf('%s/%s.db', PHPWG_ROOT_PATH.$conf['data_location'], $database); - - if (script_basename()=='install') - { - $sqlite_open_mode = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE; - } - else - { - $sqlite_open_mode = SQLITE3_OPEN_READWRITE; - } - - $link = new SQLite3($db_file, $sqlite_open_mode); - if (!$link) - { - throw new Exception('Connection to server succeed, but it was impossible to connect to database'); - } - - $link->createFunction('now', 'pwg_now', 0); - $link->createFunction('unix_timestamp', 'pwg_unix_timestamp', 1); - $link->createFunction('md5', 'md5', 1); - $link->createFunction('if', 'pwg_if', 3); - - $link->createFunction('regexp', 'pwg_regexp', 2); - - return $link; -} - -function pwg_db_check_version() -{ - $current_version = pwg_get_db_version(); - if (version_compare($current_version, REQUIRED_SQLITE_VERSION, '<')) - { - fatal_error( - sprintf( - 'your database version is too old, you have "%s" and you need at least "%s"', - $current_version, - REQUIRED_SQLITE_VERSION - ) - ); - } -} - -function pwg_db_check_charset() -{ - return true; -} - -function pwg_get_db_version() -{ - global $pwg_db_link; - - $versionInfos = $pwg_db_link->version(); - return $versionInfos['versionString']; -} - -function pwg_query($query) -{ - global $conf,$page,$debug,$t2,$pwg_db_link; - - $start = get_moment(); - - $truncate_pattern = '`truncate(.*)`i'; - $insert_pattern = '`(INSERT INTO [^)]*\)\s*VALUES)(\([^)]*\))\s*,\s*(.*)`mi'; - - if (preg_match($truncate_pattern, $query, $matches)) - { - $query = str_replace('TRUNCATE TABLE', 'DELETE FROM', $query); - $truncate_query = true; - ($result = $pwg_db_link->exec($query)) or die($query."\n<br>".$pwg_db_link->lastErrorMsg()); - } - elseif (preg_match($insert_pattern, $query, $matches)) - { - $base_query = substr($query, 0, strlen($matches[1])+1); - $values_pattern = '`\)\s*,\s*\(`'; - $values = preg_split($values_pattern, substr($query, strlen($matches[1])+1)); - $values[0] = substr($values[0], 1); - $values[count($values)-1] = substr($values[count($values)-1], - 0, - strlen($values[count($values)-1])-1 - ); - for ($n=0;$n<count($values);$n++) - { - $query = $base_query . '('. $values[$n] . ")\n;"; - ($result = $pwg_db_link->query($query)) - or die($query."\n<br>".$pwg_db_link->lastErrorMsg()); - } - } - else - { - ($result = $pwg_db_link->query($query)) - or die($query."\n<br>".$pwg_db_link->lastErrorMsg()); - } - - $time = get_moment() - $start; - - if (!isset($page['count_queries'])) - { - $page['count_queries'] = 0; - $page['queries_time'] = 0; - } - - $page['count_queries']++; - $page['queries_time']+= $time; - - if ($conf['show_queries']) - { - $output = ''; - $output.= '<pre>['.$page['count_queries'].'] '; - $output.= "\n".$query; - $output.= "\n".'(this query time : '; - $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>'; - $output.= "\n".'(total SQL time : '; - $output.= number_format($page['queries_time'], 3, '.', ' ').' s)'; - $output.= "\n".'(total time : '; - $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)'; - if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) ) - { - $output.= "\n".'(num rows : '; - $output.= pwg_db_num_rows($result).' )'; - } - elseif ( $result!=null - and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query) - and !isset($truncate_query)) - { - $output.= "\n".'(affected rows : '; - $output.= pwg_db_changes($result).' )'; - } - $output.= "</pre>\n"; - - $debug .= $output; - } - - return $result; -} - -function pwg_db_nextval($column, $table) -{ - $query = ' -SELECT MAX('.$column.')+1 - FROM '.$table; - list($next) = pwg_db_fetch_row(pwg_query($query)); - if (is_null($next)) - { - $next = 1; - } - return $next; -} - -/** - * - * complex functions - * - */ - -function pwg_db_changes(SQLite3Result $result=null) -{ - global $pwg_db_link; - - return $pwg_db_link->changes(); -} - -function pwg_db_num_rows($result) -{ - return $result->numColumns(); -} - -function pwg_db_fetch_assoc($result) -{ - return $result->fetchArray(SQLITE3_ASSOC); -} - -function pwg_db_fetch_row($result) -{ - return $result->fetchArray(SQLITE3_NUM); -} - -function pwg_db_fetch_object($result) -{ - return $result; -} - -function pwg_db_free_result($result) -{ -} - -function pwg_db_real_escape_string($s) -{ - global $pwg_db_link; - - return $pwg_db_link->escapeString($s); -} - -function pwg_db_insert_id($table=null, $column='id') -{ - global $pwg_db_link; - - return $pwg_db_link->lastInsertRowID(); -} - -/** - * - * complex functions - * - */ - -/** - * creates an array based on a query, this function is a very common pattern - * used here - * - * @param string $query - * @param string $fieldname - * @return array - */ -function array_from_query($query, $fieldname) -{ - $array = array(); - - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - array_push($array, $row[$fieldname]); - } - - return $array; -} - -define('MASS_UPDATES_SKIP_EMPTY', 1); -/** - * updates multiple lines in a table - * - * @param string table_name - * @param array dbfields - * @param array datas - * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones - * @return void - */ -function mass_updates($tablename, $dbfields, $datas, $flags=0) -{ - if (count($datas) == 0) - return; - - foreach ($datas as $data) - { - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($dbfields['update'] as $key) - { - $separator = $is_first ? '' : ",\n "; - - if (isset($data[$key]) and $data[$key] != '') - { - $query.= $separator.$key.' = \''.$data[$key].'\''; - } - else - { - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - continue; // next field - $query.= "$separator$key = NULL"; - } - $is_first = false; - } - if (!$is_first) - {// only if one field at least updated - $query.= ' - WHERE '; - $is_first = true; - foreach ($dbfields['primary'] as $key) - { - if (!$is_first) - { - $query.= ' AND '; - } - if ( isset($data[$key]) ) - { - $query.= $key.' = \''.$data[$key].'\''; - } - else - { - $query.= $key.' IS NULL'; - } - $is_first = false; - } - pwg_query($query); - } - } -} - -/** - * updates one line in a table - * - * @param string table_name - * @param array set_fields - * @param array where_fields - * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones - * @return void - */ -function single_update($tablename, $set_fields, $where_fields, $flags=0) -{ - if (count($set_fields) == 0) - { - return; - } - - $query = ' -UPDATE '.$tablename.' - SET '; - $is_first = true; - foreach ($set_fields as $key => $value) - { - $separator = $is_first ? '' : ",\n "; - - if (isset($value) and $value != '') - { - $query.= $separator.$key.' = \''.$value.'\''; - } - else - { - if ( $flags & MASS_UPDATES_SKIP_EMPTY ) - continue; // next field - $query.= "$separator$key = NULL"; - } - $is_first = false; - } - if (!$is_first) - {// only if one field at least updated - $query.= ' - WHERE '; - $is_first = true; - foreach ($where_fields as $key => $value) - { - if (!$is_first) - { - $query.= ' AND '; - } - if ( isset($value) ) - { - $query.= $key.' = \''.$value.'\''; - } - else - { - $query.= $key.' IS NULL'; - } - $is_first = false; - } - pwg_query($query); - } -} - -/** - * inserts multiple lines in a table - * - * @param string table_name - * @param array dbfields - * @param array inserts - * @return void - */ -function mass_inserts($table_name, $dbfields, $datas) -{ - if (count($datas) != 0) - { - $first = true; - - $packet_size = 16777216; - $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/ - $query = ''; - - foreach ($datas as $insert) - { - if (strlen($query) >= $packet_size) - { - pwg_query($query); - $first = true; - } - - if ($first) - { - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', $dbfields).') - VALUES'; - $first = false; - } - else - { - $query .= ' - , '; - } - - $query .= '('; - foreach ($dbfields as $field_id => $dbfield) - { - if ($field_id > 0) - { - $query .= ','; - } - - if (!isset($insert[$dbfield]) or $insert[$dbfield] === '') - { - $query .= 'NULL'; - } - else - { - $query .= "'".$insert[$dbfield]."'"; - } - } - $query .= ')'; - } - pwg_query($query); - } -} - -/** - * inserts one line in a table - * - * @param string table_name - * @param array dbfields - * @param array insert - * @return void - */ -function single_insert($table_name, $data) -{ - if (count($data) != 0) - { - $query = ' -INSERT INTO '.$table_name.' - ('.implode(',', array_keys($data)).') - VALUES'; - - $query .= '('; - $is_first = true; - foreach ($data as $key => $value) - { - if (!$is_first) - { - $query .= ','; - } - else - { - $is_first = false; - } - - if ($value === '') - { - $query .= 'NULL'; - } - else - { - $query .= "'".$value."'"; - } - } - $query .= ')'; - - pwg_query($query); - } -} - -/** - * Do maintenance on all PWG tables - * - * @return none - */ -function do_maintenance_all_tables() -{ - global $prefixeTable, $page; - - $all_tables = array(); - - // List all tables - $query = 'SELECT name FROM SQLITE_MASTER -WHERE name LIKE \''.$prefixeTable.'%\''; - - $all_tables = array_from_query($query, 'name'); - foreach ($all_tables as $table_name) - { - $query = 'VACUUM '.$table_name.';'; - $result = pwg_query($query); - } - - array_push($page['infos'], - l10n('All optimizations have been successfully completed.') - ); -} - -function pwg_db_concat($array) -{ - return implode($array, ' || '); -} - -function pwg_db_concat_ws($array, $separator) -{ - return implode($array, ' || \''.$separator.'\' || '); -} - -function pwg_db_cast_to_text($string) -{ - return $string; -} - -/** - * returns an array containing the possible values of an enum field - * - * @param string tablename - * @param string fieldname - */ -function get_enums($table, $field) -{ - $Enums['categories']['status'] = array('public', 'private'); - $Enums['history']['section'] = array('categories','tags','search','list','favorites','most_visited','best_rated','recent_pics','recent_cats'); - $Enums['user_infos']['status'] = array('webmaster','admin','normal','generic','guest'); - $Enums['image']['type'] = array('picture','high','other'); - $Enums['plugins']['state'] = array('active', 'inactive'); - $Enums['user_cache_image']['access_type'] = array('NOT IN','IN'); - - $table = str_replace($GLOBALS['prefixeTable'], '', $table); - if (isset($Enums[$table][$field])) { - return $Enums[$table][$field]; - } else { - return array(); - } -} - -// get_boolean transforms a string to a boolean value. If the string is -// "false" (case insensitive), then the boolean value false is returned. In -// any other case, true is returned. -function get_boolean( $string ) -{ - $boolean = true; - if ('f' === $string || 'false' === $string) - { - $boolean = false; - } - return $boolean; -} - -/** - * returns boolean string 'true' or 'false' if the given var is boolean - * - * @param mixed $var - * @return mixed - */ -function boolean_to_string($var) -{ - if (is_bool($var)) - { - return $var ? 'true' : 'false'; - } - else - { - return $var; - } -} - -/** - * - * interval and date functions - * - */ - -function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE') -{ - if ($date!='CURRENT_DATE') - { - $date = '\''.$date.'\''; - } - - return 'date('.$date.',\''.-$period.' DAY\')'; -} - -function pwg_db_get_recent_period($period, $date='CURRENT_DATE') -{ - $query = 'select '.pwg_db_get_recent_period_expression($period, $date); - list($d) = pwg_db_fetch_row(pwg_query($query)); - - return $d; -} - -function pwg_db_get_flood_period_expression($seconds) -{ - return 'datetime(\'now\', \'localtime\', \''.-$seconds.' seconds\')'; -} - -function pwg_db_get_hour($date) -{ - return 'strftime(\'%H\', '.$date.')'; -} - -function pwg_db_get_date_YYYYMM($date) -{ - return 'strftime(\'%Y%m\','.$date.')'; -} - -function pwg_db_get_date_MMDD($date) -{ - return 'strftime(\'%m%d\','.$date.')'; -} - -function pwg_db_get_year($date) -{ - return 'strftime(\'%Y\','.$date.')'; -} - -function pwg_db_get_month($date) -{ - return 'strftime(\'%m\','.$date.')'; -} - -function pwg_db_get_week($date, $mode=null) -{ - return 'strftime(\'%W\','.$date.')'; -} - -function pwg_db_get_dayofmonth($date) -{ - return 'strftime(\'%d\','.$date.')'; -} - -function pwg_db_get_dayofweek($date) -{ - return 'strftime(\'%w\','.$date.')'; -} - -function pwg_db_get_weekday($date) -{ - return 'strftime(\'%w\',date('.$date.',\'-1 DAY\'))'; -} - -function pwg_db_date_to_ts($date) -{ - return 'UNIX_TIMESTAMP('.$date.')'; -} - -// my_error returns (or send to standard output) the message concerning the -// error occured for the last mysql query. -function my_error($header, $die) -{ - global $pwg_db_link; - - $error = ''; - if (isset($pwg_db_link)) - { - $error .= '[sqlite error]'.$pwg_db_link->lastErrorMsg()."\n"; - } - - $error .= $header; - - if ($die) - { - fatal_error($error); - } - echo("<pre>"); - trigger_error($error, E_USER_WARNING); - echo("</pre>"); -} - -// sqlite create functions -function pwg_now() -{ - return date('Y-m-d H:i:s'); -} - -function pwg_unix_timestamp() -{ - return strtotime($strDate); -} - -function pwg_if($expression, $value1, $value2) -{ - if ($expression) - { - return $value1; - } - else - { - return $value2; - } -} - -function pwg_regexp($pattern, $string) -{ - $pattern = sprintf('`%s`', $pattern); - return preg_match($pattern, $string); -} -?> diff --git a/install/piwigo_structure-pdo-sqlite.sql b/install/piwigo_structure-pdo-sqlite.sql deleted file mode 100644 index 24c63b95a..000000000 --- a/install/piwigo_structure-pdo-sqlite.sql +++ /dev/null @@ -1,541 +0,0 @@ ------------------------------------------------------------------------------ --- piwigo_caddie ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_caddie; -CREATE TABLE "piwigo_caddie" -( - "user_id" INTEGER default 0 NOT NULL, - "element_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","element_id") -); - ------------------------------------------------------------------------------ --- piwigo_categories ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_categories; -CREATE TABLE "piwigo_categories" -( - "id" INTEGER NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "id_uppercat" INTEGER, - "comment" TEXT, - "dir" VARCHAR(255), - "rank" INTEGER, - "status" VARCHAR(50) default 'public', - "site_id" INTEGER default 1, - "visible" BOOLEAN default true, - "representative_picture_id" INTEGER, - "uppercats" TEXT, - "commentable" BOOLEAN default true, - "global_rank" VARCHAR(255), - "image_order" VARCHAR(128), - "permalink" VARCHAR(64), - PRIMARY KEY ("id"), - CONSTRAINT "categories_i3" UNIQUE ("permalink") -); - -CREATE INDEX "categories_i2" ON "piwigo_categories" ("id_uppercat"); - ------------------------------------------------------------------------------ --- piwigo_config ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_config; -CREATE TABLE piwigo_config -( - "param" VARCHAR(40) default '' NOT NULL, - "value" TEXT, - "comment" VARCHAR(255), - PRIMARY KEY ("param") -); - ------------------------------------------------------------------------------ --- piwigo_favorites ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_favorites; -CREATE TABLE piwigo_favorites -( - "user_id" INTEGER default 0 NOT NULL, - "image_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","image_id") -); - - ------------------------------------------------------------------------------ --- piwigo_group_access ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_group_access; -CREATE TABLE piwigo_group_access -( - "group_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("group_id","cat_id") -); - ------------------------------------------------------------------------------ --- piwigo_groups ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_groups; -CREATE TABLE piwigo_groups -( - "id" INTEGER NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "is_default" BOOLEAN default false, - PRIMARY KEY ("id"), - CONSTRAINT "groups_ui1" UNIQUE ("name") -); - ------------------------------------------------------------------------------ --- piwigo_history ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_history; -CREATE TABLE piwigo_history -( - "id" INTEGER NOT NULL, - "date" DATE NOT NULL, - "time" TIME NOT NULL, - "user_id" INTEGER default 0 NOT NULL, - "ip" VARCHAR(15) default '' NOT NULL, - "section" VARCHAR(50) default NULL, - "category_id" INTEGER, - "tag_ids" VARCHAR(50), - "image_id" INTEGER, - "summarized" BOOLEAN default false, - "image_type" VARCHAR(50) default NULL, - PRIMARY KEY ("id") -); - - -CREATE INDEX "history_i1" ON "piwigo_history" ("summarized"); - ------------------------------------------------------------------------------ --- piwigo_history_summary ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_history_summary; -CREATE TABLE piwigo_history_summary -( - "year" INTEGER default 0 NOT NULL, - "month" INTEGER, - "day" INTEGER, - "hour" INTEGER, - "nb_pages" INTEGER, - "id" INTEGER NOT NULL, - PRIMARY KEY ("id"), - CONSTRAINT "history_summary_ymdh" UNIQUE ("year","month","day","hour") -); - ------------------------------------------------------------------------------ --- piwigo_image_category ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_image_category; -CREATE TABLE piwigo_image_category -( - "image_id" INTEGER default 0 NOT NULL, - "category_id" INTEGER default 0 NOT NULL, - "rank" INTEGER, - PRIMARY KEY ("image_id","category_id") -); - - -CREATE INDEX "image_category_i1" ON "piwigo_image_category" ("category_id"); - ------------------------------------------------------------------------------ --- piwigo_image_tag ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_image_tag; -CREATE TABLE piwigo_image_tag -( - "image_id" INTEGER default 0 NOT NULL, - "tag_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("image_id","tag_id") -); - - -CREATE INDEX "image_tag_i1" ON "piwigo_image_tag" ("tag_id"); - ------------------------------------------------------------------------------ --- piwigo_images ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_images; -CREATE TABLE piwigo_images -( - "id" INTEGER NOT NULL, - "file" VARCHAR(255) default '' NOT NULL, - "date_available" TIMESTAMP NOT NULL, - "date_creation" TIMESTAMP, - "tn_ext" VARCHAR(4) default '', - "name" VARCHAR(255), - "comment" TEXT, - "author" VARCHAR(255), - "hit" INTEGER default 0 NOT NULL, - "filesize" INTEGER, - "width" INTEGER, - "height" INTEGER, - "representative_ext" VARCHAR(4), - "date_metadata_update" DATE, - "rating_score" FLOAT, - "has_high" BOOLEAN default false, - "path" VARCHAR(255) default '' NOT NULL, - "storage_category_id" INTEGER, - "high_filesize" INTEGER, - "high_width" INTEGER, - "high_height" INTEGER, - "level" INTEGER default 0 NOT NULL, - "md5sum" CHAR(32), - "added_by" INTEGER default 0 NOT NULL, - PRIMARY KEY ("id") -); - - -CREATE INDEX "images_i2" ON "piwigo_images" ("date_available"); - -CREATE INDEX "images_i3" ON "piwigo_images" ("rating_score"); - -CREATE INDEX "images_i4" ON "piwigo_images" ("hit"); - -CREATE INDEX "images_i5" ON "piwigo_images" ("date_creation"); - -CREATE INDEX "images_i1" ON "piwigo_images" ("storage_category_id"); - ------------------------------------------------------------------------------ --- Table structure for table `piwigo_languages` ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_languages; -CREATE TABLE piwigo_languages -( - "id" varchar(64) NOT NULL default '', - "version" varchar(64) NOT NULL default '0', - "name" varchar(64) default NULL, - PRIMARY KEY ("id") -); - ------------------------------------------------------------------------------ --- piwigo_old_permalinks ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_old_permalinks; -CREATE TABLE piwigo_old_permalinks -( - "cat_id" INTEGER default 0 NOT NULL, - "permalink" VARCHAR(64) default '' NOT NULL, - "date_deleted" TIMESTAMP NOT NULL, - "last_hit" TIMESTAMP, - "hit" INTEGER default 0 NOT NULL, - PRIMARY KEY ("permalink") -); - - ------------------------------------------------------------------------------ --- piwigo_plugins ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_plugins; -CREATE TABLE piwigo_plugins -( - "id" VARCHAR(64) default '' NOT NULL, - "state" VARCHAR(50) default 'inactive', - "version" VARCHAR(64) default '0' NOT NULL, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_rate ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_rate; -CREATE TABLE piwigo_rate -( - "user_id" INTEGER default 0 NOT NULL, - "element_id" INTEGER default 0 NOT NULL, - "anonymous_id" VARCHAR(45) default '' NOT NULL, - "rate" INTEGER default 0 NOT NULL, - "date" DATE NOT NULL, - PRIMARY KEY ("user_id","element_id","anonymous_id") -); - - ------------------------------------------------------------------------------ --- piwigo_search ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_search; -CREATE TABLE piwigo_search -( - "id" INTEGER NOT NULL, - "last_seen" DATE, - "rules" TEXT, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_sessions ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_sessions; -CREATE TABLE piwigo_sessions -( - "id" VARCHAR(255) default '' NOT NULL, - "data" TEXT NOT NULL, - "expiration" TIMESTAMP NOT NULL, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_sites ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_sites; -CREATE TABLE piwigo_sites -( - "id" INTEGER NOT NULL, - "galleries_url" VARCHAR(255) default '' NOT NULL, - PRIMARY KEY ("id"), - CONSTRAINT "sites_ui1" UNIQUE ("galleries_url") -); - - ------------------------------------------------------------------------------ --- piwigo_stuffs ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_stuffs; -CREATE TABLE piwigo_stuffs -( - "id" INTEGER NOT NULL, - "pos" INTEGER NOT NULL, - "name" TEXT NOT NULL, - "descr" VARCHAR(255), - "type" VARCHAR(255) NOT NULL, - "datas" TEXT, - "users" VARCHAR(255), - "groups" VARCHAR(255), - "show_title" CHAR NOT NULL, - "on_home" CHAR NOT NULL, - "on_cats" CHAR NOT NULL, - "on_picture" CHAR NOT NULL, - "id_line" VARCHAR(1), - "width" INTEGER, - PRIMARY KEY ("id") -); - - -CREATE INDEX "on_home" ON "piwigo_stuffs" ("on_home"); - -CREATE INDEX "on_cats" ON "piwigo_stuffs" ("on_cats"); - -CREATE INDEX "on_picture" ON "piwigo_stuffs" ("on_picture"); - ------------------------------------------------------------------------------ --- piwigo_tags ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_tags; -CREATE TABLE piwigo_tags -( - "id" INTEGER NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "url_name" VARCHAR(255) default '' NOT NULL, - PRIMARY KEY ("id") -); - - -CREATE INDEX "tags_i1" ON "piwigo_tags" ("url_name"); - ------------------------------------------------------------------------------ --- piwigo_themes ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_themes"; -CREATE TABLE "piwigo_themes" -( - "id" varchar(64) default '' NOT NULL, - "version" varchar(64) NOT NULL default '0', - "name" varchar(64) default NULL, - PRIMARY KEY ("id") -); - ------------------------------------------------------------------------------ --- piwigo_upgrade ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_upgrade; -CREATE TABLE piwigo_upgrade -( - "id" VARCHAR(20) default '' NOT NULL, - "applied" TIMESTAMP NOT NULL, - "description" VARCHAR(255), - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_access ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_access; -CREATE TABLE piwigo_user_access -( - "user_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","cat_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_cache ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_cache; -CREATE TABLE piwigo_user_cache -( - "user_id" INTEGER default 0 NOT NULL, - "need_update" BOOLEAN default true, - "cache_update_time" INTEGER default 0 NOT NULL, - "forbidden_categories" TEXT, - "nb_total_images" INTEGER, - "image_access_type" VARCHAR(50) default 'NOT IN', - "image_access_list" TEXT, - PRIMARY KEY ("user_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_cache_categories ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_cache_categories; -CREATE TABLE piwigo_user_cache_categories -( - "user_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - "date_last" TIMESTAMP, - "max_date_last" TIMESTAMP, - "nb_images" INTEGER default 0 NOT NULL, - "count_images" INTEGER default 0, - "count_categories" INTEGER default 0, - "user_representative_picture_id" INTEGER, - PRIMARY KEY ("user_id","cat_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_feed ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_feed; -CREATE TABLE piwigo_user_feed -( - "id" VARCHAR(50) default '' NOT NULL, - "user_id" INTEGER default 0 NOT NULL, - "last_check" TIMESTAMP, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_group ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_group; -CREATE TABLE piwigo_user_group -( - "user_id" INTEGER default 0 NOT NULL, - "group_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","group_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_infos ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_infos; -CREATE TABLE piwigo_user_infos -( - "user_id" INTEGER default 0 NOT NULL, - "nb_image_page" INTEGER default 15 NOT NULL, - "status" VARCHAR(50) default 'guest', - "language" VARCHAR(50) default 'en_UK' NOT NULL, - "maxwidth" INTEGER, - "maxheight" INTEGER, - "expand" BOOLEAN default false, - "show_nb_comments" BOOLEAN default false, - "show_nb_hits" BOOLEAN default false, - "recent_period" INTEGER default 7 NOT NULL, - "theme" VARCHAR(255) default 'Sylvia' NOT NULL, - "registration_date" TIMESTAMP NOT NULL, - "enabled_high" BOOLEAN default true, - "level" INTEGER default 0 NOT NULL, - "activation_key" CHAR(20) default NULL, - PRIMARY KEY ("user_id"), - CONSTRAINT "user_infos_ui1" UNIQUE ("user_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_mail_notification ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_mail_notification; -CREATE TABLE piwigo_user_mail_notification -( - "user_id" INTEGER default 0 NOT NULL, - "check_key" VARCHAR(16) default '' NOT NULL, - "enabled" BOOLEAN default false, - "last_send" TIMESTAMP, - PRIMARY KEY ("user_id"), - CONSTRAINT "user_mail_notification_ui1" UNIQUE ("check_key") -); - - ------------------------------------------------------------------------------ --- piwigo_users ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_users; -CREATE TABLE piwigo_users -( - "id" INTEGER NOT NULL, - "username" VARCHAR(100) default '' NOT NULL, - "password" VARCHAR(32), - "mail_address" VARCHAR(255), - PRIMARY KEY ("id"), - CONSTRAINT "users_ui1" UNIQUE ("username") -); - - ------------------------------------------------------------------------------ --- piwigo_comments ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_comments; -CREATE TABLE piwigo_comments -( - "id" INTEGER NOT NULL, - "image_id" INTEGER default 0 NOT NULL, - "date" TIMESTAMP NOT NULL, - "author" VARCHAR(255), - "content" TEXT, - "validated" BOOLEAN default false, - "validation_date" TIMESTAMP, - "author_id" INTEGER REFERENCES "piwigo_users" (id), - PRIMARY KEY ("id") -); - -CREATE INDEX "comments_i2" ON "piwigo_comments" ("validation_date"); -CREATE INDEX "comments_i1" ON "piwigo_comments" ("image_id"); - diff --git a/install/piwigo_structure-pgsql.sql b/install/piwigo_structure-pgsql.sql deleted file mode 100644 index f6b7b5ea3..000000000 --- a/install/piwigo_structure-pgsql.sql +++ /dev/null @@ -1,656 +0,0 @@ ------------------------------------------------------------------------------ --- piwigo_caddie ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_caddie; -CREATE TABLE "piwigo_caddie" -( - "user_id" INTEGER default 0 NOT NULL, - "element_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","element_id") -); - -COMMENT ON TABLE "piwigo_caddie" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_categories ------------------------------------------------------------------------------ - -DROP TYPE IF EXISTS CATEGORIES_STATUS; -CREATE TYPE CATEGORIES_STATUS AS ENUM('public', 'private'); - -DROP TABLE IF EXISTS "piwigo_categories" CASCADE; -CREATE TABLE "piwigo_categories" -( - "id" serial NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "id_uppercat" INTEGER, - "comment" TEXT, - "dir" VARCHAR(255), - "rank" INTEGER, - "status" CATEGORIES_STATUS default 'public'::CATEGORIES_STATUS, - "site_id" INTEGER default 1, - "visible" BOOLEAN default true, - "representative_picture_id" INTEGER, - "uppercats" TEXT, - "commentable" BOOLEAN default true, - "global_rank" VARCHAR(255), - "image_order" VARCHAR(128), - "permalink" VARCHAR(64), - PRIMARY KEY ("id"), - CONSTRAINT "categories_i3" UNIQUE ("permalink") -); - -COMMENT ON TABLE "piwigo_categories" IS ''; - - -SET search_path TO public; -CREATE INDEX "categories_i2" ON "piwigo_categories" ("id_uppercat"); - ------------------------------------------------------------------------------ --- piwigo_config ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_config" CASCADE; -CREATE TABLE "piwigo_config" -( - "param" VARCHAR(40) default '' NOT NULL, - "value" TEXT, - "comment" VARCHAR(255), - PRIMARY KEY ("param") -); - -COMMENT ON TABLE "piwigo_config" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_favorites ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_favorites" CASCADE; -CREATE TABLE "piwigo_favorites" -( - "user_id" INTEGER default 0 NOT NULL, - "image_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","image_id") -); - -COMMENT ON TABLE "piwigo_favorites" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_group_access ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_group_access" CASCADE; -CREATE TABLE "piwigo_group_access" -( - "group_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("group_id","cat_id") -); - -COMMENT ON TABLE "piwigo_group_access" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_groups ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_groups" CASCADE; -CREATE TABLE "piwigo_groups" -( - "id" serial NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "is_default" BOOLEAN default false, - PRIMARY KEY ("id"), - CONSTRAINT "groups_ui1" UNIQUE ("name") -); - -COMMENT ON TABLE "piwigo_groups" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_history ------------------------------------------------------------------------------ - -DROP TYPE IF EXISTS HISTORY_SECTION; -CREATE TYPE HISTORY_SECTION AS ENUM('categories','tags','search','list','favorites','most_visited','best_rated','recent_pics','recent_cats'); -DROP TYPE IF EXISTS HISTORY_IMAGE_TYPE; -CREATE TYPE HISTORY_IMAGE_TYPE AS ENUM('picture','high','other'); - -DROP TABLE IF EXISTS "piwigo_history" CASCADE; -CREATE TABLE "piwigo_history" -( - "id" serial NOT NULL, - "date" DATE NOT NULL, - "time" TIME NOT NULL, - "user_id" INTEGER default 0 NOT NULL, - "ip" VARCHAR(15) default '' NOT NULL, - "section" HISTORY_SECTION default NULL, - "category_id" INTEGER, - "tag_ids" VARCHAR(50), - "image_id" INTEGER, - "summarized" BOOLEAN default false, - "image_type" HISTORY_IMAGE_TYPE default NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_history" IS ''; - - -SET search_path TO public; -CREATE INDEX "history_i1" ON "piwigo_history" ("summarized"); - ------------------------------------------------------------------------------ --- piwigo_history_summary ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_history_summary" CASCADE; -CREATE TABLE "piwigo_history_summary" -( - "year" INTEGER default 0 NOT NULL, - "month" INTEGER, - "day" INTEGER, - "hour" INTEGER, - "nb_pages" INTEGER, - "id" serial NOT NULL, - PRIMARY KEY ("id"), - CONSTRAINT "history_summary_ymdh" UNIQUE ("year","month","day","hour") -); - -COMMENT ON TABLE "piwigo_history_summary" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_image_category ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_image_category" CASCADE; -CREATE TABLE "piwigo_image_category" -( - "image_id" INTEGER default 0 NOT NULL, - "category_id" INTEGER default 0 NOT NULL, - "rank" INTEGER, - PRIMARY KEY ("image_id","category_id") -); - -COMMENT ON TABLE "piwigo_image_category" IS ''; - - -SET search_path TO public; -CREATE INDEX "image_category_i1" ON "piwigo_image_category" ("category_id"); - ------------------------------------------------------------------------------ --- piwigo_image_tag ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_image_tag" CASCADE; -CREATE TABLE "piwigo_image_tag" -( - "image_id" INTEGER default 0 NOT NULL, - "tag_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("image_id","tag_id") -); - -COMMENT ON TABLE "piwigo_image_tag" IS ''; - - -SET search_path TO public; -CREATE INDEX "image_tag_i1" ON "piwigo_image_tag" ("tag_id"); - ------------------------------------------------------------------------------ --- piwigo_images ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_images" CASCADE; -CREATE TABLE "piwigo_images" -( - "id" serial NOT NULL, - "file" VARCHAR(255) default '' NOT NULL, - "date_available" TIMESTAMP NOT NULL, - "date_creation" TIMESTAMP, - "tn_ext" VARCHAR(4) default '', - "name" VARCHAR(255), - "comment" TEXT, - "author" VARCHAR(255), - "hit" INTEGER default 0 NOT NULL, - "filesize" INTEGER, - "width" INTEGER, - "height" INTEGER, - "representative_ext" VARCHAR(4), - "date_metadata_update" DATE, - "rating_score" FLOAT, - "has_high" BOOLEAN default false, - "path" VARCHAR(255) default '' NOT NULL, - "storage_category_id" INTEGER, - "high_filesize" INTEGER, - "high_width" INTEGER, - "high_height" INTEGER, - "level" INTEGER default 0 NOT NULL, - "md5sum" CHAR(32), - "added_by" INTEGER default 0 NOT NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_images" IS ''; - - -SET search_path TO public; -CREATE INDEX "images_i2" ON "piwigo_images" ("date_available"); - -CREATE INDEX "images_i3" ON "piwigo_images" ("rating_score"); - -CREATE INDEX "images_i4" ON "piwigo_images" ("hit"); - -CREATE INDEX "images_i5" ON "piwigo_images" ("date_creation"); - -CREATE INDEX "images_i1" ON "piwigo_images" ("storage_category_id"); - ------------------------------------------------------------------------------ --- Table structure for table `piwigo_languages` ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_languages"; -CREATE TABLE "piwigo_languages" ( - "id" varchar(64) NOT NULL default '', - "version" varchar(64) NOT NULL default '0', - "name" varchar(64) default NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_languages" IS ''; - ------------------------------------------------------------------------------ --- piwigo_old_permalinks ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_old_permalinks" CASCADE; -CREATE TABLE "piwigo_old_permalinks" -( - "cat_id" INTEGER default 0 NOT NULL, - "permalink" VARCHAR(64) default '' NOT NULL, - "date_deleted" TIMESTAMP NOT NULL, - "last_hit" TIMESTAMP, - "hit" INTEGER default 0 NOT NULL, - PRIMARY KEY ("permalink") -); - -COMMENT ON TABLE "piwigo_old_permalinks" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_plugins ------------------------------------------------------------------------------ - -DROP TYPE IF EXISTS PLUGINS_STATE; -CREATE TYPE PLUGINS_STATE AS ENUM('active', 'inactive'); - -DROP TABLE IF EXISTS "piwigo_plugins" CASCADE; -CREATE TABLE "piwigo_plugins" -( - "id" VARCHAR(64) default '' NOT NULL, - "state" PLUGINS_STATE default 'inactive'::PLUGINS_STATE, - "version" VARCHAR(64) default '0' NOT NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_plugins" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_rate ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_rate" CASCADE; -CREATE TABLE "piwigo_rate" -( - "user_id" INTEGER default 0 NOT NULL, - "element_id" INTEGER default 0 NOT NULL, - "anonymous_id" VARCHAR(45) default '' NOT NULL, - "rate" INTEGER default 0 NOT NULL, - "date" DATE NOT NULL, - PRIMARY KEY ("user_id","element_id","anonymous_id") -); - -COMMENT ON TABLE "piwigo_rate" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_search ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_search" CASCADE; -CREATE TABLE "piwigo_search" -( - "id" serial NOT NULL, - "last_seen" DATE, - "rules" TEXT, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_search" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_sessions ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_sessions" CASCADE; -CREATE TABLE "piwigo_sessions" -( - "id" VARCHAR(255) default '' NOT NULL, - "data" TEXT NOT NULL, - "expiration" TIMESTAMP NOT NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_sessions" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_sites ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_sites" CASCADE; -CREATE TABLE "piwigo_sites" -( - "id" serial NOT NULL, - "galleries_url" VARCHAR(255) default '' NOT NULL, - PRIMARY KEY ("id"), - CONSTRAINT "sites_ui1" UNIQUE ("galleries_url") -); - -COMMENT ON TABLE "piwigo_sites" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_stuffs ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_stuffs" CASCADE; -CREATE TABLE "piwigo_stuffs" -( - "id" INTEGER NOT NULL, - "pos" INTEGER NOT NULL, - "name" TEXT NOT NULL, - "descr" VARCHAR(255), - "type" VARCHAR(255) NOT NULL, - "datas" TEXT, - "users" VARCHAR(255), - "groups" VARCHAR(255), - "show_title" CHAR NOT NULL, - "on_home" CHAR NOT NULL, - "on_cats" CHAR NOT NULL, - "on_picture" CHAR NOT NULL, - "id_line" VARCHAR(1), - "width" INTEGER, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_stuffs" IS ''; - - -SET search_path TO public; -CREATE INDEX "on_home" ON "piwigo_stuffs" ("on_home"); - -CREATE INDEX "on_cats" ON "piwigo_stuffs" ("on_cats"); - -CREATE INDEX "on_picture" ON "piwigo_stuffs" ("on_picture"); - ------------------------------------------------------------------------------ --- piwigo_tags ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_tags" CASCADE; -CREATE TABLE "piwigo_tags" -( - "id" serial NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "url_name" VARCHAR(255) default '' NOT NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_tags" IS ''; - - -SET search_path TO public; -CREATE INDEX "tags_i1" ON "piwigo_tags" ("url_name"); - ------------------------------------------------------------------------------ --- piwigo_themes ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_themes" CASCADE; -CREATE TABLE "piwigo_themes" -( - "id" varchar(64) default '' NOT NULL, - "version" varchar(64) NOT NULL default '0', - "name" varchar(64) default NULL, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_themes" IS ''; - ------------------------------------------------------------------------------ --- piwigo_upgrade ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_upgrade" CASCADE; -CREATE TABLE "piwigo_upgrade" -( - "id" VARCHAR(20) default '' NOT NULL, - "applied" TIMESTAMP NOT NULL, - "description" VARCHAR(255), - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_upgrade" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_access ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_user_access" CASCADE; -CREATE TABLE "piwigo_user_access" -( - "user_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","cat_id") -); - -COMMENT ON TABLE "piwigo_user_access" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_cache ------------------------------------------------------------------------------ - -DROP TYPE IF EXISTS USER_CACHE_IMAGE_ACCESS_TYPE; -CREATE TYPE USER_CACHE_IMAGE_ACCESS_TYPE AS ENUM('NOT IN','IN'); - -DROP TABLE IF EXISTS "piwigo_user_cache" CASCADE; -CREATE TABLE "piwigo_user_cache" -( - "user_id" INTEGER default 0 NOT NULL, - "need_update" BOOLEAN default true, - "cache_update_time" INTEGER default 0 NOT NULL, - "forbidden_categories" TEXT, - "nb_total_images" INTEGER, - "image_access_type" USER_CACHE_IMAGE_ACCESS_TYPE default 'NOT IN'::USER_CACHE_IMAGE_ACCESS_TYPE, - "image_access_list" TEXT, - PRIMARY KEY ("user_id") -); - -COMMENT ON TABLE "piwigo_user_cache" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_cache_categories ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_user_cache_categories" CASCADE; -CREATE TABLE "piwigo_user_cache_categories" -( - "user_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - "date_last" TIMESTAMP, - "max_date_last" TIMESTAMP, - "nb_images" INTEGER default 0 NOT NULL, - "count_images" INTEGER default 0, - "count_categories" INTEGER default 0, - "user_representative_picture_id" INTEGER, - PRIMARY KEY ("user_id","cat_id") -); - -COMMENT ON TABLE "piwigo_user_cache_categories" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_feed ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_user_feed" CASCADE; -CREATE TABLE "piwigo_user_feed" -( - "id" VARCHAR(50) default '' NOT NULL, - "user_id" INTEGER default 0 NOT NULL, - "last_check" TIMESTAMP, - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_user_feed" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_group ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_user_group" CASCADE; -CREATE TABLE "piwigo_user_group" -( - "user_id" INTEGER default 0 NOT NULL, - "group_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","group_id") -); - -COMMENT ON TABLE "piwigo_user_group" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_infos ------------------------------------------------------------------------------ - -DROP TYPE IF EXISTS USER_INFOS_STATUS; -CREATE TYPE USER_INFOS_STATUS AS ENUM('webmaster','admin','normal','generic','guest'); - -DROP TABLE IF EXISTS "piwigo_user_infos" CASCADE; -CREATE TABLE "piwigo_user_infos" -( - "user_id" INTEGER default 0 NOT NULL, - "nb_image_page" INTEGER default 15 NOT NULL, - "status" USER_INFOS_STATUS default 'guest'::USER_INFOS_STATUS, - "language" VARCHAR(50) default 'en_UK' NOT NULL, - "maxwidth" INTEGER, - "maxheight" INTEGER, - "expand" BOOLEAN default false, - "show_nb_comments" BOOLEAN default false, - "show_nb_hits" BOOLEAN default false, - "recent_period" INTEGER default 7 NOT NULL, - "theme" VARCHAR(255) default 'Sylvia' NOT NULL, - "registration_date" TIMESTAMP NOT NULL, - "enabled_high" BOOLEAN default true, - "level" INTEGER default 0 NOT NULL, - "activation_key" CHAR(20) default NULL, - PRIMARY KEY ("user_id"), - CONSTRAINT "user_infos_ui1" UNIQUE ("user_id") -); - -COMMENT ON TABLE "piwigo_user_infos" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_user_mail_notification ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_user_mail_notification" CASCADE; -CREATE TABLE "piwigo_user_mail_notification" -( - "user_id" INTEGER default 0 NOT NULL, - "check_key" VARCHAR(16) default '' NOT NULL, - "enabled" BOOLEAN default false, - "last_send" TIMESTAMP, - PRIMARY KEY ("user_id"), - CONSTRAINT "user_mail_notification_ui1" UNIQUE ("check_key") -); - -COMMENT ON TABLE "piwigo_user_mail_notification" IS ''; - - -SET search_path TO public; ------------------------------------------------------------------------------ --- piwigo_users ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_users" CASCADE; -CREATE TABLE "piwigo_users" -( - "id" serial NOT NULL, - "username" VARCHAR(100) default '' NOT NULL, - "password" VARCHAR(32), - "mail_address" VARCHAR(255), - PRIMARY KEY ("id"), - CONSTRAINT "users_ui1" UNIQUE ("username") -); - -COMMENT ON TABLE "piwigo_users" IS ''; - - -SET search_path TO public; - ------------------------------------------------------------------------------ --- piwigo_comments ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_comments" CASCADE; -CREATE TABLE "piwigo_comments" -( - "id" serial NOT NULL, - "image_id" INTEGER default 0 NOT NULL, - "date" TIMESTAMP NOT NULL, - "author" VARCHAR(255), - "content" TEXT, - "validated" BOOLEAN default false, - "validation_date" TIMESTAMP, - "author_id" INTEGER REFERENCES "piwigo_users" (id), - PRIMARY KEY ("id") -); - -COMMENT ON TABLE "piwigo_comments" IS ''; - - -SET search_path TO public; -CREATE INDEX "comments_i2" ON "piwigo_comments" ("validation_date"); - -CREATE INDEX "comments_i1" ON "piwigo_comments" ("image_id"); diff --git a/install/piwigo_structure-sqlite.sql b/install/piwigo_structure-sqlite.sql deleted file mode 100644 index 24c63b95a..000000000 --- a/install/piwigo_structure-sqlite.sql +++ /dev/null @@ -1,541 +0,0 @@ ------------------------------------------------------------------------------ --- piwigo_caddie ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_caddie; -CREATE TABLE "piwigo_caddie" -( - "user_id" INTEGER default 0 NOT NULL, - "element_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","element_id") -); - ------------------------------------------------------------------------------ --- piwigo_categories ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_categories; -CREATE TABLE "piwigo_categories" -( - "id" INTEGER NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "id_uppercat" INTEGER, - "comment" TEXT, - "dir" VARCHAR(255), - "rank" INTEGER, - "status" VARCHAR(50) default 'public', - "site_id" INTEGER default 1, - "visible" BOOLEAN default true, - "representative_picture_id" INTEGER, - "uppercats" TEXT, - "commentable" BOOLEAN default true, - "global_rank" VARCHAR(255), - "image_order" VARCHAR(128), - "permalink" VARCHAR(64), - PRIMARY KEY ("id"), - CONSTRAINT "categories_i3" UNIQUE ("permalink") -); - -CREATE INDEX "categories_i2" ON "piwigo_categories" ("id_uppercat"); - ------------------------------------------------------------------------------ --- piwigo_config ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_config; -CREATE TABLE piwigo_config -( - "param" VARCHAR(40) default '' NOT NULL, - "value" TEXT, - "comment" VARCHAR(255), - PRIMARY KEY ("param") -); - ------------------------------------------------------------------------------ --- piwigo_favorites ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_favorites; -CREATE TABLE piwigo_favorites -( - "user_id" INTEGER default 0 NOT NULL, - "image_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","image_id") -); - - ------------------------------------------------------------------------------ --- piwigo_group_access ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_group_access; -CREATE TABLE piwigo_group_access -( - "group_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("group_id","cat_id") -); - ------------------------------------------------------------------------------ --- piwigo_groups ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_groups; -CREATE TABLE piwigo_groups -( - "id" INTEGER NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "is_default" BOOLEAN default false, - PRIMARY KEY ("id"), - CONSTRAINT "groups_ui1" UNIQUE ("name") -); - ------------------------------------------------------------------------------ --- piwigo_history ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_history; -CREATE TABLE piwigo_history -( - "id" INTEGER NOT NULL, - "date" DATE NOT NULL, - "time" TIME NOT NULL, - "user_id" INTEGER default 0 NOT NULL, - "ip" VARCHAR(15) default '' NOT NULL, - "section" VARCHAR(50) default NULL, - "category_id" INTEGER, - "tag_ids" VARCHAR(50), - "image_id" INTEGER, - "summarized" BOOLEAN default false, - "image_type" VARCHAR(50) default NULL, - PRIMARY KEY ("id") -); - - -CREATE INDEX "history_i1" ON "piwigo_history" ("summarized"); - ------------------------------------------------------------------------------ --- piwigo_history_summary ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_history_summary; -CREATE TABLE piwigo_history_summary -( - "year" INTEGER default 0 NOT NULL, - "month" INTEGER, - "day" INTEGER, - "hour" INTEGER, - "nb_pages" INTEGER, - "id" INTEGER NOT NULL, - PRIMARY KEY ("id"), - CONSTRAINT "history_summary_ymdh" UNIQUE ("year","month","day","hour") -); - ------------------------------------------------------------------------------ --- piwigo_image_category ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_image_category; -CREATE TABLE piwigo_image_category -( - "image_id" INTEGER default 0 NOT NULL, - "category_id" INTEGER default 0 NOT NULL, - "rank" INTEGER, - PRIMARY KEY ("image_id","category_id") -); - - -CREATE INDEX "image_category_i1" ON "piwigo_image_category" ("category_id"); - ------------------------------------------------------------------------------ --- piwigo_image_tag ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_image_tag; -CREATE TABLE piwigo_image_tag -( - "image_id" INTEGER default 0 NOT NULL, - "tag_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("image_id","tag_id") -); - - -CREATE INDEX "image_tag_i1" ON "piwigo_image_tag" ("tag_id"); - ------------------------------------------------------------------------------ --- piwigo_images ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_images; -CREATE TABLE piwigo_images -( - "id" INTEGER NOT NULL, - "file" VARCHAR(255) default '' NOT NULL, - "date_available" TIMESTAMP NOT NULL, - "date_creation" TIMESTAMP, - "tn_ext" VARCHAR(4) default '', - "name" VARCHAR(255), - "comment" TEXT, - "author" VARCHAR(255), - "hit" INTEGER default 0 NOT NULL, - "filesize" INTEGER, - "width" INTEGER, - "height" INTEGER, - "representative_ext" VARCHAR(4), - "date_metadata_update" DATE, - "rating_score" FLOAT, - "has_high" BOOLEAN default false, - "path" VARCHAR(255) default '' NOT NULL, - "storage_category_id" INTEGER, - "high_filesize" INTEGER, - "high_width" INTEGER, - "high_height" INTEGER, - "level" INTEGER default 0 NOT NULL, - "md5sum" CHAR(32), - "added_by" INTEGER default 0 NOT NULL, - PRIMARY KEY ("id") -); - - -CREATE INDEX "images_i2" ON "piwigo_images" ("date_available"); - -CREATE INDEX "images_i3" ON "piwigo_images" ("rating_score"); - -CREATE INDEX "images_i4" ON "piwigo_images" ("hit"); - -CREATE INDEX "images_i5" ON "piwigo_images" ("date_creation"); - -CREATE INDEX "images_i1" ON "piwigo_images" ("storage_category_id"); - ------------------------------------------------------------------------------ --- Table structure for table `piwigo_languages` ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_languages; -CREATE TABLE piwigo_languages -( - "id" varchar(64) NOT NULL default '', - "version" varchar(64) NOT NULL default '0', - "name" varchar(64) default NULL, - PRIMARY KEY ("id") -); - ------------------------------------------------------------------------------ --- piwigo_old_permalinks ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_old_permalinks; -CREATE TABLE piwigo_old_permalinks -( - "cat_id" INTEGER default 0 NOT NULL, - "permalink" VARCHAR(64) default '' NOT NULL, - "date_deleted" TIMESTAMP NOT NULL, - "last_hit" TIMESTAMP, - "hit" INTEGER default 0 NOT NULL, - PRIMARY KEY ("permalink") -); - - ------------------------------------------------------------------------------ --- piwigo_plugins ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_plugins; -CREATE TABLE piwigo_plugins -( - "id" VARCHAR(64) default '' NOT NULL, - "state" VARCHAR(50) default 'inactive', - "version" VARCHAR(64) default '0' NOT NULL, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_rate ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_rate; -CREATE TABLE piwigo_rate -( - "user_id" INTEGER default 0 NOT NULL, - "element_id" INTEGER default 0 NOT NULL, - "anonymous_id" VARCHAR(45) default '' NOT NULL, - "rate" INTEGER default 0 NOT NULL, - "date" DATE NOT NULL, - PRIMARY KEY ("user_id","element_id","anonymous_id") -); - - ------------------------------------------------------------------------------ --- piwigo_search ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_search; -CREATE TABLE piwigo_search -( - "id" INTEGER NOT NULL, - "last_seen" DATE, - "rules" TEXT, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_sessions ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_sessions; -CREATE TABLE piwigo_sessions -( - "id" VARCHAR(255) default '' NOT NULL, - "data" TEXT NOT NULL, - "expiration" TIMESTAMP NOT NULL, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_sites ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_sites; -CREATE TABLE piwigo_sites -( - "id" INTEGER NOT NULL, - "galleries_url" VARCHAR(255) default '' NOT NULL, - PRIMARY KEY ("id"), - CONSTRAINT "sites_ui1" UNIQUE ("galleries_url") -); - - ------------------------------------------------------------------------------ --- piwigo_stuffs ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_stuffs; -CREATE TABLE piwigo_stuffs -( - "id" INTEGER NOT NULL, - "pos" INTEGER NOT NULL, - "name" TEXT NOT NULL, - "descr" VARCHAR(255), - "type" VARCHAR(255) NOT NULL, - "datas" TEXT, - "users" VARCHAR(255), - "groups" VARCHAR(255), - "show_title" CHAR NOT NULL, - "on_home" CHAR NOT NULL, - "on_cats" CHAR NOT NULL, - "on_picture" CHAR NOT NULL, - "id_line" VARCHAR(1), - "width" INTEGER, - PRIMARY KEY ("id") -); - - -CREATE INDEX "on_home" ON "piwigo_stuffs" ("on_home"); - -CREATE INDEX "on_cats" ON "piwigo_stuffs" ("on_cats"); - -CREATE INDEX "on_picture" ON "piwigo_stuffs" ("on_picture"); - ------------------------------------------------------------------------------ --- piwigo_tags ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_tags; -CREATE TABLE piwigo_tags -( - "id" INTEGER NOT NULL, - "name" VARCHAR(255) default '' NOT NULL, - "url_name" VARCHAR(255) default '' NOT NULL, - PRIMARY KEY ("id") -); - - -CREATE INDEX "tags_i1" ON "piwigo_tags" ("url_name"); - ------------------------------------------------------------------------------ --- piwigo_themes ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS "piwigo_themes"; -CREATE TABLE "piwigo_themes" -( - "id" varchar(64) default '' NOT NULL, - "version" varchar(64) NOT NULL default '0', - "name" varchar(64) default NULL, - PRIMARY KEY ("id") -); - ------------------------------------------------------------------------------ --- piwigo_upgrade ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_upgrade; -CREATE TABLE piwigo_upgrade -( - "id" VARCHAR(20) default '' NOT NULL, - "applied" TIMESTAMP NOT NULL, - "description" VARCHAR(255), - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_access ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_access; -CREATE TABLE piwigo_user_access -( - "user_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","cat_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_cache ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_cache; -CREATE TABLE piwigo_user_cache -( - "user_id" INTEGER default 0 NOT NULL, - "need_update" BOOLEAN default true, - "cache_update_time" INTEGER default 0 NOT NULL, - "forbidden_categories" TEXT, - "nb_total_images" INTEGER, - "image_access_type" VARCHAR(50) default 'NOT IN', - "image_access_list" TEXT, - PRIMARY KEY ("user_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_cache_categories ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_cache_categories; -CREATE TABLE piwigo_user_cache_categories -( - "user_id" INTEGER default 0 NOT NULL, - "cat_id" INTEGER default 0 NOT NULL, - "date_last" TIMESTAMP, - "max_date_last" TIMESTAMP, - "nb_images" INTEGER default 0 NOT NULL, - "count_images" INTEGER default 0, - "count_categories" INTEGER default 0, - "user_representative_picture_id" INTEGER, - PRIMARY KEY ("user_id","cat_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_feed ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_feed; -CREATE TABLE piwigo_user_feed -( - "id" VARCHAR(50) default '' NOT NULL, - "user_id" INTEGER default 0 NOT NULL, - "last_check" TIMESTAMP, - PRIMARY KEY ("id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_group ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_group; -CREATE TABLE piwigo_user_group -( - "user_id" INTEGER default 0 NOT NULL, - "group_id" INTEGER default 0 NOT NULL, - PRIMARY KEY ("user_id","group_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_infos ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_infos; -CREATE TABLE piwigo_user_infos -( - "user_id" INTEGER default 0 NOT NULL, - "nb_image_page" INTEGER default 15 NOT NULL, - "status" VARCHAR(50) default 'guest', - "language" VARCHAR(50) default 'en_UK' NOT NULL, - "maxwidth" INTEGER, - "maxheight" INTEGER, - "expand" BOOLEAN default false, - "show_nb_comments" BOOLEAN default false, - "show_nb_hits" BOOLEAN default false, - "recent_period" INTEGER default 7 NOT NULL, - "theme" VARCHAR(255) default 'Sylvia' NOT NULL, - "registration_date" TIMESTAMP NOT NULL, - "enabled_high" BOOLEAN default true, - "level" INTEGER default 0 NOT NULL, - "activation_key" CHAR(20) default NULL, - PRIMARY KEY ("user_id"), - CONSTRAINT "user_infos_ui1" UNIQUE ("user_id") -); - - ------------------------------------------------------------------------------ --- piwigo_user_mail_notification ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_user_mail_notification; -CREATE TABLE piwigo_user_mail_notification -( - "user_id" INTEGER default 0 NOT NULL, - "check_key" VARCHAR(16) default '' NOT NULL, - "enabled" BOOLEAN default false, - "last_send" TIMESTAMP, - PRIMARY KEY ("user_id"), - CONSTRAINT "user_mail_notification_ui1" UNIQUE ("check_key") -); - - ------------------------------------------------------------------------------ --- piwigo_users ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_users; -CREATE TABLE piwigo_users -( - "id" INTEGER NOT NULL, - "username" VARCHAR(100) default '' NOT NULL, - "password" VARCHAR(32), - "mail_address" VARCHAR(255), - PRIMARY KEY ("id"), - CONSTRAINT "users_ui1" UNIQUE ("username") -); - - ------------------------------------------------------------------------------ --- piwigo_comments ------------------------------------------------------------------------------ - -DROP TABLE IF EXISTS piwigo_comments; -CREATE TABLE piwigo_comments -( - "id" INTEGER NOT NULL, - "image_id" INTEGER default 0 NOT NULL, - "date" TIMESTAMP NOT NULL, - "author" VARCHAR(255), - "content" TEXT, - "validated" BOOLEAN default false, - "validation_date" TIMESTAMP, - "author_id" INTEGER REFERENCES "piwigo_users" (id), - PRIMARY KEY ("id") -); - -CREATE INDEX "comments_i2" ON "piwigo_comments" ("validation_date"); -CREATE INDEX "comments_i1" ON "piwigo_comments" ("image_id"); - |