Skip to content

Commit

Permalink
Bug 1766 fixed : [PostgreSQL] unkown database function UNIX_TIMESTAMP()
Browse files Browse the repository at this point in the history
Add a new function pwg_db_date_to_ts() to calculate a timestamp from a date

git-svn-id: http://piwigo.org/svn/trunk@6666 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Jul 6, 2010
1 parent a9849aa commit 804d79a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/dblayer/functions_mysql.inc.php
Expand Up @@ -636,6 +636,11 @@ function pwg_db_get_weekday($date)
return 'WEEKDAY('.$date.')';
}

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)
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_pdo-sqlite.inc.php
Expand Up @@ -550,6 +550,11 @@ 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)
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_pgsql.inc.php
Expand Up @@ -596,6 +596,11 @@ 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)
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_sqlite.inc.php
Expand Up @@ -561,6 +561,11 @@ 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)
Expand Down
2 changes: 1 addition & 1 deletion include/functions_session.inc.php
Expand Up @@ -175,7 +175,7 @@ function pwg_session_gc()
$query = '
DELETE
FROM '.SESSIONS_TABLE.'
WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(expiration) > '
WHERE '.pwg_db_date_to_ts('NOW()').' - '.pwg_db_date_to_ts('expiration').' > '
.$conf['session_length'].'
;';
pwg_query($query);
Expand Down

0 comments on commit 804d79a

Please sign in to comment.