From 2e59a1accddedabb6b465ca2865cbfbb1ba476c1 Mon Sep 17 00:00:00 2001 From: zero Date: Thu, 12 Apr 2007 04:45:05 +0000 Subject: [PATCH] git-svn-id: http://xe-core.googlecode.com/svn/trunk@1109 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/db/DB.class.php | 57 ++++++++++++++------ classes/db/DBCubrid.class.php | 2 +- classes/db/DBMysql.class.php | 78 ++++++++++++---------------- classes/db/DBMysqli.class.php | 2 +- classes/db/DBSqlite2.class.php | 2 +- classes/db/DBSqlite3_pdo.class.php | 2 +- classes/xml/XmlQueryParser.class.php | 2 +- 7 files changed, 80 insertions(+), 65 deletions(-) diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index df7749ab7..40144094d 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -15,10 +15,7 @@ class DB { - /** - * @brief 조건문에서 조건을 등호로 표시하는 변수 - **/ - var $cond_operation = array( + var $cond_operation = array( ///< 조건문에서 조건을 등호로 표시하는 변수 'equal' => '=', 'more' => '>=', 'excess' => '>', @@ -43,7 +40,7 @@ var $supported_list = array(); ///< 지원하는 DB의 종류, classes/DB/DB***.class.php 를 이용하여 동적으로 작성됨 - var $cache_file = './files/cache/queries/'; + var $cache_file = './files/cache/queries/'; ///< query cache파일의 위치 /** * @brief DB를 상속받는 특정 db type의 instance를 생성 후 return @@ -110,14 +107,6 @@ return in_array($db_type, $supported_list); } - /** - * @brief 에러발생시 에러 메세지를 남기고 debug 모드일때는 GLOBALS 변수에 에러 로깅 - **/ - function setError($errno, $errstr) { - $this->errno = $errno; - $this->errstr = $errstr; - } - /** * @brief 접속되었는지 return **/ @@ -125,11 +114,45 @@ return $this->is_connected?true:false; } + /** + * @brief 로그 남김 + **/ + function actStart($query) { + if(!__DEBUG__) return; + $this->setError(0,'success'); + $this->query = $query; + $this->act_start = getMicroTime(); + } + + function actFinish() { + if(!__DEBUG__) return; + $this->act_finish = getMicroTime(); + $elapsed_time = $this->act_finish - $this->act_start; + $GLOBALS['__db_elapsed_time__'] += $elapsed_time; + + $str = sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time); + + if($this->isError()) { + $str .= sprintf("\t Query Failed : %d\n\t\t\t %s\n", $this->errno, $this->errstr); + } else { + $str .= "\t Query Success\n"; + } + $GLOBALS['__db_queries__'] .= $str; + } + + /** + * @brief 에러발생시 에러 메세지를 남기고 debug 모드일때는 GLOBALS 변수에 에러 로깅 + **/ + function setError($errno = 0, $errstr = 'success') { + $this->errno = $errno; + $this->errstr = $errstr; + } + /** * @brief 오류가 발생하였는지 return **/ function isError() { - return $error===0?true:false; + return $this->errno===0?false:true; } /** @@ -205,8 +228,9 @@ /** * @brief $val을 $filter_type으로 검사 + * XmlQueryParser에서 사용하도록 함 **/ - function _checkFilter($key, $val, $filter_type) { + function checkFilter($key, $val, $filter_type) { global $lang; switch($filter_type) { @@ -237,6 +261,8 @@ /** * @brief 이름, 값, operation, type으로 값을 변경 + * like, like_prefix의 경우 value자체가 변경됨 + * type == number가 아니면 addQuotes()를 하고 ' ' 로 묶음 **/ function getConditionValue($name, $value, $operation, $type) { if($type == 'number') return (int)$value; @@ -256,6 +282,7 @@ /** * @brief 이름, 값, operation으로 조건절 작성 + * 조건절을 완성하기 위해 세부 조건절 마다 정리를 해서 return **/ function getConditionPart($name, $value, $operation) { switch($operation) { diff --git a/classes/db/DBCubrid.class.php b/classes/db/DBCubrid.class.php index 1331985e9..9dcd65b10 100644 --- a/classes/db/DBCubrid.class.php +++ b/classes/db/DBCubrid.class.php @@ -16,7 +16,7 @@ var $password = NULL; ///< password var $database = NULL; ///< database var $port = 33000; ///< db server port - var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) + var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) /** * @brief mysql에서 사용될 column type diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index 0a6ac4bd7..2a9108317 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -10,11 +10,14 @@ class DBMysql extends DB { + /** + * @brief Mysql DB에 접속하기 위한 정보 + **/ var $hostname = '127.0.0.1'; ///< hostname var $userid = NULL; ///< user id var $password = NULL; ///< password var $database = NULL; ///< database - var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) + var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) /** * @brief mysql에서 사용될 column type @@ -106,49 +109,6 @@ return $string; } - /** - * @brief : 쿼리문의 실행 및 결과의 fetch 처리 - * - * query : query문 실행하고 result return\n - * fetch : reutrn 된 값이 없으면 NULL\n - * rows이면 array object\n - * row이면 object\n - * return\n - **/ - function _query($query) { - if(!$this->isConnected()) return; - - $this->query = $query; - - if(__DEBUG__) $query_start = getMicroTime(); - - $this->setError(0,'success'); - - $result = @mysql_query($query, $this->fd); - - if(__DEBUG__) { - $query_end = getMicroTime(); - $elapsed_time = $query_end - $query_start; - $GLOBALS['__db_elapsed_time__'] += $elapsed_time; - } - - if(mysql_error()) { - $this->setError(mysql_errno(), mysql_error()); - - if(__DEBUG__) { - $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr); - } - - return; - } - - if(__DEBUG__) { - $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time); - } - - return $result; - } - /** * @brief 트랜잭션 시작 **/ @@ -167,11 +127,39 @@ function commit() { } + /** + * @brief : 쿼리문의 실행 및 결과의 fetch 처리 + * + * query : query문 실행하고 result return\n + * fetch : reutrn 된 값이 없으면 NULL\n + * rows이면 array object\n + * row이면 object\n + * return\n + **/ + function _query($query) { + if(!$this->isConnected()) return; + + // 쿼리 시작을 알림 + $this->actStart($query); + + // 쿼리 문 실행 + $result = @mysql_query($query, $this->fd); + + // 오류 체크 + if(mysql_error($this->fd)) $this->setError(mysql_errno($this->fd), mysql_error($this->fd)); + + // 쿼리 실행 종료를 알림 + $this->actFinish(); + + // 결과 리턴 + return $result; + } + /** * @brief 결과를 fetch **/ function _fetch($result) { - if($this->isError() || !$result) return; + if(!$this->isConnected() || $this->isError() || !$result) return; while($tmp = mysql_fetch_object($result)) { $output[] = $tmp; } diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php index 2b74f8d88..be7d41b39 100644 --- a/classes/db/DBMysqli.class.php +++ b/classes/db/DBMysqli.class.php @@ -16,7 +16,7 @@ var $userid = NULL; ///< user id var $password = NULL; ///< password var $database = NULL; ///< database - var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) + var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) /** * @brief mysql에서 사용될 column type diff --git a/classes/db/DBSqlite2.class.php b/classes/db/DBSqlite2.class.php index 6505d36db..612d806d7 100644 --- a/classes/db/DBSqlite2.class.php +++ b/classes/db/DBSqlite2.class.php @@ -11,7 +11,7 @@ class DBSqlite2 extends DB { var $database = NULL; ///< database - var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) + var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) /** * @brief sqlite 에서 사용될 column type diff --git a/classes/db/DBSqlite3_pdo.class.php b/classes/db/DBSqlite3_pdo.class.php index e3cb5f86c..e758aecc7 100644 --- a/classes/db/DBSqlite3_pdo.class.php +++ b/classes/db/DBSqlite3_pdo.class.php @@ -14,7 +14,7 @@ var $bind_vars = array(); var $database = NULL; ///< database - var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) + var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) /** * @brief sqlite3 에서 사용될 column type diff --git a/classes/xml/XmlQueryParser.class.php b/classes/xml/XmlQueryParser.class.php index 28a4424ac..cd88d7ff7 100644 --- a/classes/xml/XmlQueryParser.class.php +++ b/classes/xml/XmlQueryParser.class.php @@ -259,7 +259,7 @@ if(count($filter_list)) { foreach($filter_list as $key => $val) { if(!$notnull_list[$key]) continue; - $pre_buff .= sprintf('unset($_output); $_output = $this->_checkFilter("%s",$args->%s,"%s"); if(!$_output->toBool()) return $_output;%s',$val->var,$val->var,$val->filter,"\n"); + $pre_buff .= sprintf('unset($_output); $_output = $this->checkFilter("%s",$args->%s,"%s"); if(!$_output->toBool()) return $_output;%s',$val->var,$val->var,$val->filter,"\n"); } }