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

@ -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):'';