Skip to content

Commit

Permalink
Bug 1738 fixed : hour function doesn't exists for database other than…
Browse files Browse the repository at this point in the history
… mysql.

git-svn-id: http://piwigo.org/svn/trunk@6578 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Jun 22, 2010
1 parent f4d4a3d commit 5a677f1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion admin/stats.php
Expand Up @@ -116,7 +116,7 @@ function get_summary($year = null, $month = null, $day = null)
$query = '
SELECT
date,
hour(time) AS hour,
'.pwg_db_get_hour('time').' AS hour,
MAX(id) AS max_id,
COUNT(*) AS nb_pages
FROM '.HISTORY_TABLE.'
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_mysql.inc.php
Expand Up @@ -580,6 +580,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_hour($date)
{
return 'hour('.$date.')';
}

function pwg_db_get_date_YYYYMM($date)
{
return 'DATE_FORMAT('.$date.', \'%Y%m\')';
Expand Down
12 changes: 6 additions & 6 deletions include/dblayer/functions_pdo-sqlite.inc.php
Expand Up @@ -46,7 +46,6 @@ function pwg_db_connect($host, $user, $password, $database)
}

$link->sqliteCreateFunction('now', 'pwg_now', 0);
$link->sqliteCreateFunction('hour', 'pwg_hour', 1);
$link->sqliteCreateFunction('unix_timestamp', 'pwg_unix_timestamp', 0);
$link->sqliteCreateFunction('md5', 'md5', 1);
$link->sqliteCreateFunction('if', 'pwg_if', 3);
Expand Down Expand Up @@ -502,6 +501,12 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_hour($date)
{
return 'strftime(\'%H\', '.$date.')';
}


function pwg_db_get_date_YYYYMM($date)
{
return 'strftime(\'%Y%m\','.$date.')';
Expand Down Expand Up @@ -571,11 +576,6 @@ function pwg_now()
return date('Y-m-d H:i:s');
}

function pwg_hour($datetime)
{
return strftime('%H', $datetime);
}

function pwg_unix_timestamp()
{
return time();
Expand Down
5 changes: 5 additions & 0 deletions include/dblayer/functions_pgsql.inc.php
Expand Up @@ -544,6 +544,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_hour($date)
{
return 'EXTRACT(HOUR FROM '.$date.')';
}

function pwg_db_get_date_YYYYMM($date)
{
return 'TO_CHAR('.$date.', \'YYYYMM\')';
Expand Down
11 changes: 5 additions & 6 deletions include/dblayer/functions_sqlite.inc.php
Expand Up @@ -55,7 +55,6 @@ function pwg_db_connect($host, $user, $password, $database)
}

$link->createFunction('now', 'pwg_now', 0);
$link->createFunction('hour', 'pwg_hour', 1);
$link->createFunction('unix_timestamp', 'pwg_unix_timestamp', 0);
$link->createFunction('md5', 'md5', 1);
$link->createFunction('if', 'pwg_if', 3);
Expand Down Expand Up @@ -514,6 +513,11 @@ function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
return $d;
}

function pwg_db_get_hour($date)
{
return 'strftime(\'%H\', '.$date.')';
}

function pwg_db_get_date_YYYYMM($date)
{
return 'strftime(\'%Y%m\','.$date.')';
Expand Down Expand Up @@ -583,11 +587,6 @@ function pwg_now()
return date('Y-m-d H:i:s');
}

function pwg_hour($datetime)
{
return strftime('%H', $datetime);
}

function pwg_unix_timestamp()
{
return time();
Expand Down

0 comments on commit 5a677f1

Please sign in to comment.