DB
[ class tree: DB ] [ index: DB ] [ all elements ]

Source for file SC_DB_DBFactory_PGSQL.php

Documentation is available at SC_DB_DBFactory_PGSQL.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24.  
  25. // {{{ requires
  26. require_once(CLASS_PATH "db/SC_DB_DBFactory.php");
  27.  
  28. /**
  29.  * PostgreSQL 固有の処理をするクラス.
  30.  *
  31.  * このクラスを直接インスタンス化しないこと.
  32.  * 必ず SC_DB_DBFactory クラスを経由してインスタンス化する.
  33.  * また, SC_DB_DBFactory クラスの関数を必ずオーバーライドしている必要がある.
  34.  *
  35.  * @package DB
  36.  * @author LOCKON CO.,LTD.
  37.  * @version $Id:SC_DB_DBFactory_PGSQL.php 15532 2007-08-31 14:39:46Z nanasess $
  38.  */
  39.  
  40.     /**
  41.      * DBのバージョンを取得する.
  42.      *
  43.      * @param string $dsn データソース名
  44.      * @return string データベースのバージョン
  45.      */
  46.     function sfGetDBVersion($dsn ""{
  47.         $objQuery new SC_Query($this->getDSN($dsn)truetrue);
  48.         list($db_typesplit(":"$dsn);
  49.         $val $objQuery->getOne("select version()");
  50.         $arrLine split(" " $val);
  51.         return $arrLine[0" " $arrLine[1];
  52.     }
  53.  
  54.     /**
  55.      * MySQL 用の SQL 文に変更する.
  56.      *
  57.      * DB_TYPE が PostgreSQL の場合は何もしない
  58.      *
  59.      * @access private
  60.      * @param string $sql SQL 文
  61.      * @return string MySQL 用に置換した SQL 文
  62.      */
  63.     function sfChangeMySQL($sql){
  64.         return $sql;
  65.     }
  66.  
  67.     /**
  68.      * テーブルの存在チェックを行う SQL 文を返す.
  69.      *
  70.      * @return string テーブルの存在チェックを行う SQL 文
  71.      */
  72.     function getTableExistsSql({
  73.         return "  SELECT relname "
  74.              . "    FROM pg_class "
  75.              . "   WHERE (relkind = 'r' OR relkind = 'v') "
  76.              . "     AND relname = ? "
  77.              . "GROUP BY relname";
  78.     }
  79.  
  80.     /**
  81.      * インデックスの検索結果を配列で返す.
  82.      *
  83.      * @param string $index_name インデックス名
  84.      * @param string $table_name テーブル名(PostgreSQL では使用しない)
  85.      * @return array インデックスの検索結果の配列
  86.      */
  87.     function getTableIndex($index_name$table_name ""{
  88.         $objQuery new SC_Query(""truetrue);
  89.         return $objQuery->getAll("SELECT relname FROM pg_class WHERE relname = ?",
  90.                                  array($index_name));
  91.     }
  92.  
  93.     /**
  94.      * インデックスを作成する.
  95.      *
  96.      * @param string $index_name インデックス名
  97.      * @param string $table_name テーブル名
  98.      * @param string $col_name カラム名
  99.      * @param integer $length 作成するインデックスのバイト長
  100.      * @return void 
  101.      */
  102.     function createTableIndex($index_name$table_name$col_name$length 0{
  103.         $objQuery new SC_Query($dsntruetrue);
  104.         $objQuery->query("CREATE INDEX ? ON ? (?)"array($index_name$table_name$col_name));
  105.     }
  106.  
  107.     /**
  108.      * テーブルのカラム一覧を取得する.
  109.      *
  110.      * @param string $table_name テーブル名
  111.      * @return array テーブルのカラム一覧の配列
  112.      */
  113.     function sfGetColumnList($table_name{
  114.         $objQuery new SC_Query();
  115.         $sql "  SELECT a.attname "
  116.              . "    FROM pg_class c, pg_attribute a "
  117.              . "   WHERE c.relname=? "
  118.              . "     AND c.oid=a.attrelid "
  119.              . "     AND a.attnum > 0 "
  120.              . "     AND not a.attname "
  121.              . "    LIKE '........pg.dropped.%........' "
  122.              . "ORDER BY a.attnum";
  123.         $arrColList $objQuery->getAll($sqlarray($table_name));
  124.         $arrColList SC_Utils_Ex::sfswaparray($arrColList);
  125.         return $arrColList["attname"];
  126.     }
  127.  
  128.     /**
  129.      * テーブルを検索する.
  130.      *
  131.      * 引数に部分一致するテーブル名を配列で返す.
  132.      *
  133.      * @param string $expression 検索文字列
  134.      * @return array テーブル名の配列
  135.      */
  136.     function findTableNames($expression ""{
  137.         $objQuery new SC_Query();
  138.         $sql "   SELECT c.relname AS name, "
  139.             .  "     CASE c.relkind "
  140.             .  "     WHEN 'r' THEN 'table' "
  141.             .  "     WHEN 'v' THEN 'view' END AS type "
  142.             .  "     FROM pg_catalog.pg_class c "
  143.             .  "LEFT JOIN pg_catalog.pg_namespace n "
  144.             .  "       ON n.oid = c.relnamespace "
  145.             .  "    WHERE c.relkind IN ('r','v') "
  146.             .  "      AND n.nspname NOT IN ('pg_catalog', 'pg_toast') "
  147.             .  "      AND pg_catalog.pg_table_is_visible(c.oid) "
  148.             .  "      AND c.relname LIKE ?"
  149.             .  " ORDER BY 1,2;";
  150.         $arrColList $objQuery->getAll($sqlarray("%" $expression "%"));
  151.         $arrColList SC_Utils_Ex::sfswaparray($arrColListfalse);
  152.         return $arrColList[0];
  153.     }
  154.     
  155.     
  156.     /**
  157.      * 文字コード情報を取得する
  158.      * 
  159.      * @return array 文字コード情報
  160.      */
  161.      function getCharSet({
  162.          // 未実装
  163.          return array();
  164.      }
  165. }
  166. ?>

Documentation generated on Fri, 24 Feb 2012 14:00:05 +0900 by Seasoft