mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-02 08:42:15 +09:00
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:
parent
693e215bc1
commit
4d272994dd
219 changed files with 6407 additions and 8705 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue