ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Ticket #3210: db_admin.pgsql-analysis-sqlfix.patch

File db_admin.pgsql-analysis-sqlfix.patch, 7.8 KB (added by tietew, 12 years ago)
  • webapp/modules/admin/lib/db_admin.php

     
    10911091function p_access_analysis_day_access_analysis_day($ym, $ktai_flag)
    10921092{
    10931093    if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1094         $sql = "SELECT substr(r_datetime,1,10) as ymd , count(*) as count" .
     1094        $sql = "SELECT to_char(r_datetime, 'YYYY-MM-DD') as ymd , count(*) as count" .
    10951095            " FROM c_access_log " .
    1096             " where substr(r_datetime,1,7) = ?" .
     1096            " where to_char(r_datetime, 'YYYY-MM') = ?" .
    10971097            " and ktai_flag = ? " .
    10981098            " group by ymd";
    10991099    } else {
     
    11551155    $params = array(intval($ktai_flag));
    11561156    if ($month_flag) {
    11571157        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1158             $sql .= " and substr(r_datetime,1,7) = ? ";
     1158            $sql .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    11591159        } else {
    11601160            $sql .= " and left(r_datetime, 7) = ? ";
    11611161        }
     
    11631163        array_push($params,substr($ymd,0,7));
    11641164    } else {
    11651165        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1166             $sql .= " and substr(r_datetime,1,10) = ? ";
     1166            $sql .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    11671167        } else {
    11681168            $sql .= " and left(r_datetime,10) = ? ";
    11691169        }
     
    12591259    $params = array(intval($ktai_flag));
    12601260    if ($month_flag) {
    12611261        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1262             $sql .= " and substr(r_datetime,1,7) = ? ";
     1262            $sql .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    12631263        } else {
    12641264            $sql .= " and left(r_datetime, 7) = ? ";
    12651265        }
    12661266        array_push($params,substr($ymd,0,7));
    12671267    } else {
    12681268        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1269             $sql .= " and substr(r_datetime,1,10) = ? ";
     1269            $sql .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    12701270        } else {
    12711271            $sql .= " and left(r_datetime,10) = ? ";
    12721272        }
     
    12981298    $params = array(intval($ktai_flag));
    12991299    if ($month_flag) {
    13001300        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1301             $sql .= " and substr(r_datetime,1,7) = ? ";
     1301            $sql .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    13021302        } else {
    13031303            $sql .= " and left(r_datetime, 7) = ? ";
    13041304        }
    13051305        array_push($params,substr($ymd,0,7));
    13061306    } else {
    13071307        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1308             $sql .= " and substr(r_datetime,1,10) = ? ";
     1308            $sql .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    13091309        } else {
    13101310            $sql .= " and left(r_datetime,10) = ? ";
    13111311        }
     
    13571357    $params = array(intval($ktai_flag));
    13581358    if ($month_flag) {
    13591359        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1360             $where .= " and substr(r_datetime,1, 7) = ? ";
     1360            $where .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    13611361        } else {
    13621362            $where .= " and left(r_datetime, 7) = ? ";
    13631363        }
    13641364        array_push($params,substr($ymd,0,7));
    13651365    } else {
    13661366        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1367             $where .= " and substr(r_datetime,1,10) = ? ";
     1367            $where .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    13681368        } else {
    13691369            $where .= " and left(r_datetime,10) = ? ";
    13701370        }
     
    14401440    $params = array(intval($ktai_flag));
    14411441    if ($month_flag) {
    14421442        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1443             $sql .= " and substr(r_datetime,1,7) = ? ";
     1443            $sql .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    14441444        } else {
    14451445            $sql .= " and left(r_datetime, 7) = ? ";
    14461446        }
    14471447        array_push($params,substr($ymd,0,7));
    14481448    } else {
    14491449        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1450             $sql .= " and substr(r_datetime,1,10) = ? ";
     1450            $sql .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    14511451        } else {
    14521452            $sql .= " and left(r_datetime,10) = ? ";
    14531453        }
     
    14801480    $params = array(intval($ktai_flag));
    14811481    if ($month_flag) {
    14821482        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1483             $sql .= " and substr(r_datetime,1,7) = ? ";
     1483            $sql .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    14841484        } else {
    14851485            $sql .= " and left(r_datetime, 7) = ? ";
    14861486        }
    14871487        array_push($params,substr($ymd,0,7));
    14881488    } else {
    14891489        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1490             $sql .= " and substr(r_datetime,1,10) = ? ";
     1490            $sql .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    14911491        } else {
    14921492            $sql .= " and left(r_datetime,10) = ? ";
    14931493        }
     
    15361536    $params = array(intval($ktai_flag));
    15371537    if ($month_flag) {
    15381538        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1539             $where .= " and substr(r_datetime,1,7) = ? ";
     1539            $where .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    15401540        } else {
    15411541            $where .= " and left(r_datetime, 7) = ? ";
    15421542        }
    15431543        array_push($params,substr($ymd,0,7));
    15441544    } else {
    15451545        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1546             $where .= " and substr(r_datetime,1,10) = ? ";
     1546            $where .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    15471547        } else {
    15481548            $where .= " and left(r_datetime,10) = ? ";
    15491549        }
     
    16141614    $params = array(intval($ktai_flag));
    16151615    if ($month_flag) {
    16161616        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1617             $where .= " and substr(r_datetime,1,7) = ? ";
     1617            $where .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    16181618        } else {
    16191619            $where .= " and left(r_datetime, 7) = ? ";
    16201620        }
    16211621        array_push($params,substr($ymd,0,7));
    16221622    } else {
    16231623        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1624             $where .= " and substr(r_datetime,1,10) = ? ";
     1624            $where .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    16251625        } else {
    16261626            $where .= " and left(r_datetime,10) = ? ";
    16271627        }
     
    16551655    $params = array(intval($ktai_flag));
    16561656    if ($month_flag) {
    16571657        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1658             $where .= " and substr(r_datetime,1,7) = ? ";
     1658            $where .= " and to_char(r_datetime, 'YYYY-MM') = ? ";
    16591659        } else {
    16601660            $where .= " and left(r_datetime, 7) = ? ";
    16611661        }
    16621662        array_push($params,substr($ymd,0,7));
    16631663    } else {
    16641664        if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    1665             $where .= " and substr(r_datetime,1,10) = ? ";
     1665            $where .= " and to_char(r_datetime, 'YYYY-MM-DD') = ? ";
    16661666        } else {
    16671667            $where .= " and left(r_datetime,10) = ? ";
    16681668        }
     
    18411841
    18421842    if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] == 'pgsql') {
    18431843        $sql = "SELECT ((date_part('year', now()) - birth_year)- " .
    1844             "cast(substring(CURRENT_DATE,'.....$')<(to_char(birth_month, '00') || '-' || to_char(birth_day, '00')) as int)) " .
     1844            "cast(to_char(CURRENT_DATE, 'MMDD')<(to_char(birth_month, '00') || to_char(birth_day, '00')) as int)) " .
    18451845            "AS age FROM c_member WHERE birth_year <> 0;";
    18461846    } else {
    18471847        $today = getdate();