source:
tmp/version-2_5-test/patches/ADOdb_SC_DbConn.patch
@
18609
Revision 18609, 7.5 KB checked in by kajiwara, 13 years ago (diff) |
---|
-
data/class/SC_DbConn.php
22 22 */ 23 23 24 24 $current_dir = realpath(dirname(__FILE__)); 25 require_once($current_dir . "/../module/DB.php"); 25 require_once($current_dir . "/../module/adodb/adodb.inc.php"); 26 define('ADODB_ERROR_HANDLER_TYPE', E_USER_ERROR); 27 define('ADODB_ERROR_LOG_TYPE',3); 28 define('ADODB_ERROR_LOG_DEST', DATA_PATH . "logs/error.log"); 29 require_once($current_dir . "/../module/adodb/adodb-errorhandler.inc.php"); 30 require_once($current_dir . "/../module/adodb/adodb-errorpear.inc.php"); 26 31 27 $objDbConn = ""; 28 32 /** 33 * FIXME インストーラ要修正 34 */ 29 35 class SC_DbConn { 30 36 31 37 var $conn; 32 38 var $result; 33 var $includePath;34 39 var $dsn; 35 40 var $err_disp = true; 36 41 var $dbFactory; … … 38 43 39 44 // コンストラクタ 40 45 function SC_DbConn($dsn = "", $err_disp = true, $new = false){ 41 global $objDbConn;42 46 43 // Debugモード指定 44 $options['debug'] = PEAR_DB_DEBUG; 45 // 持続的接続オプション 46 $options['persistent'] = PEAR_DB_PERSISTENT; 47 48 // 既に接続されていないか、新規接続要望の場合は接続する。 49 if(!isset($objDbConn->connection) || $new) { 50 if($dsn != "") { 51 $objDbConn = DB::connect($dsn, $options); 52 $this->dsn = $dsn; 47 if (empty($dsn)) { 48 if (defined('DEFAULT_DSN')) { 49 $dsn = DEFAULT_DSN; 53 50 } else { 54 if(defined('DEFAULT_DSN')) { 55 $objDbConn = DB::connect(DEFAULT_DSN, $options); 56 $this->dsn = DEFAULT_DSN; 57 } else { 58 return; 59 } 51 return; 60 52 } 53 // 接続オプションのために "?" をつける 54 $this->dsn = $dsn . "?"; 55 } 56 57 if (!empty($this->dsn)) { 58 // 持続的接続モード指定 59 if (PEAR_DB_PERSISTENT) { 60 $this->dsn = $this->dsn . "&persist"; 61 61 } 62 63 if (DB_TYPE == 'mysql') {64 $ objDbConn->query('SET NAMES utf8');62 // Debug モード指定 63 if(PEAR_DB_DEBUG > 0) { 64 $this->dsn = $this->dsn . "&debug"; 65 65 } 66 67 $this->conn = $objDbConn; 66 // 常に新規接続 67 if ($new) { 68 $this->dsn = $this->dsn . "&new"; 69 } 70 } 71 72 $this->conn =& ADONewConnection($this->dsn); 73 $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); 74 75 if (DB_TYPE == 'mysql') { 76 $this->conn->Execute('SET NAMES utf8'); 77 } 78 68 79 $this->err_disp = $err_disp; 69 80 $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); 70 81 } … … 75 86 if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 76 87 77 88 if ( $arr ) { 78 $result = $this->conn-> query($n, $arr);89 $result = $this->conn->Execute($n, $arr); 79 90 } else { 80 $result = $this->conn-> query($n);91 $result = $this->conn->Execute($n); 81 92 } 82 93 83 if ($this->conn-> isError($result)&& !$ignore_err){84 $this->send_err_mail($result, $n);94 if ($this->conn->ErrorNo() < 0 && !$ignore_err){ 95 return ADODB_Pear_Error(); 85 96 } 86 97 87 98 $this->result = $result; … … 99 110 } else { 100 111 $result = $this->conn->getOne($n); 101 112 } 102 if ($this->conn-> isError($result)){103 $this->send_err_mail($result ,$n);113 if ($this->conn->ErrorNo() < 0) { 114 return ADODB_Pear_Error(); 104 115 } 116 105 117 $this->result = $result; 106 118 107 119 return $this->result; … … 122 134 123 135 $result = $this->conn->getRow($sql, $arrVal ,$fetchmode); 124 136 125 if ($this->conn-> isError($result)){126 $this->send_err_mail($result ,$sql);137 if ($this->conn->ErrorNo() < 0) { 138 return ADODB_Pear_Error(); 127 139 } 140 128 141 $this->result = $result; 129 142 return $this->result; 130 143 } … … 135 148 if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 136 149 137 150 if ($arr) { 138 $result = $this->conn-> getCol($n, $col, $arr);151 $result = $this->conn->GetCol($n, $arr); 139 152 } else { 140 $result = $this->conn-> getCol($n, $col);153 $result = $this->conn->GetCol($n); 141 154 } 142 if ($this->conn->isError($result)) { 143 $this->send_err_mail($result, $n); 155 156 if ($this->conn->ErrorNo() < 0) { 157 return ADODB_Pear_Error(); 144 158 } 159 145 160 $this->result = $result; 146 161 return $this->result; 147 162 } … … 160 175 } 161 176 return 0; 162 177 } 163 164 178 if ( $arr ){ 165 $result = $this->conn-> getAll($n, $arr, DB_FETCHMODE_ASSOC);179 $result = $this->conn->GetAll($n, $arr); 166 180 } else { 167 $result = $this->conn-> getAll($n, DB_FETCHMODE_ASSOC);181 $result = $this->conn->GetAll($n); 168 182 } 169 183 170 if ($this->conn-> isError($result)){171 $this->send_err_mail($result, $n);184 if ($this->conn->ErrorNo() < 0) { 185 return ADODB_Pear_Error(); 172 186 } 187 173 188 $this->result = $result; 174 189 175 190 return $this->result; … … 178 193 function autoExecute($table_name, $fields_values, $sql_where = null){ 179 194 180 195 if ( $sql_where ) { 181 $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where);196 $result = $this->conn->autoExecute( $table_name, $fields_values, 'UPDATE', $sql_where); 182 197 } else { 183 $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT);198 $result = $this->conn->autoExecute( $table_name, $fields_values, 'INSERT'); 184 199 } 185 200 186 if ($this->conn-> isError($result)){187 $this->send_err_mail($result, $n);201 if ($this->conn->ErrorNo() < 0) { 202 return ADODB_Pear_Error(); 188 203 } 189 $this->result = $result; 190 return $this->result;204 205 return 1; 191 206 } 192 207 193 208 /** 209 * XXX バックエンドが ADOdb の場合は動作しません. 210 * 211 * @deprecated 本体で未使用のため非推奨 212 */ 194 213 function prepare($n){ 195 214 global $sql; 196 215 $sql = $n; … … 199 218 return $this->result; 200 219 } 201 220 221 /** 222 * XXX バックエンドが ADOdb の場合は動作しません. 223 * 224 * @deprecated 本体で未使用のため非推奨 225 */ 202 226 function execute($n, $obj){ 203 227 global $sql; 204 228 $sql = $n; … … 207 231 return $this->result; 208 232 } 209 233 234 /** 235 * XXX バックエンドが ADOdb の場合は動作しません. 236 * 237 * @deprecated 本体で未使用のため非推奨 238 */ 210 239 function reset(){ 211 240 $this->conn->disconnect(); 212 241 } … … 221 250 $objPage->pearResult = $pearResult; 222 251 GC_Utils_Ex::gfPrintLog($objPage->sfGetErrMsg()); 223 252 $objPage->process(); 224 225 exit(); 253 exit; 226 254 } 227 255 228 256 /** 229 257 * 直前に実行されたSQL文を取得する. 230 258 * 259 * XXX バックエンドが ADOdb の場合は動作しません. 260 * 261 * @deprecated PEAR_DB_DEBUG = 1 で代用して下さい. 231 262 * @param boolean $disp trueの場合、画面出力を行う. 232 263 * @return string SQL文 233 264 */
Note: See TracBrowser
for help on using the repository browser.