english comments added

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0_english@8278 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
mosmartin 2011-04-06 16:48:06 +00:00
parent 693e215bc1
commit 4d272994dd
219 changed files with 6407 additions and 8705 deletions

View file

@ -241,7 +241,7 @@
}
/**
* @brief query xml 파일을 실행하여 결과를 return
* @brief Run the result of the query xml file
* @param[in] $query_id query id (module.queryname
* @param[in] $args arguments for query
* @return result of query

View file

@ -2,34 +2,34 @@
/**
* @class DBCubrid
* @author NHN (developers@xpressengine.com)
* @brief Cubrid DBMS이용하기 위한 class
* @brief Cubrid DBMS to use the class
* @version 0.1p1
*
* CUBRID2008 R1.3 대응하도록 수정 Prototype (prototype@cubrid.com) / 09.02.23
* 7.3 ~ 2008 R1.3 까지 테스트 완료함.
* 기본 쿼리만 사용하였기에 특화된 튜닝이 필요
* Modified to work with CUBRID2008 R1.3 verion by Prototype (prototype@cubrid.com)/09.02.23
* Test completed for CUBRID 7.3 ~ 2008 R1.3 versions.
* Only basic query used so query tunning and optimization needed
**/
class DBCubrid extends DB
{
/**
* @brief Cubrid DB에 접속하기 위한 정보
* @brief CUBRID DB connection information
**/
var $hostname = '127.0.0.1'; ///< hostname
var $userid = NULL; ///< user id
var $password = NULL; ///< password
var $database = NULL; ///< database
var $port = 33000; ///< db server port
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능)
var $cutlen = 12000; ///< 큐브리드의 최대 상수 크기(스트링이 이보다 크면 '...'+'...' 방식을 사용해야 한다
var $prefix = 'xe'; // / <prefix of XE tables(One more XE can be installed on a single DB)
var $cutlen = 12000; // /< max size of constant in CUBRID(if string is larger than this, '...'+'...' should be used)
var $comment_syntax = '/* %s */';
/**
* @brief cubrid에서 사용될 column type
* @brief column type used in CUBRID
*
* column_typeschema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* column_type should be replaced for each DBMS's type
* becasue it uses commonly defined type in the schema/query xml
**/
var $column_type = array(
'bignumber' => 'numeric(20)',
@ -61,7 +61,7 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if installable
**/
function isSupported()
{
@ -70,7 +70,7 @@
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo()
{
@ -86,17 +86,17 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect()
{
// db 정보가 없으면 무시
// ignore if db information not exists
if (!$this->hostname || !$this->userid || !$this->password || !$this->database || !$this->port) return;
// 접속시도
// attempts to connect
$this->fd = @cubrid_connect ($this->hostname, $this->port, $this->database, $this->userid, $this->password);
// 접속체크
// check connections
if (!$this->fd) {
$this->setError (-1, 'database connect fail');
return $this->is_connected = false;
@ -107,7 +107,7 @@
}
/**
* @brief DB접속 해제
* @brief DB disconnect
**/
function close()
{
@ -119,7 +119,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief handles quatation of the string variables from the query
**/
function addQuotes($string)
{
@ -147,7 +147,7 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin()
{
@ -156,7 +156,7 @@
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback()
{
@ -166,7 +166,7 @@
}
/**
* @brief 커밋
* @brief Commit
**/
function commit()
{
@ -178,24 +178,24 @@
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : executing the query and fetching the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* return\n
* query: run a query and return the result\n
* fetch: NULL if no value returned \n
* array object if rows returned \n
* object if a row returned \n
* return\n
**/
function _query($query)
{
if (!$query || !$this->isConnected ()) return;
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart ($query);
// 쿼리 문 실행
// Execute the query
$result = @cubrid_execute ($this->fd, $query);
// 오류 체크
// error check
if (cubrid_error_code ()) {
$code = cubrid_error_code ();
$msg = cubrid_error_msg ();
@ -203,15 +203,15 @@
$this->setError ($code, $msg);
}
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish ();
// 결과 리턴
// Return the result
return $result;
}
/**
* @brief 결과를 fetch
* @brief Fetch the result
**/
function _fetch($result)
{
@ -246,7 +246,7 @@
}
/**
* @brief 1 증가되는 sequence 값을 return (cubrid의 auto_increment는 sequence테이블에서만 사용)
* @brief return the sequence value incremented by 1(auto_increment column only used in the CUBRID sequence table)
**/
function getNextSequence()
{
@ -260,7 +260,7 @@
}
/**
* @brief 마이그레이션시 sequence 없을 경우 생성
* @brief return if the table already exists
**/
function _makeSequence()
{
@ -302,7 +302,7 @@
/**
* @brief 테이블 기생성 여부 return
* brief return a table if exists
**/
function isTableExists ($target_name)
{
@ -327,7 +327,7 @@
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief add a column to the table
**/
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false)
{
@ -362,7 +362,7 @@
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief drop a column from the table
**/
function dropColumn ($table_name, $column_name)
{
@ -372,7 +372,7 @@
}
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief return column information of the table
**/
function isColumnExists ($table_name, $column_name)
{
@ -388,7 +388,7 @@
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief add an index to the table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
@ -404,7 +404,7 @@
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief drop an index from the table
**/
function dropIndex ($table_name, $index_name, $is_unique = false)
{
@ -414,7 +414,7 @@
}
/**
* @brief 특정 테이블의 index 정보를 return
* @brief return index information of the table
**/
function isIndexExists ($table_name, $index_name)
{
@ -430,7 +430,7 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief creates a table by using xml file
**/
function createTableByXml ($xml_doc)
{
@ -438,19 +438,19 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief creates a table by using xml file
**/
function createTableByXmlFile ($file_name)
{
if (!file_exists ($file_name)) return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile ($file_name);
return $this->_createTable ($buff);
}
/**
* @brief schema xml을 이용하여 create class query생성
* @brief create table by using the schema xml
*
* type : number, varchar, tinytext, text, bigtext, char, date, \n
* opt : notnull, default, size\n
@ -461,14 +461,13 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
// if the table already exists exit function
if ($this->isTableExists($table_name)) return;
// 만약 테이블 이름이 sequence라면 serial 생성
// If the table name is sequence, it creates a serial
if ($table_name == 'sequence') {
$query = sprintf ('create serial "%s" start with 1 increment by 1'.
' minvalue 1 '.
@ -563,7 +562,7 @@
}
/**
* @brief 조건문 작성하여 return
* @brief return the condition
**/
function getCondition ($output)
{
@ -651,16 +650,16 @@
}
/**
* @brief insertAct 처리
* @brief handles insertAct
**/
function _executeInsertAct ($output)
{
// 테이블 정리
// tables
foreach ($output->tables as $val) {
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 컬럼 정리
// columns
foreach ($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -699,18 +698,18 @@
}
/**
* @brief updateAct 처리
* @brief handles updateAct
**/
function _executeUpdateAct ($output)
{
// 테이블 정리
// tables
foreach ($output->tables as $key => $val) {
$table_list[] = '"'.$this->prefix.$val.'" as "'.$key.'"';
}
$check_click_count = true;
// 컬럼 정리
// columns
foreach ($output->columns as $key => $val) {
if (!isset ($val['value'])) continue;
$name = $val['name'];
@ -721,10 +720,10 @@
}
for ($i = 0; $i < $key; $i++) {
/* 한문장에 같은 속성에 대한 중복 설정은 큐브리드에서는 허용치 않음 */
// not allows to define the same property repeatedly in a single query in CUBRID
if ($output->columns[$i]['name'] == $name) break;
}
if ($i < $key) continue; // 중복이 발견되면 이후의 설정은 무시
if ($i < $key) continue; // ignore the rest of properties if duplicated property found
if (strpos ($name, '.') !== false && strpos ($value, '.') !== false) {
$column_list[] = $name.' = '.$value;
@ -742,7 +741,7 @@
}
}
// 조건절 정리
// conditional clause
$condition = $this->getCondition ($output);
$check_click_count_condition = false;
@ -792,16 +791,16 @@
}
/**
* @brief deleteAct 처리
* @brief handles deleteAct
**/
function _executeDeleteAct ($output)
{
// 테이블 정리
// tables
foreach ($output->tables as $val) {
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 조건절 정리
// Conditional clauses
$condition = $this->getCondition ($output);
$query = sprintf ("delete from %s %s", implode (',',$table_list), $condition);
@ -812,14 +811,14 @@
}
/**
* @brief selectAct 처리
* @brief Handle selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* to get a specific page list easily in select statement,\n
* a method, navigation, is used
**/
function _executeSelectAct ($output)
{
// 테이블 정리
// tables
$table_list = array ();
foreach ($output->tables as $key => $val) {
$table_list[] = '"'.$this->prefix.$val.'" as "'.$key.'"';
@ -966,7 +965,7 @@
}
// list_count를 사용할 경우 적용
// apply when using list_count
if ($output->list_count['value']) {
$start_count = 0;
$list_count = $output->list_count['value'];
@ -1050,7 +1049,7 @@
}
/**
* @brief 현재 시점의 Stack trace를 보여줌.결과를 fetch
* @brief displays the current stack trace. Fetch the result
**/
function backtrace ()
{
@ -1102,9 +1101,9 @@
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief paginates when navigation info exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* it is convenient although its structure is not good .. -_-;
**/
function _getNavigationData ($table_list, $columns, $left_join, $condition, $output) {
require_once (_XE_PATH_.'classes/page/PageHandler.class.php');
@ -1129,7 +1128,7 @@
$page = $output->page['value'];
if (!$page) $page = 1;
// 전체 페이지를 구함
// total pages
if ($total_count) {
$total_page = (int) (($total_count - 1) / $list_count) + 1;
}
@ -1137,7 +1136,7 @@
$total_page = 1;
}
// 페이지 변수를 체크
// check the page variables
if ($page > $total_page) $page = $total_page;
$start_count = ($page - 1) * $list_count;

View file

@ -1,8 +1,8 @@
<?php
/**
* @class DBFriebird
* @author 김현식 (dev.hyuns@gmail.com)
* @brief Firebird DBMS이용하기 위한 class
* @class DBFirebird
* @author Kim Hyun Sik (dev.hyuns @ gmail.com)
* @brief class to use Firebird DBMS
* @version 0.3
*
* firebird handling class
@ -11,21 +11,21 @@
class DBFireBird extends DB {
/**
* @brief Firebird DB접속하기 위한 정보
* @brief connection to Firebird DB
**/
var $hostname = '127.0.0.1'; ///< hostname
var $userid = NULL; ///< user id
var $password = NULL; ///< password
var $database = NULL; ///< database
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능)
var $idx_no = 0; // 인덱스 생성시 사용할 카운터
var $prefix = 'xe'; // / <prefix of XE tables(One more XE can be installed on a single DB)
var $idx_no = 0; // counter for creating an index
var $comment_syntax = '/* %s */';
/**
* @brief firebird에서 사용될 column type
* @brief column type used in firebird
*
* column_typeschema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* column_type should be replaced for each DBMS's type
* becasue it uses commonly defined type in the schema/query xml
**/
var $column_type = array(
'bignumber' => 'BIGINT',
@ -55,7 +55,7 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if installable
**/
function isSupported() {
if(!function_exists('ibase_connect')) return false;
@ -63,7 +63,7 @@
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo() {
$db_info = Context::getDBInfo();
@ -77,16 +77,14 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect() {
// db 정보가 없으면 무시
// ignore if db information not exists
if(!$this->hostname || !$this->port || !$this->userid || !$this->password || !$this->database) return;
//if(strpos($this->hostname, ':')===false && $this->port) $this->hostname .= ':'.$this->port;
// 접속시도
// attempts to connect
$host = $this->hostname."/".$this->port.":".$this->database;
$this->fd = @ibase_connect($host, $this->userid, $this->password);
@ -94,8 +92,7 @@
$this->setError(ibase_errcode(), ibase_errmsg());
return $this->is_connected = false;
}
// Firebird 버전 확인후 2.0 이하면 오류 표시
// Error when Firebird version is lower than 2.0
if (($service = ibase_service_attach($this->hostname, $this->userid, $this->password)) != FALSE) {
// get server version and implementation strings
$server_info = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
@ -118,14 +115,13 @@
@ibase_close($this->fd);
return $this->is_connected = false;
}
// 접속체크
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
}
/**
* @brief DB접속 해제
* @brief DB disconnect
**/
function close() {
if(!$this->isConnected()) return;
@ -135,7 +131,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief handles quatation of the string variables from the query
**/
function addQuotes($string) {
// if(get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
@ -144,7 +140,7 @@
}
/**
* @brief 쿼리에서 입력되는 table, column 명에 더블쿼터를 넣어줌
* @brief put double quotes for tabls, column names in the query statement
**/
function addDoubleQuotes($string) {
if($string == "*") return $string;
@ -162,12 +158,11 @@
}
/**
* @brief 쿼리에서 입력되는 table, column 명에 더블쿼터를 넣어줌
* @brief put double quotes for tabls, column names in the query statement
**/
function autoQuotes($string){
$string = strtolower($string);
// substr 함수 일경우
// for substr function
if(strpos($string, "substr(") !== false) {
$tokken = strtok($string, "(,)");
$tokken = strtok("(,)");
@ -190,8 +185,7 @@
$as = trim($as);
$as = $this->addDoubleQuotes($as);
}
// 함수 사용시
// for functions
$tmpFunc1 = null;
$tmpFunc2 = null;
if(($no1 = strpos($string,'('))!==false && ($no2 = strpos($string, ')'))!==false) {
@ -199,8 +193,7 @@
$tmpFunc2 = substr($string, $no2, strlen($string)-$no2+1);
$string = trim(substr($string, $no1+1, $no2-$no1-1));
}
// (테이블.컬럼) 구조 일때 처리
// for (table.column) structure
preg_match("/((?i)[a-z0-9_-]+)[.]((?i)[a-z0-9_\-\*]+)/", $string, $matches);
if($matches) {
@ -225,7 +218,7 @@
}
foreach($values as $val1) {
// (테이블.컬럼) 구조 일때 처리
// for (table.column) structure
preg_match("/((?i)[a-z0-9_-]+)[.]((?i)[a-z0-9_\-\*]+)/", $val1, $matches);
if($matches) {
$isTable = false;
@ -257,7 +250,7 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin() {
if(!$this->isConnected() || $this->transaction_started) return;
@ -265,7 +258,7 @@
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback() {
if(!$this->isConnected() || !$this->transaction_started) return;
@ -274,7 +267,7 @@
}
/**
* @brief 커밋
* @brief Commits
**/
function commit() {
if(!$force && (!$this->isConnected() || !$this->transaction_started)) return;
@ -283,48 +276,43 @@
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : Run a query and fetch the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* return\n
* query: run a query and return the result\n
* fetch: NULL if no value returned \n
* array object if rows returned \n
* object if a row returned \n
* return\n
**/
function _query($query, $params=null) {
if(!$this->isConnected()) return;
if(count($params) == 0) {
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
// 쿼리 문 실행
// Execute the query statement
$result = ibase_query($this->fd, $query);
}
else {
// 쿼리 시작을 알림
// Notify to start a query execution
$log = $query."\n\t\t\t";
$log .= implode(",", $params);
$this->actStart($log);
// 쿼리 문 실행 (blob type 입력하기 위한 방법)
// Execute the query(for blob type)
$query = ibase_prepare($this->fd, $query);
$fnarr = array_merge(array($query), $params);
$result = call_user_func_array("ibase_execute", $fnarr);
}
// 오류 체크
// Error Check
if(ibase_errmsg()) $this->setError(ibase_errcode(), ibase_errmsg());
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish();
// 결과 리턴
// Return the result
return $result;
}
/**
* @brief 결과를 fetch
* @brief Fetch the result
**/
function _fetch($result, $output = null) {
if(!$this->isConnected() || $this->isError() || !$result) return;
@ -332,12 +320,11 @@
while($tmp = ibase_fetch_object($result)) {
foreach($tmp as $key => $val) {
$type = $output->column_type[$key];
// type 값이 null 일때는 $key값이 alias인 경우라 실제 column 이름을 찾아 type을 구함
// type value is null when $key is an alias. so get a type by finding actual coloumn name
if($type == null && $output->columns && count($output->columns)) {
foreach($output->columns as $cols) {
if($cols['alias'] == $key) {
// table.column 형식인지 정규식으로 검사 함
// checks if the format is table.column or a regular expression
preg_match("/\w+[.](\w+)/", $cols['name'], $matches);
if($matches) {
$type = $output->column_type[$matches[1]];
@ -356,7 +343,7 @@
ibase_blob_close($blob_hndl);
}
else if($type == "char") {
$tmp->{$key} = trim($tmp->{$key}); // DB의 character set이 UTF8일때 생기는 빈칸을 제거
$tmp->{$key} = trim($tmp->{$key}); // remove blanks generated when DB character set is UTF8
}
}
@ -368,7 +355,7 @@
}
/**
* @brief 1 증가되는 sequence값을 return (firebird의 generator 값을 증가)
* @brief return sequence value incremented by 1(increase the value of the generator in firebird)
**/
function getNextSequence() {
$gen = "GEN_".$this->prefix."sequence_ID";
@ -377,7 +364,7 @@
}
/**
* @brief 테이블 기생성 여부 return
* @brief returns if the table already exists
**/
function isTableExists($target_name) {
$query = sprintf("select rdb\$relation_name from rdb\$relations where rdb\$system_flag=0 and rdb\$relation_name = '%s%s';", $this->prefix, $target_name);
@ -392,7 +379,7 @@
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief add a column to the table
**/
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
$type = $this->column_type[$type];
@ -412,7 +399,7 @@
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief drop a column from the table
**/
function dropColumn($table_name, $column_name) {
$query = sprintf("alter table %s%s drop %s ", $this->prefix, $table_name, $column_name);
@ -422,7 +409,7 @@
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief return column information of the table
**/
function isColumnExists($table_name, $column_name) {
$query = sprintf("SELECT RDB\$FIELD_NAME as \"FIELD\" FROM RDB\$RELATION_FIELDS WHERE RDB\$RELATION_NAME = '%s%s'", $this->prefix, $table_name);
@ -446,15 +433,14 @@
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief add an index to the table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
function addIndex($table_name, $index_name, $target_columns, $is_unique = false) {
// index name 크기가 31byte로 제한으로 index name을 넣지 않음
// Firebird에서는 index name을 넣지 않으면 "RDB$10"처럼 자동으로 이름을 부여함
// table을 삭제 할 경우 인덱스도 자동으로 삭제 됨
// index name size should be limited to 31 byte. no index name assigned
// if index name omitted, Firebird automatically assign its name like "RDB $10"
// deletes indexes when deleting the table
if(!is_array($target_columns)) $target_columns = array($target_columns);
$query = sprintf('CREATE %s INDEX "" ON "%s%s" ("%s");', $is_unique?'UNIQUE':'', $this->prefix, $table_name, implode('", "',$target_columns));
@ -464,7 +450,7 @@
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief drop an index from the table
**/
function dropIndex($table_name, $index_name, $is_unique = false) {
$query = sprintf('DROP INDEX "%s" ON "%s%s"', $index_name, $this->prefix, $table_name);
@ -475,7 +461,7 @@
/**
* @brief 특정 테이블의 index 정보를 return
* @brief return index information of the table
**/
function isIndexExists($table_name, $index_name) {
$query = "SELECT\n";
@ -512,24 +498,24 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief creates a table by using xml file
**/
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
/**
* @brief xml 받아서 테이블을 생성
* @brief creates a table by using xml file
**/
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief create table by using the schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -539,8 +525,7 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;
@ -596,10 +581,9 @@
if(count($index_list)) {
foreach($index_list as $key => $val) {
// index name 크기가 31byte로 제한으로 index name을 넣지 않음
// Firebird에서는 index name을 넣지 않으면 "RDB$10"처럼 자동으로 이름을 부여함
// table을 삭제 할 경우 인덱스도 자동으로 삭제 됨
// index name size should be limited to 31 byte. no index name assigned
// if index name omitted, Firebird automatically assign its name like "RDB $10"
// deletes indexes when deleting the table
$schema = sprintf("CREATE INDEX \"\" ON \"%s\" (\"%s\");",
$table_name, implode($val, "\",\""));
$output = $this->_query($schema);
@ -613,12 +597,11 @@
$output = $this->_query($schema);
if(!$this->transaction_started) @ibase_commit($this->fd);
if(!$output) return false;
// Firebird에서 auto increment는 generator를 만들어 insert 발생시 트리거를 실행시켜
// generator의 값을 증가시키고 그값을 테이블에 넣어주는 방식을 사용함.
// 아래 트리거가 auto increment 역할을 하지만 쿼리로 트리거 등록이 되지 않아 주석처리 하였음.
// php 함수에서 generator 값을 증가시켜 주는 함수가 있어 XE에서는 굳이
// auto increment를 사용 할 필요가 없어보임.
// auto_increment in Firebird creates a generator which activates a trigger when insert occurs
// the generator increases the value of the generator and then insert to the table
// The trigger below acts like auto_increment however I commented the below because the trigger cannot be defined by a query statement
// php api has a function to increase a generator, so
// no need to use auto increment in XE
/*
$schema = 'SET TERM ^ ; ';
$schema .= sprintf('CREATE TRIGGER "%s_BI" FOR "%s" ', $table_name, $table_name);
@ -634,7 +617,7 @@
}
/**
* @brief 조건문 작성하여 return
* @brief Return conditional clause
**/
function getCondition($output) {
if(!$output->conditions) return;
@ -683,15 +666,14 @@
}
/**
* @brief insertAct 처리
* @brief Handle the insertAct
**/
function _executeInsertAct($output) {
// 테이블 정리
// tables
foreach($output->tables as $key => $val) {
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 컬럼 정리
// Columns
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -721,15 +703,14 @@
}
/**
* @brief updateAct 처리
* @brief handles updateAct
**/
function _executeUpdateAct($output) {
// 테이블 정리
// Tables
foreach($output->tables as $key => $val) {
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 컬럼 정리
// Columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -747,7 +728,7 @@
else if($output->column_type[$name]=='number' ||
$output->column_type[$name]=='bignumber' ||
$output->column_type[$name]=='float') {
// 연산식이 들어갔을 경우 컬럼명이 있는 지 체크해 더블쿼터를 넣어줌
// put double-quotes on column name if an expression is entered
preg_match("/(?i)[a-z][a-z0-9_]+/", $value, $matches);
foreach($matches as $key => $val) {
@ -764,8 +745,7 @@
$column_list[] = sprintf('"%s" = ?', $name);
}
}
// 조건절 정리
// conditional clause
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s;", implode(',',$table_list), implode(',',$column_list), $condition);
@ -775,15 +755,14 @@
}
/**
* @brief deleteAct 처리
* @brief handles deleteAct
**/
function _executeDeleteAct($output) {
// 테이블 정리
// Tables
foreach($output->tables as $key => $val) {
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s;", implode(',',$table_list), $condition);
@ -794,13 +773,13 @@
}
/**
* @brief selectAct 처리
* @brief Handle selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* In order to get a list of pages easily when selecting \n
* it supports a method as navigation
**/
function _executeSelectAct($output) {
// 테이블 정리
// Tables
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = sprintf("\"%s%s\" as \"%s\"", $this->prefix, $val, $key);
@ -839,8 +818,7 @@
$output->column_list = $column_list;
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// query added in the condition to use an index when ordering by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -852,8 +830,7 @@
}
}
}
// list_count를 사용할 경우 적용
// apply when using list_count
if($output->list_count['value']) $limit = sprintf('FIRST %d', $output->list_count['value']);
else $limit = '';
@ -910,9 +887,9 @@
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief paginates when navigation info exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* it is convenient although its structure is not good .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
@ -929,8 +906,8 @@
}
/*
// group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정
// 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다.
// modified to get the number of rows by SELECT query with group by clause
// activate the commented codes when you confirm it works correctly
//
$count_condition = strlen($query_groupby) ? sprintf('%s group by %s', $condition, $query_groupby) : $condition;
$total_count = $this->getCountCache($output->tables, $count_condition);
@ -944,8 +921,7 @@
$this->putCountCache($output->tables, $count_condition, $total_count);
}
*/
// 전체 개수를 구함
// total number of rows
$count_query = sprintf("select count(*) as \"count\" from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id . ' count(*)'):'';
$result = $this->_query($count_query);
@ -960,16 +936,13 @@
if(!$page_count) $page_count = 10;
$page = $output->page['value'];
if(!$page) $page = 1;
// 전체 페이지를 구함
// total pages
if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1;
else $total_page = 1;
// 페이지 변수를 체크
// check the page variables
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// query added in the condition to use an index when ordering by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -1025,12 +998,11 @@
while($tmp = ibase_fetch_object($result)) {
foreach($tmp as $key => $val){
$type = $output->column_type[$key];
// type 값이 null 일때는 $key값이 alias인 경우라 실제 column 이름을 찾아 type을 구함
// $key value is an alias when type value is null. get type by finding the actual column name
if($type == null && $output->columns && count($output->columns)) {
foreach($output->columns as $cols) {
if($cols['alias'] == $key) {
// table.column 형식인지 정규식으로 검사 함
// checks if the format is table.column or a regular expression
preg_match("/\w+[.](\w+)/", $cols['name'], $matches);
if($matches) {
$type = $output->column_type[$matches[1]];

View file

@ -3,26 +3,26 @@
/**
* @class DBMSSQL
* @author NHN (developers@xpressengine.com)
* @brief MSSQL driver로 수정 sol (sol@ngleader.com)
* @brief Modified to use MSSQL driver by sol (sol@ngleader.com)
* @version 0.1
**/
class DBMssql extends DB {
/**
* DB를 이용하기 위한 정보
* information to connect to DB
**/
var $conn = NULL;
var $database = NULL; ///< database
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능)
var $prefix = 'xe'; // / <prefix of XE tables(One more XE can be installed on a single DB)
var $param = array();
var $comment_syntax = '/* %s */';
/**
* @brief mssql 에서 사용될 column type
* @brief column type used in mssql
*
* column_typeschema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* column_type should be replaced for each DBMS's type
* becasue it uses commonly defined type in the schema/query xml
**/
var $column_type = array(
'bignumber' => 'bigint',
@ -52,7 +52,7 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if installable
**/
function isSupported() {
if (!extension_loaded("sqlsrv")) return false;
@ -60,7 +60,7 @@
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo() {
$db_info = Context::getDBInfo();
@ -75,10 +75,10 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect() {
// db 정보가 없으면 무시
// ignore if db information not exists
if(!$this->hostname || !$this->database) return;
//sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
@ -89,7 +89,8 @@
array( 'Database' => $this->database,'UID'=>$this->userid,'PWD'=>$this->password ));
// 접속체크
// Check connections
if($this->conn){
$this->is_connected = true;
$this->password = md5($this->password);
@ -99,7 +100,7 @@
}
/**
* @brief DB접속 해제
* @brief DB disconnect
**/
function close() {
if($this->is_connected == false) return;
@ -110,7 +111,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief handles quatation of the string variables from the query
**/
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
@ -120,7 +121,7 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin() {
if($this->is_connected == false || $this->transaction_started) return;
@ -130,7 +131,7 @@
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback() {
if($this->is_connected == false || !$this->transaction_started) return;
@ -140,7 +141,7 @@
}
/**
* @brief 커밋
* @brief Commit
**/
function commit($force = false) {
if(!$force && ($this->is_connected == false || !$this->transaction_started)) return;
@ -150,13 +151,13 @@
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : executing the query and fetching the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* return\n
* query: run a query and return the result\n
* fetch: NULL if no value returned \n
* array object if rows returned \n
* object if a row returned \n
* return\n
**/
function _query($query) {
if($this->is_connected == false || !$query) return;
@ -173,21 +174,21 @@
}
}
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
// 쿼리 문 실행
// Run the query statement
$result = false;
if(count($_param)){
$result = @sqlsrv_query($this->conn, $query, $_param);
}else{
$result = @sqlsrv_query($this->conn, $query);
}
// 오류 체크
// Error Check
if(!$result) $this->setError(print_r(sqlsrv_errors(),true));
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish();
$this->param = array();
@ -195,7 +196,7 @@
}
/**
* @brief 결과를 fetch
* @brief Fetch results
**/
function _fetch($result) {
if(!$this->isConnected() || $this->isError() || !$result) return;
@ -219,7 +220,7 @@
}
/**
* @brief 1 증가되는 sequence값을 return (mssql의 auto_increment는 sequence테이블에서만 사용)
* @brief Return sequence value incremented by 1(auto_increment is usd in the sequence table only)
**/
function getNextSequence() {
$query = sprintf("insert into %ssequence (seq) values (ident_incr('%ssequence'))", $this->prefix, $this->prefix);
@ -234,7 +235,7 @@
}
/**
* @brief 테이블 기생성 여부 return
* @brief Return if a table already exists
**/
function isTableExists($target_name) {
$query = sprintf("select name from sysobjects where name = '%s%s' and xtype='U'", $this->prefix, $this->addQuotes($target_name));
@ -246,7 +247,7 @@
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief Add a column to a table
**/
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
if($this->isColumnExists($table_name, $column_name)) return;
@ -263,7 +264,7 @@
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief Delete a column from a table
**/
function dropColumn($table_name, $column_name) {
if(!$this->isColumnExists($table_name, $column_name)) return;
@ -272,7 +273,7 @@
}
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief Return column information of a table
**/
function isColumnExists($table_name, $column_name) {
$query = sprintf("select syscolumns.name as name from syscolumns, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = syscolumns.id and syscolumns.name = '%s'", $this->prefix, $table_name, $column_name);
@ -284,7 +285,7 @@
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief Add an index to a table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
@ -297,7 +298,7 @@
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief Drop an index from a table
**/
function dropIndex($table_name, $index_name, $is_unique = false) {
if(!$this->isIndexExists($table_name, $index_name)) return;
@ -306,7 +307,7 @@
}
/**
* @brief 특정 테이블의 index 정보를 return
* @brief Return index information of a table
**/
function isIndexExists($table_name, $index_name) {
$query = sprintf("select sysindexes.name as name from sysindexes, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = sysindexes.id and sysindexes.name = '%s'", $this->prefix, $table_name, $index_name);
@ -320,24 +321,24 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief generate a query statement to create a table by using schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -347,8 +348,7 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
@ -409,7 +409,7 @@
}
/**
* @brief 조건문 작성하여 return
* @brief Return conditional clause
**/
function getCondition($output) {
if(!$output->conditions) return;
@ -525,16 +525,15 @@
}
/**
* @brief insertAct 처리
* @brief Handle the insertAct
**/
function _executeInsertAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = '['.$this->prefix.$val.']';
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -561,15 +560,16 @@
}
/**
* @brief updateAct 처리
* @brief Handle updateAct
**/
function _executeUpdateAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = '['.$this->prefix.$val.']';
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
@ -597,8 +597,7 @@
}
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s", implode(',',$table_list), implode(',',$column_list), $condition);
@ -607,15 +606,14 @@
}
/**
* @brief deleteAct 처리
* @brief Handle deleteAct
**/
function _executeDeleteAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = '['.$this->prefix.$val.']';
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
@ -624,13 +622,13 @@
}
/**
* @brief selectAct 처리
* @brief Handle selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* In order to get a list of pages easily when selecting \n
* it supports a method as navigation
**/
function _executeSelectAct($output) {
// 테이블 정리
// List tables
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = '['.$this->prefix.$val.'] as '.$key;
@ -675,8 +673,7 @@
$output->column_list = $column_list;
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -718,7 +715,7 @@
}
$query = sprintf("%s from %s %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition, $groupby_query.$orderby_query);
// list_count를 사용할 경우 적용
// Apply when using list_count
if($output->list_count['value']) $query = sprintf('select top %d %s', $output->list_count['value'], $query);
else $query = "select ".$query;
@ -741,16 +738,16 @@
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief Paging is handled if navigation information exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* It is quite convenient although its structure is not good at all .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
$column_list = $output->column_list;
// 전체 개수를 구함
// Get a total count
if(count($output->groups)){
foreach($output->groups as $k => $v ){
if(preg_match('/^substr\(/i',$v)) $output->groups[$k] = preg_replace('/^substr\(/i','substring(',$v);
@ -780,16 +777,13 @@
if(!$page_count) $page_count = 10;
$page = $output->page['value'];
if(!$page) $page = 1;
// 전체 페이지를 구함
// Get a total page
if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1;
else $total_page = 1;
// 페이지 변수를 체크
// Check Page variables
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
$conditions = $this->getConditionList($output);
if($output->order) {
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -802,7 +796,7 @@
}
}
// group by 절 추가
// Add group by clause
if(count($output->groups)){
foreach($output->groups as $k => $v ){
if(preg_match('/^substr\(/i',$v)) $output->groups[$k] = preg_replace('/^substr\(/i','substring(',$v);
@ -812,7 +806,7 @@
$group = sprintf('group by %s', implode(',',$output->groups));
}
// order 절 추가
// Add order by clause
$order_targets = array();
if($output->order) {
foreach($output->order as $key => $val) {
@ -848,7 +842,7 @@
$first_sub_columns[] = $k;
}
// 1차로 order 대상에 해당 하는 값을 가져옴
// Fetch values to sort
$param = $this->param;
$first_query = sprintf("select %s from (select top %d %s from %s %s %s %s %s) xet", implode(',',$first_columns), $start_count, implode(',',$first_sub_columns), implode(',',$table_list), implode(' ',$left_join), $condition, $group, $order);
$result = $this->_query($first_query);
@ -857,7 +851,7 @@
// 1차에서 나온 값을 이용 다시 쿼리 실행
// Re-execute a query by using fetched values
$sub_cond = array();
foreach($order_targets as $k => $v) {
$sub_cond[] = sprintf("%s %s '%s'", $k, $v=='asc'?'>':'<', $tmp->{$k});

View file

@ -2,7 +2,7 @@
/**
* @class DBMysql
* @author NHN (developers@xpressengine.com)
* @brief MySQL DBMS이용하기 위한 class
* @brief Class to use MySQL DBMS
* @version 0.1
*
* mysql handling class
@ -11,20 +11,20 @@
class DBMysql extends DB {
/**
* @brief Mysql DB에 접속하기 위한 정보
* @brief Connection information for Mysql DB
**/
var $hostname = '127.0.0.1'; ///< hostname
var $userid = NULL; ///< user id
var $password = NULL; ///< password
var $database = NULL; ///< database
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능)
var $prefix = 'xe'; // / <prefix of a tablename (One or more XEs can be installed in a single DB)
var $comment_syntax = '/* %s */';
/**
* @brief mysql에서 사용될 column type
* @brief Column type used in MySQL
*
* column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* Becasue a common column type in schema/query xml is used for colum_type,
* it should be replaced properly for each DBMS
**/
var $column_type = array(
'bignumber' => 'bigint',
@ -50,7 +50,7 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if it is installable
**/
function isSupported() {
if(!function_exists('mysql_connect')) return false;
@ -58,7 +58,7 @@
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo() {
$db_info = Context::getDBInfo();
@ -72,44 +72,39 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect() {
// db 정보가 없으면 무시
// Ignore if no DB information exists
if(!$this->hostname || !$this->userid || !$this->password || !$this->database) return;
if(strpos($this->hostname, ':')===false && $this->port) $this->hostname .= ':'.$this->port;
// 접속시도
// Attempt to connect
$this->fd = @mysql_connect($this->hostname, $this->userid, $this->password);
if(mysql_error()) {
$this->setError(mysql_errno(), mysql_error());
return;
}
// 버전 확인후 4.1 이하면 오류 표시
// Error appears if the version is lower than 4.1
if(mysql_get_server_info($this->fd)<"4.1") {
$this->setError(-1, "XE cannot be installed under the version of mysql 4.1. Current mysql version is ".mysql_get_server_info());
return;
}
// db 선택
// select db
@mysql_select_db($this->database, $this->fd);
if(mysql_error()) {
$this->setError(mysql_errno(), mysql_error());
return;
}
// 접속체크
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
// mysql의 경우 utf8임을 지정
// Set utf8 if a database is MySQL
$this->_query("set names 'utf8'");
}
/**
* @brief DB접속 해제
* @brief DB disconnection
**/
function close() {
if(!$this->isConnected()) return;
@ -117,7 +112,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief Add quotes on the string variables in a query
**/
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
@ -126,53 +121,48 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin() {
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback() {
}
/**
* @brief 커밋
* @brief Commits
**/
function commit() {
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : Run a query and fetch the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* query: run a query and return the result \n
* fetch: NULL if no value is returned \n
* array object if rows are returned \n
* object if a row is returned \n
* return\n
**/
function _query($query) {
if(!$this->isConnected()) return;
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
// 쿼리 문 실행
// Run the query statement
$result = @mysql_query($query, $this->fd);
// 오류 체크
// Error Check
if(mysql_error($this->fd)) $this->setError(mysql_errno($this->fd), mysql_error($this->fd));
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish();
// 결과 리턴
// Return result
return $result;
}
/**
* @brief 결과를 fetch
* @brief Fetch results
**/
function _fetch($result) {
if(!$this->isConnected() || $this->isError() || !$result) return;
@ -184,7 +174,7 @@
}
/**
* @brief 1 증가되는 sequence값을 return (mysql의 auto_increment는 sequence테이블에서만 사용)
* @brief Return sequence value incremented by 1(auto_increment is used in sequence table only in MySQL)
**/
function getNextSequence() {
$query = sprintf("insert into `%ssequence` (seq) values ('0')", $this->prefix);
@ -199,7 +189,7 @@
}
/**
* @brief mysql old password를 가져오는 함수 (mysql에서만 사용)
* @brief Function to obtain mysql old password(mysql only)
**/
function isValidOldPassword($password, $saved_password) {
$query = sprintf("select password('%s') as password, old_password('%s') as old_password", $this->addQuotes($password), $this->addQuotes($password));
@ -210,7 +200,7 @@
}
/**
* @brief 테이블 기생성 여부 return
* @brief Return if a table already exists
**/
function isTableExists($target_name) {
$query = sprintf("show tables like '%s%s'", $this->prefix, $this->addQuotes($target_name));
@ -221,7 +211,7 @@
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief Add a column to a table
**/
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
$type = $this->column_type[$type];
@ -237,7 +227,7 @@
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief Delete a column from a table
**/
function dropColumn($table_name, $column_name) {
$query = sprintf("alter table `%s%s` drop `%s` ", $this->prefix, $table_name, $column_name);
@ -245,7 +235,7 @@
}
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief Return column information of a table
**/
function isColumnExists($table_name, $column_name) {
$query = sprintf("show fields from `%s%s`", $this->prefix, $table_name);
@ -263,7 +253,7 @@
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief Add an index to a table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
@ -275,7 +265,7 @@
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief Drop an index from a table
**/
function dropIndex($table_name, $index_name, $is_unique = false) {
$query = sprintf("alter table `%s%s` drop index `%s`", $this->prefix, $table_name, $index_name);
@ -284,7 +274,7 @@
/**
* @brief 특정 테이블의 index 정보를 return
* @brief Return index information of a table
**/
function isIndexExists($table_name, $index_name) {
//$query = sprintf("show indexes from %s%s where key_name = '%s' ", $this->prefix, $table_name, $index_name);
@ -302,24 +292,24 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief generate a query statement to create a table by using schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -329,8 +319,7 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;
@ -386,7 +375,7 @@
}
/**
* @brief 조건문 작성하여 return
* @brief Return conditional clause
**/
function getCondition($output) {
if(!$output->conditions) return;
@ -429,15 +418,14 @@
}
/**
* @brief insertAct 처리
* @brief Handle the insertAct
**/
function _executeInsertAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = '`'.$this->prefix.$val.'`';
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -466,15 +454,14 @@
}
/**
* @brief updateAct 처리
* @brief Handle updateAct
**/
function _executeUpdateAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -487,8 +474,7 @@
$column_list[] = sprintf("`%s` = %s", $name, $value);
}
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s", implode(',',$table_list), implode(',',$column_list), $condition);
@ -497,15 +483,14 @@
}
/**
* @brief deleteAct 처리
* @brief Handle deleteAct
**/
function _executeDeleteAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = '`'.$this->prefix.$val.'`';
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
@ -514,13 +499,13 @@
}
/**
* @brief selectAct 처리
* @brief Handle selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* In order to get a list of pages easily when selecting \n
* it supports a method as navigation
**/
function _executeSelectAct($output) {
// 테이블 정리
// List tables
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
@ -584,8 +569,7 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -633,7 +617,7 @@
$query = sprintf("select %s from %s %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition, $groupby_query.$orderby_query);
// list_count를 사용할 경우 적용
// Apply when using list_count
if($output->list_count['value']) $query = sprintf('%s limit %d', $query, $output->list_count['value']);
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
@ -656,16 +640,16 @@
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief Paging is handled if navigation information exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* It is quite convenient although its structure is not good at all .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
$column_list = $output->column_list;
// 전체 개수를 구함
// Get a total count
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
$count_query = sprintf("select count(*) as count from %s %s %s", implode(', ', $table_list), implode(' ', $left_join), $count_condition);
if (count($output->groups)) $count_query = sprintf('select count(*) as count from (%s) xet', $count_query);
@ -681,16 +665,13 @@
if(!$page_count) $page_count = 10;
$page = $output->page['value'];
if(!$page) $page = 1;
// 전체 페이지를 구함
// Get a total page
if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1;
else $total_page = 1;
// 페이지 변수를 체크
// Check Page variables
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {

View file

@ -4,7 +4,7 @@
/**
* @class DBMysql_innodb
* @author NHN (developers@xpressengine.com)
* @brief MySQL DBMS이용하기 위한 class
* @brief class to use MySQL DBMS
* @version 0.1
*
* mysql innodb handling class
@ -29,7 +29,7 @@
}
/**
* @brief DB접속 해제
* @brief DB disconnection
**/
function close() {
if(!$this->isConnected()) return;
@ -38,7 +38,7 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin() {
if(!$this->isConnected() || $this->transaction_started) return;
@ -47,7 +47,7 @@
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback() {
if(!$this->isConnected() || !$this->transaction_started) return;
@ -56,7 +56,7 @@
}
/**
* @brief 커밋
* @brief Commits
**/
function commit($force = false) {
if(!$force && (!$this->isConnected() || !$this->transaction_started)) return;
@ -65,35 +65,30 @@
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : Run a query and fetch the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* query: run a query and return the result \n
* fetch: NULL if no value is returned \n
* array object if rows are returned \n
* object if a row is returned \n
* return\n
**/
function _query($query) {
if(!$this->isConnected()) return;
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
// 쿼리 문 실행
// Run the query statement
$result = @mysql_query($query, $this->fd);
// 오류 체크
// Error Check
if(mysql_error($this->fd)) $this->setError(mysql_errno($this->fd), mysql_error($this->fd));
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish();
// 결과 리턴
// Return result
return $result;
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief generate a query statement to create a table by using schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -103,8 +98,7 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;

View file

@ -3,7 +3,7 @@
/**
* @class DBMysqli
* @author NHN (developers@xpressengine.com)
* @brief MySQL DBMS를 mysqli_* 이용하기 위한 class
* @brief Class to use MySQL DBMS as mysqli_*
* @version 0.1
*
* mysql handling class
@ -21,7 +21,7 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if it is installable
**/
function isSupported() {
if(!function_exists('mysqli_connect')) return false;
@ -37,13 +37,12 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect() {
// db 정보가 없으면 무시
// Ignore if no DB information exists
if(!$this->hostname || !$this->userid || !$this->password || !$this->database) return;
// 접속시도
// Attempt to connect
if($this->port){
$this->fd = @mysqli_connect($this->hostname, $this->userid, $this->password, $this->database, $this->port);
}else{
@ -55,14 +54,13 @@
return;
}
mysqli_set_charset($this->fd,'utf8');
// 접속체크
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
}
/**
* @brief DB접속 해제
* @brief DB disconnection
**/
function close() {
if(!$this->isConnected()) return;
@ -70,7 +68,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief Add quotes on the string variables in a query
**/
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
@ -79,32 +77,29 @@
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : Run a query and fetch the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* query: run a query and return the result \n
* fetch: NULL if no value is returned \n
* array object if rows are returned \n
* object if a row is returned \n
* return\n
**/
function _query($query) {
if(!$this->isConnected()) return;
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
// 쿼리 문 실행
// Run the query statement
$result = mysqli_query($this->fd,$query);
// 오류 체크
// Error Check
$error = mysqli_error($this->fd);
if($error){
$this->setError(mysqli_errno($this->fd), $error);
}
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish();
// 결과 리턴
// Return result
return $result;
}

View file

@ -2,34 +2,34 @@
/**
* @class DBPostgreSQL
* @author ioseph (ioseph@postgresql.kr) updated by yoonjong.joh@gmail.com
* @brief MySQL DBMS를 이용하기 위한 class
* @brief Class to use PostgreSQL DBMS
* @version 0.2
*
* postgresql handling class
* 2009.02.10 update delete query를 실행할때 table 이름에 alias 사용하는 것을 없앰. 지원 안함
* order by clause를 실행할때 함수를 실행 하는 부분을 column alias로 대체.
* 2009.02.11 dropColumn() function이 추가
* 2009.02.13 addColumn() 함수 변경
* 2009.02.10 update and delete query for the table name at runtime, eliminating the alias to use. Not Supported
* when running order by clause column alias to run a function to replace parts.
* 2009.02.11 dropColumn() function added
* 2009.02.13 addColumn() function changes
**/
class DBPostgresql extends DB
{
/**
* @brief PostgreSQL DB접속하기 위한 정보
* @brief Connection information for PostgreSQL DB
**/
var $hostname = '127.0.0.1'; ///< hostname
var $userid = null; ///< user id
var $password = null; ///< password
var $database = null; ///< database
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE설치 가능)
var $prefix = 'xe'; // / <prefix of a tablename (One or more XEs can be installed in a single DB)
var $comment_syntax = '/* %s */';
/**
* @brief postgresql에서 사용될 column type
* @brief column type used in postgresql
*
* column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* Becasue a common column type in schema/query xml is used for colum_type,
* it should be replaced properly for each DBMS
**/
var $column_type = array(
'bignumber' => 'bigint',
@ -60,7 +60,7 @@ class DBPostgresql extends DB
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if it is installable
**/
function isSupported()
{
@ -70,7 +70,7 @@ class DBPostgresql extends DB
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo()
{
@ -86,40 +86,36 @@ class DBPostgresql extends DB
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect()
{
// pg용 connection string
// the connection string for PG
$conn_string = "";
// db 정보가 없으면 무시
// Ignore if no DB information exists
if (!$this->hostname || !$this->userid || !$this->database)
return;
// connection string 만들기
// Create connection string
$conn_string .= ($this->hostname) ? " host=$this->hostname" : "";
$conn_string .= ($this->userid) ? " user=$this->userid" : "";
$conn_string .= ($this->password) ? " password=$this->password" : "";
$conn_string .= ($this->database) ? " dbname=$this->database" : "";
$conn_string .= ($this->port) ? " port=$this->port" : "";
// 접속시도
// Attempt to connect
$this->fd = @pg_connect($conn_string);
if (!$this->fd || pg_connection_status($this->fd) != PGSQL_CONNECTION_OK) {
$this->setError(-1, "CONNECTION FAILURE");
return;
}
// 접속체크
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
// utf8임을 지정
// Set utf8
//$this ->_query('set client_encoding to uhc');
}
/**
* @brief DB접속 해제
* @brief DB disconnection
**/
function close()
{
@ -129,7 +125,7 @@ class DBPostgresql extends DB
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief Add quotes on the string variables in a query
**/
function addQuotes($string)
{
@ -141,7 +137,7 @@ class DBPostgresql extends DB
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin()
{
@ -152,7 +148,7 @@ class DBPostgresql extends DB
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback()
{
@ -163,7 +159,7 @@ class DBPostgresql extends DB
}
/**
* @brief 커밋
* @brief Commits
**/
function commit()
{
@ -174,12 +170,12 @@ class DBPostgresql extends DB
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : Run a query and fetch the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* query: run a query and return the result \n
* fetch: NULL if no value is returned \n
* array object if rows are returned \n
* object if a row is returned \n
* return\n
**/
function _query($query)
@ -208,16 +204,12 @@ class DBPostgresql extends DB
}
}
*/
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
$arr = array('Hello', 'World!', 'Beautiful', 'Day!');
// 쿼리 문 실행
// Run the query statement
$result = @pg_query($this->fd, $query);
// 오류 체크
// Error Check
if (!$result) {
// var_dump($l_query_array);
//var_dump($query);
@ -225,16 +217,14 @@ class DBPostgresql extends DB
//var_dump(debug_backtrace());
$this->setError(1, pg_last_error($this->fd));
}
// 쿼리 실행 종료를 알림
// Notify to complete a query execution
$this->actFinish();
// 결과 리턴
// Return result
return $result;
}
/**
* @brief 결과를 fetch
* @brief Fetch results
**/
function _fetch($result)
{
@ -249,7 +239,7 @@ class DBPostgresql extends DB
}
/**
* @brief 1 증가되는 sequence값을 return (postgresql의 auto_increment는 sequence테이블에서만 사용)
* @brief Return sequence value incremented by 1(in postgresql, auto_increment is used in the sequence table only)
**/
function getNextSequence()
{
@ -260,7 +250,7 @@ class DBPostgresql extends DB
}
/**
* @brief 테이블 기생성 여부 return
* @brief Return if a table already exists
**/
function isTableExists($target_name)
{
@ -277,7 +267,7 @@ class DBPostgresql extends DB
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief Add a column to a table
**/
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default =
NULL, $notnull = false)
@ -309,7 +299,7 @@ class DBPostgresql extends DB
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief Return column information of a table
**/
function isColumnExists($table_name, $column_name)
{
@ -329,7 +319,7 @@ class DBPostgresql extends DB
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief Add an index to a table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
@ -340,8 +330,7 @@ class DBPostgresql extends DB
if (strpos($table_name, $this->prefix) === false)
$table_name = $this->prefix . $table_name;
// index_name의 경우 앞에 table이름을 붙여줘서 중복을 피함
// Use a tablename before an index name to avoid defining the same index
$index_name = $table_name . $index_name;
$query = sprintf("create %s index %s on %s (%s);", $is_unique ? 'unique' : '', $index_name,
@ -350,7 +339,7 @@ class DBPostgresql extends DB
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief Delete a column from a table
**/
function dropColumn($table_name, $column_name)
{
@ -359,14 +348,13 @@ class DBPostgresql extends DB
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief Drop an index from a table
**/
function dropIndex($table_name, $index_name, $is_unique = false)
{
if (strpos($table_name, $this->prefix) === false)
$table_name = $this->prefix . $table_name;
// index_name의 경우 앞에 table이름을 붙여줘서 중복을 피함
// Use a tablename before an index name to avoid defining the same index
$index_name = $table_name . $index_name;
$query = sprintf("drop index %s", $index_name);
@ -375,14 +363,13 @@ class DBPostgresql extends DB
/**
* @brief 특정 테이블의 index 정보를 return
* @brief Return index information of a table
**/
function isIndexExists($table_name, $index_name)
{
if (strpos($table_name, $this->prefix) === false)
$table_name = $this->prefix . $table_name;
// index_name의 경우 앞에 table이름을 붙여줘서 중복을 피함
// Use a tablename before an index name to avoid defining the same index
$index_name = $table_name . $index_name;
//$query = sprintf("show indexes from %s%s where key_name = '%s' ", $this->prefix, $table_name, $index_name);
@ -402,7 +389,7 @@ class DBPostgresql extends DB
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXml($xml_doc)
{
@ -410,19 +397,19 @@ class DBPostgresql extends DB
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXmlFile($file_name)
{
if (!file_exists($file_name))
return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief generate a query statement to create a table by using schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -433,8 +420,7 @@ class DBPostgresql extends DB
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if ($table_name == 'sequence') {
@ -508,7 +494,7 @@ class DBPostgresql extends DB
}
/**
* @brief 조건문 작성하여 return
* @brief Return conditional clause
**/
function getCondition($output)
{
@ -564,16 +550,15 @@ class DBPostgresql extends DB
/**
* @brief insertAct 처리
* @brief Handle the insertAct
**/
function _executeInsertAct($output)
{
// 테이블 정리
// List tables
foreach ($output->tables as $key => $val) {
$table_list[] = $this->prefix . $val;
}
// 컬럼 정리
// List columns
foreach ($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -594,17 +579,16 @@ class DBPostgresql extends DB
}
/**
* @brief updateAct 처리
* @brief Handle updateAct
**/
function _executeUpdateAct($output)
{
// 테이블 정리
// List tables
foreach ($output->tables as $key => $val) {
//$table_list[] = $this->prefix.$val.' as '.$key;
$table_list[] = $this->prefix . $val;
}
// 컬럼 정리
// List columns
foreach ($output->columns as $key => $val) {
if (!isset($val['value']))
continue;
@ -621,8 +605,7 @@ class DBPostgresql extends DB
$column_list[] = sprintf("%s = %s", $name, $value);
}
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s", implode(',', $table_list), implode(',',
@ -632,16 +615,15 @@ class DBPostgresql extends DB
}
/**
* @brief deleteAct 처리
* @brief Handle deleteAct
**/
function _executeDeleteAct($output)
{
// 테이블 정리
// List tables
foreach ($output->tables as $key => $val) {
$table_list[] = $this->prefix . $val;
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s", implode(',', $table_list), $condition);
@ -650,14 +632,14 @@ class DBPostgresql extends DB
}
/**
* @brief selectAct 처리
* @brief Handle selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* In order to get a list of pages easily when selecting \n
* it supports a method as navigation
**/
function _executeSelectAct($output)
{
// 테이블 정리
// List tables
$table_list = array();
foreach ($output->tables as $key => $val) {
$table_list[] = $this->prefix . $val . ' as ' . $key;
@ -709,8 +691,7 @@ class DBPostgresql extends DB
if ($output->list_count && $output->page)
return $this->_getNavigationData($table_list, $columns, $left_join, $condition,
$output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if ($output->order) {
$conditions = $this->getConditionList($output);
if (!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -794,9 +775,9 @@ class DBPostgresql extends DB
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief Paging is handled if navigation information exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* It is quite convenient although its structure is not good at all .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output)
{
@ -804,8 +785,8 @@ class DBPostgresql extends DB
$column_list = $output->column_list;
/*
// group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정
// 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다.
// Modified to find total number of SELECT queries having group by clause
// If it works correctly, uncomment the following codes
//
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
$total_count = $this->getCountCache($output->tables, $count_condition);
@ -820,7 +801,7 @@ class DBPostgresql extends DB
}
*/
// 전체 개수를 구함
// Get a total count
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',', $table_list), implode(' ', $left_join), $condition);
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id . ' count(*)'):'';
$result = $this->_query($count_query);
@ -835,15 +816,14 @@ class DBPostgresql extends DB
if (!$page)
$page = 1;
// 전체 페이지를 구함
// Get a total page
if ($total_count) $total_page = (int)(($total_count - 1) / $list_count) + 1;
else $total_page = 1;
// 페이지 변수를 체크
// Check Page variables
if ($page > $total_page) $page = $total_page;
$start_count = ($page - 1) * $list_count;
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if ($output->order) {
$conditions = $this->getConditionList($output);
if (!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {

View file

@ -2,7 +2,7 @@
/**
* @class DBSqlite2
* @author NHN (developers@xpressengine.com)
* @brief SQLite ver 2.x 이용하기 위한 class
* @brief Class for using SQLite ver 2.x
* @version 0.1
*
* sqlite handling class (sqlite ver 2.x)
@ -11,17 +11,17 @@
class DBSqlite2 extends DB {
/**
* DB이용하기 위한 정보
* DB information
**/
var $database = NULL; ///< database
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE설치 가능)
var $prefix = 'xe'; // / <prefix of a tablename (One or more XEs can be installed in a single DB)
var $comment_syntax = '/* %s */';
/**
* @brief sqlite 에서 사용될 column type
* @brief sqlite column type used in
*
* column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* Becasue a common column type in schema/query xml is used for colum_type,
* it should be replaced properly for each DBMS
**/
var $column_type = array(
'bignumber' => 'INTEGER',
@ -51,7 +51,7 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if it is installable
**/
function isSupported() {
if(!function_exists('sqlite_open')) return false;
@ -59,7 +59,7 @@
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo() {
$db_info = Context::getDBInfo();
@ -69,27 +69,25 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect() {
// db 정보가 없으면 무시
// Ignore if no DB information exists
if(!$this->database) return;
// 데이터 베이스 파일 접속 시도
// Attempt to access the database file
$this->fd = sqlite_open($this->database, 0666, $error);
if(!file_exists($this->database) || $error) {
$this->setError(-1,$error);
$this->is_connected = false;
return;
}
// 접속체크
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
}
/**
* @brief DB접속 해제
* @brief DB disconnection
**/
function close() {
if(!$this->isConnected()) return;
@ -97,7 +95,7 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin transaction
**/
function begin() {
if(!$this->is_connected || $this->transaction_started) return;
@ -105,7 +103,7 @@
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback() {
if(!$this->is_connected || !$this->transaction_started) return;
@ -114,7 +112,7 @@
}
/**
* @brief 커밋
* @brief Commits
**/
function commit($force = false) {
if(!$force && (!$this->isConnected() || !$this->transaction_started)) return;
@ -124,7 +122,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief Add quotes on the string variables in a query
**/
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
@ -133,34 +131,30 @@
}
/**
* @brief : 쿼리문의 실행 결과의 fetch 처리
* @brief : Run a query and fetch the result
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* query: run a query and return the result \n
* fetch: NULL if no value is returned \n
* array object if rows are returned \n
* object if a row is returned \n
* return\n
**/
function _query($query) {
if(!$this->isConnected()) return;
// 쿼리 시작을 알림
// Notify to start a query execution
$this->actStart($query);
// 쿼리 문 실행
// Run the query statement
$result = @sqlite_query($query, $this->fd);
// 오류 체크
// Error Check
if(sqlite_last_error($this->fd)) $this->setError(sqlite_last_error($this->fd), sqlite_error_string(sqlite_last_error($this->fd)));
// 쿼리 실행 알림
// Notify to complete a query execution
$this->actFinish();
return $result;
}
/**
* @brief 결과를 fetch
* @brief Fetch results
**/
function _fetch($result) {
if($this->isError() || !$result) return;
@ -180,7 +174,7 @@
}
/**
* @brief 1 증가되는 sequence값을 return
* @brief Return the sequence value is incremented by 1
**/
function getNextSequence() {
$query = sprintf("insert into %ssequence (seq) values ('')", $this->prefix);
@ -195,7 +189,7 @@
}
/**
* @brief 테이블 기생성 여부 return
* @brief Return if a table already exists
**/
function isTableExists($target_name) {
$query = sprintf('pragma table_info(%s%s)', $this->prefix, $this->addQuotes($target_name));
@ -205,7 +199,7 @@
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief Add a column to a table
**/
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
$type = $this->column_type[$type];
@ -221,7 +215,7 @@
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief Delete a column from a table
**/
function dropColumn($table_name, $column_name) {
$query = sprintf("alter table %s%s drop column %s ", $this->prefix, $table_name, $column_name);
@ -229,7 +223,7 @@
}
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief Return column information of a table
**/
function isColumnExists($table_name, $column_name) {
$query = sprintf("pragma table_info(%s%s)", $this->prefix, $table_name);
@ -246,7 +240,7 @@
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief Add an index to a table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
@ -261,7 +255,7 @@
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief Drop an index from a table
**/
function dropIndex($table_name, $index_name, $is_unique = false) {
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
@ -270,7 +264,7 @@
}
/**
* @brief 특정 테이블의 index 정보를 return
* @brief Return index information of a table
**/
function isIndexExists($table_name, $index_name) {
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
@ -282,24 +276,24 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
/**
* @brief xml 받아서 테이블을 생성
* @brief Create a table by using xml file
**/
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief generate a query statement to create a table by using schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -309,8 +303,7 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;
@ -371,7 +364,7 @@
}
/**
* @brief 조건문 작성하여 return
* @brief Return conditional clause
**/
function getCondition($output) {
if(!$output->conditions) return;
@ -415,15 +408,14 @@
}
/**
* @brief insertAct 처리
* @brief Handle the insertAct
**/
function _executeInsertAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val;
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -441,18 +433,16 @@
}
/**
* @brief updateAct 처리
* @brief Handle updateAct
**/
function _executeUpdateAct($output) {
$table_count = count(array_values($output->tables));
// 대상 테이블이 1개일 경우
// If one day the destination table
if($table_count == 1) {
// 테이블 정리
// List tables
list($target_table) = array_values($output->tables);
$target_table = $this->prefix.$target_table;
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -465,27 +455,23 @@
$column_list[] = sprintf("%s = %s", $name, $value);
}
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s", $target_table, implode(',',$column_list), $condition);
// 대상 테이블이 2개일 경우 (sqlite에서 update 테이블을 1개 이상 지정 못해서 이렇게 꽁수로... 다른 방법이 있으려나..)
// trick to handle if targt table to update is more than one (sqlite doesn't support update to multi-tables)
} elseif($table_count == 2) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[$val] = $this->prefix.$key;
}
list($source_table, $target_table) = array_values($table_list);
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
foreach($table_list as $key => $val) {
$condition = eregi_replace($key.'\\.', $val.'.', $condition);
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -507,15 +493,14 @@
}
/**
* @brief deleteAct 처리
* @brief Handle deleteAct
**/
function _executeDeleteAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val;
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
@ -524,13 +509,13 @@
}
/**
* @brief selectAct 처리
* @brief Handle selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* In order to get a list of pages easily when selecting \n
* it supports a method as navigation
**/
function _executeSelectAct($output) {
// 테이블 정리
// List tables
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val.' as '.$key;
@ -573,8 +558,7 @@
$output->column_list = $column_list;
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -597,8 +581,7 @@
}
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
}
// list_count를 사용할 경우 적용
// Apply when using list_count
if($output->list_count['value']) $query = sprintf('%s limit %d', $query, $output->list_count['value']);
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
@ -620,17 +603,17 @@
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief Paging is handled if navigation information exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* It is quite convenient although its structure is not good at all .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
$column_list = $output->column_list;
/*
// group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정
// 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다.
// Modified to find total number of SELECT queries having group by clause
// If it works correctly, uncomment the following codes
//
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
$total_count = $this->getCountCache($output->tables, $count_condition);
@ -644,8 +627,7 @@
$this->putCountCache($output->tables, $count_condition, $total_count);
}
*/
// 전체 개수를 구함
// Get a total count
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id . ' count(*)'):'';
$result = $this->_query($count_query);
@ -658,16 +640,13 @@
if(!$page_count) $page_count = 10;
$page = $output->page['value'];
if(!$page) $page = 1;
// 전체 페이지를 구함
// Get a total page
if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1;
else $total_page = 1;
// 페이지 변수를 체크
// Check Page variables
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {

View file

@ -2,21 +2,21 @@
/**
* @class DBSqlite3_pdo
* @author NHN (developers@xpressengine.com)
* @brief SQLite3를 PDO로 이용하여 class
* @brief class to use SQLite3 with PDO
* @version 0.1
**/
class DBSqlite3_pdo extends DB {
/**
* DB이용하기 위한 정보
* DB information
**/
var $database = NULL; ///< database
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능)
var $prefix = 'xe'; // /< prefix of a tablename (many XEs can be installed in a single DB)
var $comment_syntax = '/* %s */';
/**
* PDO 사용시 필요한 변수들
* Variables for using PDO
**/
var $handler = NULL;
var $stmt = NULL;
@ -24,10 +24,10 @@
var $bind_vars = array();
/**
* @brief sqlite3 에서 사용될 column type
* @brief column type used in sqlite3
*
* column_typeschema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다
* column_type should be replaced for each DBMS properly
* because column_type uses a commonly defined type in schema/query xml files
**/
var $column_type = array(
'bignumber' => 'INTEGER',
@ -57,14 +57,14 @@
}
/**
* @brief 설치 가능 여부를 return
* @brief Return if installable
**/
function isSupported() {
return class_exists('PDO');
}
/**
* @brief DB정보 설정 connect/ close
* @brief DB settings and connect/close
**/
function _setDBInfo() {
$db_info = Context::getDBInfo();
@ -74,13 +74,13 @@
}
/**
* @brief DB 접속
* @brief DB Connection
**/
function _connect() {
// db 정보가 없으면 무시
// override if db information not exists
if(!$this->database) return;
// 데이터 베이스 파일 접속 시도
// Attempt to access the database file
try {
// PDO is only supported with PHP5,
// so it is allowed to use try~catch statment in this class.
@ -91,13 +91,13 @@
return;
}
// 접속체크
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
}
/**
* @brief DB접속 해제
* @brief disconnect to DB
**/
function close() {
if(!$this->is_connected) return;
@ -105,7 +105,7 @@
}
/**
* @brief 트랜잭션 시작
* @brief Begin a transaction
**/
function begin() {
if(!$this->is_connected || $this->transaction_started) return;
@ -113,7 +113,7 @@
}
/**
* @brief 롤백
* @brief Rollback
**/
function rollback() {
if(!$this->is_connected || !$this->transaction_started) return;
@ -122,7 +122,7 @@
}
/**
* @brief 커밋
* @brief Commit
**/
function commit($force = false) {
if(!$force && (!$this->is_connected || !$this->transaction_started)) return;
@ -131,7 +131,7 @@
}
/**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
* @brief Add or change quotes to the query string variables
**/
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
@ -140,12 +140,12 @@
}
/**
* @brief : 쿼리문의 prepare
* @brief : Prepare a query statement
**/
function _prepare($query) {
if(!$this->is_connected) return;
// 쿼리 시작을 알림
// notify to start a query execution
$this->actStart($query);
$this->stmt = $this->handler->prepare($query);
@ -159,7 +159,7 @@
}
/**
* @brief : stmt에 binding params
* @brief : Binding params in stmt
**/
function _bind($val) {
if(!$this->is_connected || !$this->stmt) return;
@ -170,7 +170,7 @@
}
/**
* @brief : prepare된 쿼리의 execute
* @brief : execute the prepared statement
**/
function _execute() {
if(!$this->is_connected || !$this->stmt) return;
@ -200,7 +200,7 @@
}
/**
* @brief 1 증가되는 sequence값을 return
* @brief Return the sequence value incremented by 1
**/
function getNextSequence() {
$query = sprintf("insert into %ssequence (seq) values (NULL)", $this->prefix);
@ -217,7 +217,7 @@
}
/**
* @brief 테이블 기생성 여부 return
* @brief return if the table already exists
**/
function isTableExists($target_name) {
$query = sprintf('pragma table_info(%s%s)', $this->prefix, $target_name);
@ -227,7 +227,7 @@
}
/**
* @brief 특정 테이블에 특정 column 추가
* @brief Add a column to a table
**/
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
$type = $this->column_type[$type];
@ -244,7 +244,7 @@
}
/**
* @brief 특정 테이블에 특정 column 제거
* @brief Remove a column from a table
**/
function dropColumn($table_name, $column_name) {
$query = sprintf("alter table %s%s drop column %s ", $this->prefix, $table_name, $column_name);
@ -252,7 +252,7 @@
}
/**
* @brief 특정 테이블의 column의 정보를 return
* @brief Return column information of a table
**/
function isColumnExists($table_name, $column_name) {
$query = sprintf("pragma table_info(%s%s)", $this->prefix, $table_name);
@ -270,7 +270,7 @@
}
/**
* @brief 특정 테이블에 특정 인덱스 추가
* @brief Add an index to a table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
@ -285,7 +285,7 @@
}
/**
* @brief 특정 테이블의 특정 인덱스 삭제
* @brief Drop an index from a table
**/
function dropIndex($table_name, $index_name, $is_unique = false) {
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
@ -294,7 +294,7 @@
}
/**
* @brief 특정 테이블의 index 정보를 return
* @brief Return index information of a table
**/
function isIndexExists($table_name, $index_name) {
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
@ -307,24 +307,24 @@
}
/**
* @brief xml 받아서 테이블을 생성
* @brief create a table from xml file
**/
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
/**
* @brief xml 받아서 테이블을 생성
* @brief create a table from xml file
**/
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// xml 파일을 읽음
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief schema xml을 이용하여 create table query생성
* @brief generate a query to create a table using the schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
@ -334,8 +334,7 @@
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// 테이블 생성 schema 작성
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;
@ -401,7 +400,7 @@
}
/**
* @brief 조건문 작성하여 return
* @brief Return conditional clause(where)
**/
function getCondition($output) {
if(!$output->conditions) return;
@ -445,15 +444,14 @@
}
/**
* @brief insertAct 처리
* @brief insertAct
**/
function _executeInsertAct($output) {
// 테이블 정리
// list tables
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val;
}
// 컬럼 정리
// list columns
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -480,18 +478,16 @@
}
/**
* @brief updateAct 처리
* @brief updateAct
**/
function _executeUpdateAct($output) {
$table_count = count(array_values($output->tables));
// 대상 테이블이 1개일 경우
// If a target table is one
if($table_count == 1) {
// 테이블 정리
// list tables
list($target_table) = array_values($output->tables);
$target_table = $this->prefix.$target_table;
// 컬럼 정리
// list columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -504,27 +500,23 @@
$column_list[] = sprintf("%s = %s", $name, $value);
}
}
// 조건절 정리
// List where cluase
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s", $target_table, implode(',',$column_list), $condition);
// 대상 테이블이 2개일 경우 (sqlite에서 update 테이블을 1개 이상 지정 못해서 이렇게 꽁수로... 다른 방법이 있으려나..)
// If tables to update are morea than two (In sqlite, it is possible to update a single table only. Let me know if you know a better way)
} elseif($table_count == 2) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[$val] = $this->prefix.$key;
}
list($source_table, $target_table) = array_values($table_list);
// 조건절 정리
// List where cluase
$condition = $this->getCondition($output);
foreach($table_list as $key => $val) {
$condition = eregi_replace($key.'\\.', $val.'.', $condition);
}
// 컬럼 정리
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -547,15 +539,14 @@
}
/**
* @brief deleteAct 처리
* @brief deleteAct
**/
function _executeDeleteAct($output) {
// 테이블 정리
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val;
}
// 조건절 정리
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
@ -565,13 +556,13 @@
}
/**
* @brief selectAct 처리
* @brief selectAct
*
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
* navigation이라는 method를 제공
* To fetch a list of the page conveniently when selecting, \n
* navigation method supported
**/
function _executeSelectAct($output) {
// 테이블 정리
// List tables
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val.' as '.$key;
@ -616,8 +607,7 @@
$output->column_list = $column_list;
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// add the condition to the query to use an index for ordering by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -655,7 +645,7 @@
}
$query = sprintf("select %s from %s %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition, $groupby_query.$orderby_query);
// list_count를 사용할 경우 적용
// apply when using list_count
if($output->list_count['value']) $query = sprintf('%s limit %d', $query, $output->list_count['value']);
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
@ -676,17 +666,17 @@
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
* @brief Paging is handled if navigation information exists in the query xml
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
* It is quite convenient although its structure is not good at all .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
$column_list = $output->column_list;
/*
// group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정
// 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다.
// Modified to find total number of SELECT queries having group by clause
// If it works correctly, uncomment the following codes
//
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
$total_count = $this->getCountCache($output->tables, $count_condition);
@ -700,8 +690,7 @@
$this->putCountCache($output->tables, $count_condition, $total_count);
}
*/
// 전체 개수를 구함
// Get a total count
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id . ' count(*)'):'';
$this->_prepare($count_query);
@ -714,16 +703,13 @@
if(!$page_count) $page_count = 10;
$page = $output->page['value'];
if(!$page) $page = 1;
// 전체 페이지를 구함
// Get a total page
if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1;
else $total_page = 1;
// 페이지 변수를 체크
// Check Page variables
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
@ -760,7 +746,7 @@
$columns = join(',',$output->arg_columns);
}
// return 결과물 생성
// Return the result
$buff = new Object();
$buff->total_count = 0;
$buff->total_page = 0;
@ -768,7 +754,7 @@
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
// 쿼리 실행
// Query Execution
$query = sprintf("select %s from %s %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition, $groupby_query.$orderby_query);
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';