Fix bug 1722 : PosgtreSQL wants all fields in select to be in Group by clause

or agregate function
Fix issue for lambda function (incorrect number of params)

merge from trunk.

git-svn-id: http://piwigo.org/svn/branches/2.1@6511 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
nikrou 2010-06-09 20:26:47 +00:00
parent 54fc109f97
commit a59d15b7b6
3 changed files with 30 additions and 12 deletions

View file

@ -514,6 +514,10 @@ $conf['apache_authentication'] = false;
// piwigo_users table. // piwigo_users table.
$conf['users_table'] = $prefixeTable.'users'; $conf['users_table'] = $prefixeTable.'users';
// If you decide to use external authentication
// change conf below by $conf['external_authentification'] = true;
$conf['external_authentification'] = false;
// Other tables can be changed, if you define associated constants // Other tables can be changed, if you define associated constants
// Example: // Example:
// define('USER_INFOS_TABLE', 'pwg_main'.'user_infos'); // define('USER_INFOS_TABLE', 'pwg_main'.'user_infos');

View file

@ -314,7 +314,7 @@ UPDATE '.$tablename.'
pwg_query($query); pwg_query($query);
} }
} // foreach update } // foreach update
} // if mysql_ver or count<X }
else else
{ {
$all_fields = array_merge($dbfields['primary'], $dbfields['update']); $all_fields = array_merge($dbfields['primary'], $dbfields['update']);
@ -326,7 +326,7 @@ CREATE TABLE '.$temporary_tablename.'
pwg_query($query); pwg_query($query);
mass_inserts($temporary_tablename, $all_fields, $datas); mass_inserts($temporary_tablename, $all_fields, $datas);
if ( $flags & MASS_UPDATES_SKIP_EMPTY ) if ( $flags & MASS_UPDATES_SKIP_EMPTY )
$func_set = create_function('$s, $t', 'return "$s = IFNULL(t2.$s, '.$tablename.'.$s)";'); $func_set = create_function('$s', 'return "$s = NULLIF(t2.$s, '.$tablename.'.$s)";');
else else
$func_set = create_function('$s', 'return "$s = t2.$s";'); $func_set = create_function('$s', 'return "$s = t2.$s";');
@ -343,7 +343,7 @@ FROM '.$temporary_tablename.' AS t2
implode( implode(
"\n AND ", "\n AND ",
array_map( array_map(
create_function('$s, $t', 'return "'.$tablename.'.$s = t2.$s";'), create_function('$s', 'return "'.$tablename.'.$s = t2.$s";'),
$dbfields['primary'] $dbfields['primary']
) )
); );
@ -585,7 +585,7 @@ function pwg_db_get_weekday($date)
} }
// my_error returns (or send to standard output) the message concerning the // my_error returns (or send to standard output) the message concerning the
// error occured for the last mysql query. // error occured for the last pgsql query.
function my_error($header, $die) function my_error($header, $die)
{ {
$error = '[pgsql error]'.pg_last_error()."\n"; $error = '[pgsql error]'.pg_last_error()."\n";

View file

@ -290,26 +290,40 @@ SELECT ';
$row = pwg_db_fetch_assoc(pwg_query($query)); $row = pwg_db_fetch_assoc(pwg_query($query));
// retrieve additional user data // retrieve user info
$query = ' $query = '
SELECT SELECT
COUNT(1) AS counter,
ui.*, ui.*,
uc.*, uc.*,
t.name AS theme_name t.name AS theme_name
FROM '.USER_INFOS_TABLE.' AS ui FROM '.USER_INFOS_TABLE.' AS ui
LEFT JOIN '.USER_CACHE_TABLE.' AS uc ON ui.user_id = uc.user_id LEFT JOIN '.USER_CACHE_TABLE.' AS uc ON ui.user_id = uc.user_id
LEFT JOIN '.THEMES_TABLE.' AS t ON t.id = ui.theme LEFT JOIN '.THEMES_TABLE.' AS t ON t.id = ui.theme
WHERE ui.user_id = \''.$user_id.'\' WHERE ui.user_id = '.$user_id.'
GROUP BY ui.user_id
;'; ;';
$result = pwg_query($query); $result = pwg_query($query);
$user_infos_row = pwg_db_fetch_assoc($result); $user_infos_row = pwg_db_fetch_assoc($result);
if (!isset($user_infos_row['counter']) or 0 == $user_infos_row['counter']) {
create_user_infos($user_id); // retrieve additional user data ?
if ($conf['external_authentification'])
{
$query = '
SELECT
COUNT(1) AS counter,
FROM '.USER_INFOS_TABLE.' AS ui
LEFT JOIN '.USER_CACHE_TABLE.' AS uc ON ui.user_id = uc.user_id
LEFT JOIN '.THEMES_TABLE.' AS t ON t.id = ui.theme
WHERE ui.user_id = '.$user_id.'
GROUP BY ui.user_id
;';
if (pwg_db_fetch_row(pwg_query($query))!=1)
{
create_user_infos($user_id);
$result = pwg_query($query); $result = pwg_query($user_info_query);
$user_infos_row = pwg_db_fetch_assoc($result); $user_infos_row = pwg_db_fetch_assoc($result);
}
} }
// then merge basic + additional user data // then merge basic + additional user data