Source for file Ethna_DB_PEAR.php
Documentation is available at Ethna_DB_PEAR.php
// vim: foldmethod=marker
* @author Masaki Fujimoto <fujimoto@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @author Masaki Fujimoto <fujimoto@php.net>
/** @var object DB PEAR DBオブジェクト */
/** @var array トランザクション管理スタック */
var $transaction =
array();
/** @var object Ethna_Logger ログオブジェクト */
/** @var object Ethna_AppSQL SQLオブジェクト */
/** @var string DBタイプ(mysql, pgsql...) */
/** @var array DSN (DB::parseDSN()の返り値) */
* Ethna_DB_PEARクラスのコンストラクタ
* @param object Ethna_Controller &$controller コントローラオブジェクト
* @param bool $persistent 持続接続設定
parent::Ethna_DB($controller, $dsn, $persistent);
$this->logger =
& $controller->getLogger();
$this->sql =
& $controller->getSQL();
$this->dsninfo =
DB::parseDSN($dsn);
$this->dsninfo['new_link'] =
true;
$this->type =
$this->dsninfo['phptype'];
* @return mixed 0:正常終了 Ethna_Error:エラー
$this->db =
& DB::connect($this->dsninfo, $this->persistent);
if (DB::isError($this->db)) {
$this->db->getUserInfo());
$error->addUserInfo($this->db);
* @return bool true:正常 false:エラー
* @return mixed 0:正常終了 Ethna_Error:エラー
if (count($this->transaction) >
0) {
$this->transaction[] =
true;
$r =
$this->query('BEGIN;');
$this->transaction[] =
true;
* @return mixed 0:正常終了 Ethna_Error:エラー
if (count($this->transaction) ==
0) {
// ロールバック時はスタック数に関わらずトランザクションをクリアする
$r =
$this->query('ROLLBACK;');
$this->transaction =
array();
* @return mixed 0:正常終了 Ethna_Error:エラー
if (count($this->transaction) ==
0) {
} else if (count($this->transaction) >
1) {
$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:エラー
return $this->_query($query);
} 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()の結果を整形して返す
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
$query =
$this->sql->get($sqlid, $args);
* @param mixed ロック対象テーブル名
* @return mixed DB_Result:結果オブジェクト Ethna_Error:エラー
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");
$r =
& $this->db->query($query);
if ($r->getCode() ==
DB_ERROR_ALREADY_EXISTS) {
$this->db->errorNative(),
$this->db->errorNative(),
Documentation generated on Fri, 11 Nov 2011 03:59:40 +0900 by phpDocumentor 1.4.3