Source for file PEAR.php
Documentation is available at PEAR.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @version $Id: 954e0cd735c096e7e12724dad5572e9c83a63024 $
* @author Masaki Fujimoto <fujimoto@php.net>
* @XXX stay public because of B.C.
* @protected object DB DBオブジェクト
/** @protected array トランザクション管理スタック */
/** @protected object Ethna_Logger ログオブジェクト */
/** @protected object Ethna_AppSQL SQLオブジェクト */
/** @protected string DBタイプ(mysql, pgsql...) */
/** @protected string DSN */
/** @protected array DSN (DB::parseDSN()の返り値) */
/** @protected bool 持続接続フラグ */
* Ethna_DB_PEARクラスのコンストラクタ
* @param object Ethna_Controller $controller コントローラオブジェクト
* @param bool $persistent 持続接続設定
public function __construct($controller, $dsn, $persistent)
$this->logger =
$controller->getLogger();
$this->sql =
$controller->getSQL();
$this->dsninfo =
DB::parseDSN($dsn);
* @return mixed 0:正常終了 Ethna_Error:エラー
if (DB::isError($this->db)) {
$this->db->getUserInfo());
$error->addUserInfo($this->db);
* @return bool true:正常 false:エラー
* @return mixed 0:正常終了 Ethna_Error:エラー
$r =
$this->query('BEGIN;');
* @return mixed 0:正常終了 Ethna_Error:エラー
// ロールバック時はスタック数に関わらずトランザクションをクリアする
$r =
$this->query('ROLLBACK;');
* @return mixed 0:正常終了 Ethna_Error:エラー
$r =
$this->query('COMMIT;');
* @param string $table テーブル名
* @return mixed array: PEAR::DBに準じたメタデータ Ethna_Error::エラー
$def =
$this->db->tableInfo($table);
$def[$k] =
array_map('strtolower', $def[$k]);
'int', 'integer', '^int\(?[0-9]\+', '^serial', '[a-z]+int$',
'bit', 'bool', 'boolean',
foreach ($type_map as $convert_to =>
$regex) {
$def[$k]['type'] =
$convert_to;
$def[$k]['flags'] =
explode(' ', $def[$k]['flags']);
// auto_increment があれば sequence
if (in_array('auto_increment', $def[$k]['flags'])) {
$def[$k]['flags'][] =
'sequence';
foreach ($def[$k]['flags'] as $f) {
if (strpos($f, 'nextval') !==
false) {
$def[$k]['flags'][] =
'sequence';
// integer, primary key ならば auto_increment を追加
if ($def[$k]['type'] ==
'int'
&&
in_array('primary_key', $def[$k]['flags'])) {
$def[$k]['flags'][] =
'sequence';
// {{{ Ethna_AppObject連携のための実装
* @param string $query SQL文
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
public function query($query)
return $this->_query($query);
public function getNextId($table_name, $field_name)
} else if ($this->type ==
'pgsql') {
$seq_name =
sprintf('%s_%s', $table_name, $field_name);
$ret =
$this->db->nextId($seq_name);
* @return mixed int:直近のINSERTにより生成されたID null:未サポート
} else if ($this->type ==
'mysql') {
} else if ($this->type ==
'sqlite') {
return sqlite_last_insert_rowid($this->db->connection);
* DB_Result::fetchRow()の結果を整形して返す
public function fetchRow($res, $fetchmode =
DB_FETCHMODE_DEFAULT, $rownum =
null)
$row =
$res->fetchRow($fetchmode, $rownum);
if ($this->type ===
'sqlite') {
// "table"."column" -> column
foreach ($row as $k =>
$v) {
if (($f =
strstr($k, '.')) !==
false) {
if ($k{0} ===
'"' &&
$k{strlen($k)-
1} ===
'"') {
return $this->db->affectedRows();
* @param mixed $identifier array or string
$ret =
'`' .
$identifier .
'`';
$ret =
'"' .
$identifier .
'"';
// {{{ Ethna_DB_PEAR独自の実装
* @param string $sqlid SQL-ID(+引数)
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
$query =
$this->sql->get($sqlid, $args);
return $this->_query($query);
* @param string $sqlid SQL-ID
public function sql($sqlid)
$query =
$this->sql->get($sqlid, $args);
* @param mixed ロック対象テーブル名
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
public function lock($tables)
return $this->query("LOCK TABLES $sql");
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
return $this->query("UNLOCK TABLES");
* @param string $query SQL文
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
$this->logger->log(LOG_DEBUG, "$query");
if ($r->getCode() ==
DB_ERROR_ALREADY_EXISTS) {
$error =
Ethna::raiseNotice('Unique Constraint Error SQL[%s]',
$this->db->errorNative(),
$this->db->errorNative(),
Documentation generated on Fri, 11 Nov 2011 03:58:47 +0900 by phpDocumentor 1.4.3