- smarty_function_select¤Ë$empty°ú¿ô¤òÄɲÃ
- mb_*¤ÎÊÑ´¹¸µ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ò¡¢EUC-JP¸ÇÄ꤫¤éÆâÉô¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤ËÊѹ¹
- Ethna_Backend::begin(), Ethna_Backend::commit(), Ethna_Backend::rollback()¤òÇÑ»ß
+- Ethna_Controller::getDB()¤òEthna_Controller::getDBType()¤ËÊѹ¹
+- Ethna_DB¥¯¥é¥¹¤òÃê¾Ý¥¯¥é¥¹(°·¤¤)¤È¤·¤Æ¿·¤¿¤ËEthna_DB¥¯¥é¥¹¤ò¼ÂÁõ¤·¤¿Ethna_DB_PEAR¥¯¥é¥¹¤òÄɲÃ
*** bug fixes
include_once(ETHNA_BASE . '/class/Ethna_Controller.php');
include_once(ETHNA_BASE . '/class/Ethna_ClassFactory.php');
include_once(ETHNA_BASE . '/class/Ethna_DB.php');
+include_once(ETHNA_BASE . '/class/DB/Ethna_DB_PEAR.php');
include_once(ETHNA_BASE . '/class/Ethna_Filter.php');
include_once(ETHNA_BASE . '/class/Ethna_I18N.php');
include_once(ETHNA_BASE . '/class/Ethna_LogWriter.php');
--- /dev/null
+<?php
+// vim: foldmethod=marker
+/**
+ * Ethna_DB_PEAR.php
+ *
+ * @author Masaki Fujimoto <fujimoto@php.net>
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @package Ethna
+ * @version $Id$
+ */
+
+// {{{ Ethna_DB_PEAR
+/**
+ * Ethna_DB¥¯¥é¥¹¤Î¼ÂÁõ(PEARÈÇ)
+ *
+ * @author Masaki Fujimoto <fujimoto@php.net>
+ * @access public
+ * @package Ethna
+ */
+class Ethna_DB_PEAR
+{
+ /**#@+
+ * @access private
+ */
+
+ /** @var object DB PEAR DB¥ª¥Ö¥¸¥§¥¯¥È */
+ var $db;
+
+ /** @var array ¥È¥é¥ó¥¶¥¯¥·¥ç¥ó´ÉÍý¥¹¥¿¥Ã¥¯ */
+ var $transaction = array();
+
+
+ /** @var object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È */
+ var $logger;
+
+ /** @var object Ethna_AppSQL SQL¥ª¥Ö¥¸¥§¥¯¥È */
+ var $sql;
+
+ /** @var string DB¥¿¥¤¥×(mysql, pgsql...) */
+ var $type;
+
+ /** @var string DSN */
+ var $dsn;
+
+ /** @var bool »ý³Àܳ¥Õ¥é¥° */
+ var $persistent;
+
+ /**#@-*/
+
+
+ // {{{ Ethna_DB¥¯¥é¥¹¤Î¼ÂÁõ
+ /**
+ * Ethna_DB_PEAR¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
+ *
+ * @access public
+ * @param object Ethna_Controller &$controller ¥³¥ó¥È¥í¡¼¥é¥ª¥Ö¥¸¥§¥¯¥È
+ * @param string $dsn DSN
+ * @param bool $persistent »ý³ÀܳÀßÄê
+ */
+ function Ethna_DB_PEAR(&$controller, $dsn, $persistent)
+ {
+ $this->dsn = $dsn;
+ $this->persistent = $persistent;
+ $this->db = null;
+ $this->logger =& $controller->getLogger();
+ $this->sql =& $controller->getSQL();
+
+ $dsninfo = DB::parseDSN($dsn);
+ $this->type = $dsninfo['phptype'];
+ }
+
+ /**
+ * DB¤ËÀܳ¤¹¤ë
+ *
+ * @access public
+ * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
+ */
+ function connect()
+ {
+ $this->db =& DB::connect($this->dsn, $this->persistent);
+ if (DB::isError($this->db)) {
+ $error = Ethna::raiseError('DBÀܳ¥¨¥é¡¼: %s', E_DB_CONNECT, $this->db->getUserInfo());
+ $error->addUserInfo($this->db);
+ $this->db = null;
+ return $error;
+ }
+
+ return 0;
+ }
+
+ /**
+ * DBÀܳ¤òÀÚÃǤ¹¤ë
+ *
+ * @access public
+ */
+ function disconnect()
+ {
+ if (is_null($this->db)) {
+ return;
+ }
+ $this->db->disconnect();
+ }
+
+ /**
+ * DBÀܳ¾õÂÖ¤òÊÖ¤¹
+ *
+ * @access public
+ * @return bool true:Àµ¾ï false:¥¨¥é¡¼
+ */
+ function isValid()
+ {
+ if (is_null($this->db)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * DB¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò³«»Ï¤¹¤ë
+ *
+ * @access public
+ * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
+ */
+ function begin()
+ {
+ if (count($this->transaction) > 0) {
+ $this->transaction[] = true;
+ return 0;
+ }
+
+ $r = $this->query('BEGIN;');
+ if (Ethna::isError($r)) {
+ return $r;
+ }
+ $this->transaction[] = true;
+
+ return 0;
+ }
+
+ /**
+ * DB¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤òÃæÃǤ¹¤ë
+ *
+ * @access public
+ * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
+ */
+ function rollback()
+ {
+ if (count($this->transaction) == 0) {
+ return 0;
+ }
+
+ // ¥í¡¼¥ë¥Ð¥Ã¥¯»þ¤Ï¥¹¥¿¥Ã¥¯¿ô¤Ë´Ø¤ï¤é¤º¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò¥¯¥ê¥¢¤¹¤ë
+ $r = $this->query('ROLLBACK;');
+ if (Ethna::isError($r)) {
+ return $r;
+ }
+ $this->transaction = array();
+
+ return 0;
+ }
+
+ /**
+ * DB¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò½ªÎ»¤¹¤ë
+ *
+ * @access public
+ * @return mixed 0:Àµ¾ï½ªÎ» Ethna_Error:¥¨¥é¡¼
+ */
+ function commit()
+ {
+ if (count($this->transaction) == 0) {
+ return 0;
+ } else if (count($this->transaction) > 1) {
+ array_pop($this->transaction);
+ return 0;
+ }
+
+ $r = $this->query('COMMIT;');
+ if (Ethna::isError($r)) {
+ return $r;
+ }
+ array_pop($this->transaction);
+
+ return 0;
+ }
+ // }}}
+
+ // {{{ Ethna_AppObjectÏ¢·È¤Î¤¿¤á¤Î¼ÂÁõ
+ /**
+ * DB¥¿¥¤¥×¤òÊÖ¤¹
+ *
+ * @access public
+ * @return string DB¥¿¥¤¥×
+ */
+ function getType()
+ {
+ return $this->type;
+ }
+
+ /**
+ * ¥¯¥¨¥ê¤òȯ¹Ô¤¹¤ë
+ *
+ * @access public
+ * @param string $query SQLʸ
+ * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
+ */
+ function &query($query)
+ {
+ return $this->_query($query);
+ }
+
+ /**
+ * ľ¶á¤ÎINSERT¤Ë¤è¤ëID¤ò¼èÆÀ¤¹¤ë
+ *
+ * ÀܳÃæ¤ÎDB¤¬mysql¤Ê¤émysql_insert_id()¤ÎÃͤòÊÖ¤¹
+ *
+ * @access public
+ * @return mixed int:ľ¶á¤ÎINSERT¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿ID null:̤¥µ¥Ý¡¼¥È
+ */
+ function getInsertId()
+ {
+ if ($this->isValid() == false) {
+ return null;
+ } else if ($this->type == 'mysql') {
+ return mysql_insert_id($this->db->connection);
+ }
+
+ return null;
+ }
+
+ /**
+ * ľ¶á¤Î¥¯¥¨¥ê¤Ë¤è¤ë¹¹¿·¹Ô¿ô¤ò¼èÆÀ¤¹¤ë
+ *
+ * @access public
+ * @return int ¹¹¿·¹Ô¿ô
+ */
+ function affectedRows()
+ {
+ return $this->db->affectedRows();
+ }
+ // }}}
+
+ // {{{ Ethna_DB_PEARÆȼ«¤Î¼ÂÁõ
+ /**
+ * SQLʸ»ØÄꥯ¥¨¥ê¤òȯ¹Ô¤¹¤ë
+ *
+ * @access public
+ * @param string $sqlid SQL-ID(+°ú¿ô)
+ * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
+ */
+ function &sqlquery($sqlid)
+ {
+ $args = func_get_args();
+ array_shift($args);
+ $query = $this->sql->get($sqlid, $args);
+
+ return $this->_query($query);
+ }
+
+ /**
+ * SQLʸ¤ò¼èÆÀ¤¹¤ë
+ *
+ * @access public
+ * @param string $sqlid SQL-ID
+ * @return string SQLʸ
+ */
+ function sql($sqlid)
+ {
+ $args = func_get_args();
+ array_shift($args);
+ $query = $this->sql->get($sqlid, $args);
+
+ return $query;
+ }
+
+ /**
+ * ¥Æ¡¼¥Ö¥ë¤ò¥í¥Ã¥¯¤¹¤ë
+ *
+ * @access public
+ * @param mixed ¥í¥Ã¥¯Âоݥơ¼¥Ö¥ë̾
+ * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
+ */
+ function lock($tables)
+ {
+ $this->message = null;
+
+ $sql = "";
+ foreach (to_array($tables) as $table) {
+ if ($sql != "") {
+ $sql .= ", ";
+ }
+ $sql .= "$table WRITE";
+ }
+
+ return $this->query("LOCK TABLES $sql");
+ }
+
+ /**
+ * ¥Æ¡¼¥Ö¥ë¤Î¥í¥Ã¥¯¤ò²òÊü¤¹¤ë
+ *
+ * @access public
+ * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
+ */
+ function unlock()
+ {
+ $this->message = null;
+ return $this->query("UNLOCK TABLES");
+ }
+
+ /**
+ * ¥¯¥¨¥ê¤òȯ¹Ô¤¹¤ë
+ *
+ * @access private
+ * @param string $query SQLʸ
+ * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
+ */
+ function &_query($query)
+ {
+ $this->logger->log(LOG_DEBUG, "$query");
+ $r =& $this->db->query($query);
+ if (DB::isError($r)) {
+ if ($r->getCode() == DB_ERROR_ALREADY_EXISTS) {
+ $error = Ethna::raiseNotice('¥æ¥Ë¡¼¥¯À©Ì󥨥顼 SQL[%s]', E_DB_DUPENT, $query, $this->db->errorNative(), $r->getUserInfo());
+ } else {
+ $error = Ethna::raiseError('¥¯¥¨¥ê¥¨¥é¡¼ SQL[%s] CODE[%d] MESSAGE[%s]', E_DB_QUERY, $query, $this->db->errorNative(), $r->getUserInfo());
+ }
+ return $error;
+ }
+ return $r;
+ }
+ // }}}
+}
+// }}}
+?>
$this->af =& $this->action_form;
$this->session =& $backend->getSession();
- $db_list = $backend->getDBlist();
+ $db_list = $backend->getDBList();
if (Ethna::isError($db_list) == false) {
foreach ($db_list as $elt) {
$varname = $elt['varname'];
$this->af =& $this->action_form;
$this->session =& $backend->getSession();
- $db_list = $backend->getDBlist();
+ $db_list = $backend->getDBList();
if (Ethna::isError($db_list) == false) {
foreach ($db_list as $elt) {
$varname = $elt['varname'];
$class_factory =& $this->controller->getClassFactory();
$db_class_name = $class_factory->getObjectName('db');
+
+ // BC: Ethna_DB -> Ethna_DB_PEAR
+ if ($db_class_name == 'Ethna_DB') {
+ $db_class_name = 'Ethna_DB_PEAR';
+ }
+
$this->db[$key] =& new $db_class_name($this->controller, $dsn, $dsn_persistent);
$r = $this->db[$key]->connect();
if (Ethna::isError($r)) {
* @return mixed array:Ethna_DB¥ª¥Ö¥¸¥§¥¯¥È¤Î°ìÍ÷ Ethan_Error:(¤¤¤º¤ì¤«°ì¤Ä°Ê¾å¤ÎÀܳ¤Ç)¥¨¥é¡¼
* @todo respect access controlls
*/
- function getDBlist()
+ function getDBList()
{
$r = array();
foreach ($this->controller->db as $key => $value) {
}
/**
- * »ØÄꤵ¤ì¤¿DB¼ïÊ̤ËÂбþ¤¹¤ëDB¥ª¥Ö¥¸¥§¥¯¥È¤ò³ÊǼ¤·¤¿¥á¥ó¥ÐÊÑ¿ô¤ò¼èÆÀ¤¹¤ë
+ * »ØÄꤵ¤ì¤¿DB¼ïÊ̤ËÂбþ¤¹¤ë(Åö³ºDB¥ª¥Ö¥¸¥§¥¯¥È¤ò³ÊǼ¤¹¤ë¤¿¤á¤Î)¥á¥ó¥ÐÊÑ¿ô̾¤ò¼èÆÀ¤¹¤ë
*
* @access private
* @param string $type DB¼ïÊÌ
*/
function &_getDB($type = "")
{
- $r = $this->controller->getDB($type);
+ $r = $this->controller->getDBType($type);
if (is_null($r)) {
return Ethna::raiseError(E_DB_INVALIDTYPE, "̤ÄêµÁ¤ÎDB¼ïÊÌ[%s]", $type);
}
* DBÀßÄê¤òÊÖ¤¹
*
* @access public
- * @param string $key DB¥¿¥¤¥×("r", ...)
+ * @param string $key DB¥¡¼("r", ...)
* @return string $key¤ËÂбþ¤¹¤ëDB¼ïÊÌÄêµÁ(ÀßÄ̵꤬¤¤¾ì¹ç¤Ïnull)
*/
- function getDB($key)
+ function getDBType($key)
{
if (isset($this->db[$key]) == false) {
return null;
// {{{ Ethna_DB
/**
- * DB¥¯¥é¥¹
+ * EthnaÍÑDBÃê¾Ý¥¯¥é¥¹
+ *
+ * Ethna¤Î¥Õ¥ì¡¼¥à¥ï¡¼¥¯¤ÇDB¥ª¥Ö¥¸¥§¥¯¥È¤ò°·¤¦¤¿¤á¤ÎÃê¾Ý¥¯¥é¥¹
+ * (¤Î¤Ä¤â¤ê...¤¢¤¡¤¹¤Ð¤é¤·¤PHP 4)
*
* @author Masaki Fujimoto <fujimoto@php.net>
* @access public
* @access private
*/
- /** @var object DB PEAR DB¥ª¥Ö¥¸¥§¥¯¥È */
+ /** @var object DB DB¥ª¥Ö¥¸¥§¥¯¥È */
var $db;
- /** @var object Ethna_Logger ¥í¥°¥ª¥Ö¥¸¥§¥¯¥È */
- var $logger;
-
- /** @var object Ethna_AppSQL SQL¥ª¥Ö¥¸¥§¥¯¥È */
- var $sql;
-
- /** @var string DB¥¿¥¤¥×(mysql, pgsql...) */
- var $type;
-
- /** @var string DSN */
- var $dsn;
-
- /** @var bool »ý³Àܳ¥Õ¥é¥° */
- var $persistent;
-
/** @var array ¥È¥é¥ó¥¶¥¯¥·¥ç¥ó´ÉÍý¥¹¥¿¥Ã¥¯ */
var $transaction = array();
* @access public
* @param object Ethna_Controller &$controller ¥³¥ó¥È¥í¡¼¥é¥ª¥Ö¥¸¥§¥¯¥È
* @param string $dsn DSN
- * @param bool $persistent »ý³ÀܳÀßÄê
+ * @param bool $persistent »ý³ÀܳÀßÄê
*/
function Ethna_DB(&$controller, $dsn, $persistent)
{
- $this->dsn = $dsn;
- $this->persistent = $persistent;
- $this->db = null;
- $this->logger =& $controller->getLogger();
- $this->sql =& $controller->getSQL();
-
- $dsninfo = DB::parseDSN($dsn);
- $this->type = $dsninfo['phptype'];
}
/**
*/
function connect()
{
- $this->db =& DB::connect($this->dsn, $this->persistent);
- if (DB::isError($this->db)) {
- $error = Ethna::raiseError('DBÀܳ¥¨¥é¡¼: %s', E_DB_CONNECT, $this->db->getUserInfo());
- $error->addUserInfo($this->db);
- $this->db = null;
- return $error;
- }
-
- return 0;
}
/**
*/
function disconnect()
{
- if (is_null($this->db)) {
- return;
- }
- $this->db->disconnect();
}
/**
* DBÀܳ¾õÂÖ¤òÊÖ¤¹
*
* @access public
- * @return bool true:Àµ¾ï false:¥¨¥é¡¼
+ * @return bool true:Àµ¾ï(ÀܳºÑ¤ß) false:¥¨¥é¡¼/̤Àܳ
*/
function isValid()
{
- if (is_null($this->db)) {
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * DB¥¿¥¤¥×¤òÊÖ¤¹
- *
- * @access public
- * @return string DB¥¿¥¤¥×
- */
- function getType()
- {
- return $this->type;
- }
-
- /**
- * ¥¯¥¨¥ê¤òȯ¹Ô¤¹¤ë
- *
- * @access public
- * @param string $query SQLʸ
- * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
- */
- function &query($query)
- {
- return $this->_query($query);
- }
-
- /**
- * SQLʸ»ØÄꥯ¥¨¥ê¤òȯ¹Ô¤¹¤ë
- *
- * @access public
- * @param string $sqlid SQL-ID(+°ú¿ô)
- * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
- */
- function &sqlquery($sqlid)
- {
- $args = func_get_args();
- array_shift($args);
- $query = $this->sql->get($sqlid, $args);
-
- return $this->_query($query);
- }
-
- /**
- * SQLʸ¤ò¼èÆÀ¤¹¤ë
- *
- * @access public
- * @param string $sqlid SQL-ID
- * @return string SQLʸ
- */
- function sql($sqlid)
- {
- $args = func_get_args();
- array_shift($args);
- $query = $this->sql->get($sqlid, $args);
-
- return $query;
- }
-
- /**
- * ľ¶á¤ÎINSERT¤Ë¤è¤ëID¤ò¼èÆÀ¤¹¤ë
- *
- * ÀܳÃæ¤ÎDB¤¬mysql¤Ê¤émysql_insert_id()¤ÎÃͤòÊÖ¤¹
- *
- * @access public
- * @return mixed int:ľ¶á¤ÎINSERT¤Ë¤è¤êÀ¸À®¤µ¤ì¤¿ID null:̤¥µ¥Ý¡¼¥È
- */
- function getInsertId()
- {
- if ($this->isValid() == false) {
- return null;
- } else if ($this->type == 'mysql') {
- return mysql_insert_id($this->db->connection);
- }
-
- return null;
- }
-
- /**
- * ľ¶á¤Î¥¯¥¨¥ê¤Ë¤è¤ë¹¹¿·¹Ô¿ô¤ò¼èÆÀ¤¹¤ë
- *
- * @access public
- * @return int ¹¹¿·¹Ô¿ô
- */
- function affectedRows()
- {
- return $this->db->affectedRows();
- }
-
- /**
- * ¥Æ¡¼¥Ö¥ë¤ò¥í¥Ã¥¯¤¹¤ë
- *
- * @access public
- * @param mixed ¥í¥Ã¥¯Âоݥơ¼¥Ö¥ë̾
- * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
- */
- function lock($tables)
- {
- $this->message = null;
-
- $sql = "";
- foreach (to_array($tables) as $table) {
- if ($sql != "") {
- $sql .= ", ";
- }
- $sql .= "$table WRITE";
- }
-
- return $this->query("LOCK TABLES $sql");
- }
-
- /**
- * ¥Æ¡¼¥Ö¥ë¤Î¥í¥Ã¥¯¤ò²òÊü¤¹¤ë
- *
- * @access public
- * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
- */
- function unlock()
- {
- $this->message = null;
- return $this->query("UNLOCK TABLES");
}
/**
*/
function begin()
{
- if (count($this->transaction) > 0) {
- $this->transaction[] = true;
- return 0;
- }
-
- $r = $this->query('BEGIN;');
- if (Ethna::isError($r)) {
- return $r;
- }
- $this->transaction[] = true;
-
- return 0;
}
/**
*/
function rollback()
{
- if (count($this->transaction) == 0) {
- return 0;
- }
-
- // ¥í¡¼¥ë¥Ð¥Ã¥¯»þ¤Ï¥¹¥¿¥Ã¥¯¿ô¤Ë´Ø¤ï¤é¤º¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò¥¯¥ê¥¢¤¹¤ë
- $r = $this->query('ROLLBACK;');
- if (Ethna::isError($r)) {
- return $r;
- }
- $this->transaction = array();
-
- return 0;
}
/**
*/
function commit()
{
- if (count($this->transaction) == 0) {
- return 0;
- } else if (count($this->transaction) > 1) {
- array_pop($this->transaction);
- return 0;
- }
-
- $r = $this->query('COMMIT;');
- if (Ethna::isError($r)) {
- return $r;
- }
- array_pop($this->transaction);
-
- return 0;
- }
-
- /**
- * ¥¯¥¨¥ê¤òȯ¹Ô¤¹¤ë
- *
- * @access private
- * @param string $query SQLʸ
- * @return mixed DB_Result:·ë²Ì¥ª¥Ö¥¸¥§¥¯¥È Ethna_Error:¥¨¥é¡¼
- */
- function &_query($query)
- {
- $this->logger->log(LOG_DEBUG, "$query");
- $r =& $this->db->query($query);
- if (DB::isError($r)) {
- if ($r->getCode() == DB_ERROR_ALREADY_EXISTS) {
- $error = Ethna::raiseNotice('¥æ¥Ë¡¼¥¯À©Ì󥨥顼 SQL[%s]', E_DB_DUPENT, $query, $this->db->errorNative(), $r->getUserInfo());
- } else {
- $error = Ethna::raiseError('¥¯¥¨¥ê¥¨¥é¡¼ SQL[%s] CODE[%d] MESSAGE[%s]', E_DB_QUERY, $query, $this->db->errorNative(), $r->getUserInfo());
- }
- return $error;
- }
- return $r;
}
}
// }}}