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 | class SC_DB_DBFactory_PGSQL extends SC_DB_DBFactory { |
---|
40 | |
---|
41 | /** |
---|
42 | * DBのバージョンを取得する. |
---|
43 | * |
---|
44 | * @param string $dsn データソース名 |
---|
45 | * @return string データベースのバージョン |
---|
46 | */ |
---|
47 | function sfGetDBVersion($dsn = "") { |
---|
48 | $objQuery = new SC_Query($this->getDSN($dsn), true, true); |
---|
49 | list($db_type) = split(":", $dsn); |
---|
50 | $val = $objQuery->getOne("select version()"); |
---|
51 | $arrLine = split(" " , $val); |
---|
52 | return $arrLine[0] . " " . $arrLine[1]; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * MySQL 用の SQL 文に変更する. |
---|
57 | * |
---|
58 | * DB_TYPE が PostgreSQL の場合は何もしない |
---|
59 | * |
---|
60 | * @access private |
---|
61 | * @param string $sql SQL 文 |
---|
62 | * @return string MySQL 用に置換した SQL 文 |
---|
63 | */ |
---|
64 | function sfChangeMySQL($sql){ |
---|
65 | return $sql; |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * テーブルの存在チェックを行う SQL 文を返す. |
---|
70 | * |
---|
71 | * @return string テーブルの存在チェックを行う SQL 文 |
---|
72 | */ |
---|
73 | function getTableExistsSql() { |
---|
74 | return " SELECT relname " |
---|
75 | . " FROM pg_class " |
---|
76 | . " WHERE (relkind = 'r' OR relkind = 'v') " |
---|
77 | . " AND relname = ? " |
---|
78 | . "GROUP BY relname"; |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * インデックスの検索結果を配列で返す. |
---|
83 | * |
---|
84 | * @param string $index_name インデックス名 |
---|
85 | * @param string $table_name テーブル名(PostgreSQL では使用しない) |
---|
86 | * @return array インデックスの検索結果の配列 |
---|
87 | */ |
---|
88 | function getTableIndex($index_name, $table_name = "") { |
---|
89 | $objQuery = new SC_Query("", true, true); |
---|
90 | return $objQuery->getAll("SELECT relname FROM pg_class WHERE relname = ?", |
---|
91 | array($index_name)); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * インデックスを作成する. |
---|
96 | * |
---|
97 | * @param string $index_name インデックス名 |
---|
98 | * @param string $table_name テーブル名 |
---|
99 | * @param string $col_name カラム名 |
---|
100 | * @param integer $length 作成するインデックスのバイト長 |
---|
101 | * @return void |
---|
102 | */ |
---|
103 | function createTableIndex($index_name, $table_name, $col_name, $length = 0) { |
---|
104 | $objQuery = new SC_Query($dsn, true, true); |
---|
105 | $objQuery->query("CREATE INDEX ? ON ? (?)", array($index_name, $table_name, $col_name)); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * テーブルのカラム一覧を取得する. |
---|
110 | * |
---|
111 | * @param string $table_name テーブル名 |
---|
112 | * @return array テーブルのカラム一覧の配列 |
---|
113 | */ |
---|
114 | function sfGetColumnList($table_name) { |
---|
115 | $objQuery = new SC_Query(); |
---|
116 | $sql = " SELECT a.attname " |
---|
117 | . " FROM pg_class c, pg_attribute a " |
---|
118 | . " WHERE c.relname=? " |
---|
119 | . " AND c.oid=a.attrelid " |
---|
120 | . " AND a.attnum > 0 " |
---|
121 | . " AND not a.attname " |
---|
122 | . " LIKE '........pg.dropped.%........' " |
---|
123 | . "ORDER BY a.attnum"; |
---|
124 | $arrColList = $objQuery->getAll($sql, array($table_name)); |
---|
125 | $arrColList = SC_Utils_Ex::sfswaparray($arrColList); |
---|
126 | return $arrColList["attname"]; |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * テーブルを検索する. |
---|
131 | * |
---|
132 | * 引数に部分一致するテーブル名を配列で返す. |
---|
133 | * |
---|
134 | * @param string $expression 検索文字列 |
---|
135 | * @return array テーブル名の配列 |
---|
136 | */ |
---|
137 | function findTableNames($expression = "") { |
---|
138 | $objQuery = new SC_Query(); |
---|
139 | $sql = " SELECT c.relname AS name, " |
---|
140 | . " CASE c.relkind " |
---|
141 | . " WHEN 'r' THEN 'table' " |
---|
142 | . " WHEN 'v' THEN 'view' END AS type " |
---|
143 | . " FROM pg_catalog.pg_class c " |
---|
144 | . "LEFT JOIN pg_catalog.pg_namespace n " |
---|
145 | . " ON n.oid = c.relnamespace " |
---|
146 | . " WHERE c.relkind IN ('r','v') " |
---|
147 | . " AND n.nspname NOT IN ('pg_catalog', 'pg_toast') " |
---|
148 | . " AND pg_catalog.pg_table_is_visible(c.oid) " |
---|
149 | . " AND c.relname LIKE ?" |
---|
150 | . " ORDER BY 1,2;"; |
---|
151 | $arrColList = $objQuery->getAll($sql, array("%" . $expression . "%")); |
---|
152 | $arrColList = SC_Utils_Ex::sfswaparray($arrColList, false); |
---|
153 | return $arrColList[0]; |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | /** |
---|
158 | * 文字コード情報を取得する |
---|
159 | * |
---|
160 | * @return array 文字コード情報 |
---|
161 | */ |
---|
162 | function getCharSet() { |
---|
163 | // 未実装 |
---|
164 | return array(); |
---|
165 | } |
---|
166 | } |
---|
167 | ?> |
---|