mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
git-svn-id: http://xe-core.googlecode.com/svn/trunk@1114 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
1ea27b0635
commit
a35fd84e0e
7 changed files with 380 additions and 313 deletions
|
|
@ -125,7 +125,7 @@
|
|||
}
|
||||
|
||||
function actFinish() {
|
||||
if(!__DEBUG__) return;
|
||||
if(!__DEBUG__ || !$this->query) return;
|
||||
$this->act_finish = getMicroTime();
|
||||
$elapsed_time = $this->act_finish - $this->act_start;
|
||||
$GLOBALS['__db_elapsed_time__'] += $elapsed_time;
|
||||
|
|
@ -138,6 +138,7 @@
|
|||
$str .= "\t Query Success\n";
|
||||
}
|
||||
$GLOBALS['__db_queries__'] .= $str;
|
||||
$this->query = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -342,9 +342,11 @@
|
|||
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
if(!isset($val['value'])) continue;
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
|
||||
else $value = (int)$value;
|
||||
|
||||
$column_list[] = sprintf("`%s` = %s", $name, $value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,9 +351,11 @@
|
|||
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
if(!isset($val['value'])) continue;
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
|
||||
else $value = (int)$value;
|
||||
|
||||
$column_list[] = sprintf("`%s` = %s", $name, $value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
|
||||
class DBSqlite2 extends DB {
|
||||
|
||||
/**
|
||||
* DB를 이용하기 위한 정보
|
||||
**/
|
||||
var $database = NULL; ///< database
|
||||
var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능)
|
||||
|
||||
|
|
@ -74,6 +77,14 @@
|
|||
$this->is_connected = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DB접속 해제
|
||||
**/
|
||||
function close() {
|
||||
if(!$this->isConnected()) return;
|
||||
sqlite_close($this->fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 트랜잭션 시작
|
||||
**/
|
||||
|
|
@ -100,16 +111,6 @@
|
|||
$this->transaction_started = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief DB접속 해제
|
||||
**/
|
||||
function close() {
|
||||
if(!$this->isConnected()) return;
|
||||
|
||||
sqlite_close($this->fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
|
||||
**/
|
||||
|
|
@ -129,38 +130,21 @@
|
|||
* return\n
|
||||
**/
|
||||
function _query($query) {
|
||||
if(!$this->isConnected()) return false;
|
||||
if(!$this->isConnected()) return;
|
||||
|
||||
$this->query = $query;
|
||||
|
||||
if(__DEBUG__) $query_start = getMicroTime();
|
||||
|
||||
$this->setError(0,'success');
|
||||
// 쿼리 시작을 알림
|
||||
$this->actStart($query);
|
||||
|
||||
// 쿼리 문 실행
|
||||
$result = @sqlite_query($query, $this->fd);
|
||||
|
||||
if(__DEBUG__) {
|
||||
$query_end = getMicroTime();
|
||||
$elapsed_time = $query_end - $query_start;
|
||||
$GLOBALS['__db_elapsed_time__'] += $elapsed_time;
|
||||
}
|
||||
// 오류 체크
|
||||
if(sqlite_last_error($this->fd)) $this->setError(sqlite_last_error($this->fd), sqlite_error_string(sqlite_last_error($this->fd)));
|
||||
|
||||
if(sqlite_last_error($this->fd)) {
|
||||
$this->setError(sqlite_last_error($this->fd), sqlite_error_string(sqlite_last_error($this->fd)));
|
||||
// 쿼리 실행 알림
|
||||
$this->actFinish();
|
||||
|
||||
if(__DEBUG__) {
|
||||
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(__DEBUG__) {
|
||||
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time);
|
||||
}
|
||||
|
||||
if($result) return $result;
|
||||
return true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -292,78 +276,89 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 삭제
|
||||
* @brief 조건문 작성하여 return
|
||||
**/
|
||||
function dropTable($target_name) {
|
||||
$query = sprintf('DROP TABLE %s%s;', $this->prefix, $this->addQuotes($target_name));
|
||||
$this->_query($query);
|
||||
function getCondition($output) {
|
||||
if(!$output->conditions) return;
|
||||
|
||||
foreach($output->conditions as $key => $val) {
|
||||
$sub_condition = '';
|
||||
foreach($val['condition'] as $k =>$v) {
|
||||
if(!$v['value']) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
$value = $v['value'];
|
||||
$type = $output->column_type[$name];
|
||||
$pipe = $v['pipe'];
|
||||
|
||||
$value = $this->getConditionValue($name, $value, $operation, $type);
|
||||
$str = $this->getConditionPart($name, $value, $operation);
|
||||
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
|
||||
$sub_condition .= $str;
|
||||
}
|
||||
if($sub_condition) {
|
||||
if($condition && $val['pipe']) $condition .= ' '.$val['pipe'].' ';
|
||||
$condition .= '('.$sub_condition.')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블의 이름 변경
|
||||
**/
|
||||
function renameTable($source_name, $targe_name) {
|
||||
$query = sprintf("ALTER TABLE %s%s RENAME TO %s%s;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name));
|
||||
$this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블을 비움
|
||||
**/
|
||||
function truncateTable($target_name) {
|
||||
$query = sprintf("VACUUM %s%s;", $this->prefix, $this->addQuotes($target_name));
|
||||
$this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 데이터 Dump
|
||||
*
|
||||
* @todo 아직 미구현
|
||||
**/
|
||||
function dumpTable($target_name) {
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insertAct 처리
|
||||
**/
|
||||
function _executeInsertAct($tables, $column, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
|
||||
foreach($column as $key => $val) {
|
||||
$key_list[] = $key;
|
||||
if(in_array($key, $pass_quotes)) $val_list[] = $this->addQuotes($val);
|
||||
else {
|
||||
if(!is_numeric($val)) $val_list[] = '\''.$this->addQuotes($val).'\'';
|
||||
else $val_list[] = $this->addQuotes($val);
|
||||
}
|
||||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
}
|
||||
|
||||
$query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$key_list), implode(',', $val_list));
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') {
|
||||
$value = "'".$this->addQuotes($value)."'";
|
||||
if(!$value) $value = 'null';
|
||||
} else {
|
||||
if(!$value) $value = 0;
|
||||
}
|
||||
|
||||
$column_list[] = $name;
|
||||
$value_list[] = $value;
|
||||
}
|
||||
|
||||
$query = sprintf("insert into %s (%s) values (%s);", implode(',',$table_list), implode(',',$column_list), implode(',', $value_list));
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief updateAct 처리
|
||||
**/
|
||||
function _executeUpdateAct($tables, $column, $args, $condition, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
|
||||
foreach($column as $key => $val) {
|
||||
// args에 아예 해당 key가 없으면 패스
|
||||
if(!isset($args->{$key})) continue;
|
||||
if(in_array($key, $pass_quotes)) $update_list[] = sprintf('%s = %s', $key, $this->addQuotes($val));
|
||||
else {
|
||||
if(!is_numeric($val)) $update_list[] = sprintf('%s = \'%s\'', $key, $this->addQuotes($val));
|
||||
else $update_list[] = sprintf('%s = %s', $key, $this->addQuotes($val));
|
||||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
if(!isset($val['value'])) continue;
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
|
||||
else $value = (int)$value;
|
||||
|
||||
$column_list[] = sprintf("%s = %s", $name, $value);
|
||||
}
|
||||
if(!count($update_list)) return;
|
||||
$update_query = implode(',',$update_list);
|
||||
|
||||
if($condition) $condition = ' WHERE '.$condition;
|
||||
// 조건절 정리
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("UPDATE %s%s SET %s %s;", $this->prefix, $table, $update_query, $condition);
|
||||
$query = sprintf("update %s set %s %s", implode(',',$table_list), implode(',',$column_list), $condition);
|
||||
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
|
@ -371,12 +366,17 @@
|
|||
/**
|
||||
* @brief deleteAct 처리
|
||||
**/
|
||||
function _executeDeleteAct($tables, $condition, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
}
|
||||
|
||||
if($condition) $condition = ' WHERE '.$condition;
|
||||
// 조건절 정리
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
|
||||
|
||||
$query = sprintf("DELETE FROM %s%s %s;", $this->prefix, $table, $condition);
|
||||
return $this->_query($query);
|
||||
}
|
||||
|
||||
|
|
@ -386,34 +386,44 @@
|
|||
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
|
||||
* navigation이라는 method를 제공
|
||||
**/
|
||||
function _executeSelectAct($tables, $column, $invert_columns, $condition, $navigation, $group_script, $pass_quotes) {
|
||||
if(!count($tables)) $table = $this->prefix.array_pop($tables);
|
||||
else {
|
||||
foreach($tables as $key => $val) $table_list[] = sprintf('%s%s as %s', $this->prefix, $key, $val);
|
||||
function _executeSelectAct($output) {
|
||||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key.' as '.$val;
|
||||
}
|
||||
$table = implode(',',$table_list);
|
||||
|
||||
if(!$column) $columns = '*';
|
||||
else {
|
||||
foreach($invert_columns as $key => $val) {
|
||||
$column_list[] = sprintf('%s as %s',$val, $key);
|
||||
if(!$output->columns) {
|
||||
$columns = '*';
|
||||
} else {
|
||||
$column_list = array();
|
||||
foreach($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$alias = $val['alias'];
|
||||
if($name == '*') {
|
||||
$column_list[] = '*';
|
||||
} elseif(strpos($name,'.')===false && strpos($name,'(')===false) {
|
||||
if($alias) $column_list[] = sprintf('%s as %s', $name, $alias);
|
||||
else $column_list[] = sprintf('%s',$name);
|
||||
} else {
|
||||
if($alias) $column_list[] = sprintf('%s as %s', $name, $alias);
|
||||
else $column_list[] = sprintf('%s',$name);
|
||||
}
|
||||
}
|
||||
$columns = implode(',',$column_list);
|
||||
}
|
||||
|
||||
if($condition) $condition = ' WHERE '.$condition;
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
if($navigation->list_count) return $this->_getNavigationData($table, $columns, $condition, $navigation);
|
||||
if($output->list_count) return $this->_getNavigationData($table_list, $columns, $condition, $output);
|
||||
|
||||
$query = sprintf("SELECT %s FROM %s %s", $columns, $table, $condition);
|
||||
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
|
||||
|
||||
$query .= ' '.$group_script;
|
||||
|
||||
if($navigation->index) {
|
||||
foreach($navigation->index as $index_obj) {
|
||||
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
|
||||
if($output->order) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
|
||||
}
|
||||
if(count($index_list)) $query .= ' ORDER BY '.implode(',',$index_list);
|
||||
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
|
||||
}
|
||||
|
||||
$result = $this->_query($query);
|
||||
|
|
@ -430,29 +440,40 @@
|
|||
*
|
||||
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
|
||||
**/
|
||||
function _getNavigationData($table, $columns, $condition, $navigation) {
|
||||
function _getNavigationData($table_list, $columns, $condition, $output) {
|
||||
require_once('./classes/page/PageHandler.class.php');
|
||||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", $table, $condition);
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$result = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result);
|
||||
$total_count = (int)$count_output->count;
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
$page_count = $output->page_count['value'];
|
||||
if(!$page_count) $page_count = 10;
|
||||
$page = $output->page->value;
|
||||
if(!$page) $page = 1;
|
||||
|
||||
// 전체 페이지를 구함
|
||||
$total_page = (int)(($total_count-1)/$navigation->list_count) +1;
|
||||
$total_page = (int)(($total_count-1)/$list_count) +1;
|
||||
|
||||
// 페이지 변수를 체크
|
||||
if($navigation->page > $total_page) $page = $navigation->page;
|
||||
else $page = $navigation->page;
|
||||
$start_count = ($page-1)*$navigation->list_count;
|
||||
if($page > $total_page) $page = $total_page;
|
||||
$start_count = ($page-1)*$list_count;
|
||||
|
||||
foreach($navigation->index as $index_obj) {
|
||||
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
|
||||
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
|
||||
|
||||
if($output->order) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
|
||||
}
|
||||
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
|
||||
}
|
||||
|
||||
$index = implode(',',$index_list);
|
||||
$query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
|
||||
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
|
||||
|
||||
$result = $this->_query($query);
|
||||
if($this->isError()) {
|
||||
$buff = new Object();
|
||||
|
|
@ -461,19 +482,21 @@
|
|||
$buff->page = 1;
|
||||
$buff->data = array();
|
||||
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $navigation->page_count);
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
return $buff;
|
||||
}
|
||||
|
||||
$virtual_no = $total_count - ($page-1)*$navigation->list_count;
|
||||
$tmp_data = $this->_fetch($result);
|
||||
if($tmp_data) {
|
||||
if(!is_array($tmp_data)) $tmp_data = array($tmp_data);
|
||||
foreach($tmp_data as $tmp) {
|
||||
$data[$virtual_no--] = $tmp;
|
||||
if($result) {
|
||||
$virtual_no = $total_count - ($page-1)*$list_count;
|
||||
while($tmp = sqlite_fetch_array($result, SQLITE_ASSOC)) {
|
||||
unset($obj);
|
||||
foreach($tmp as $key => $val) {
|
||||
$pos = strpos($key, '.');
|
||||
if($pos) $key = substr($key, $pos+1);
|
||||
$obj->{$key} = $val;
|
||||
}
|
||||
$data[$virtual_no--] = $obj;
|
||||
}
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
$buff = new Object();
|
||||
|
|
@ -482,7 +505,7 @@
|
|||
$buff->page = $page;
|
||||
$buff->data = $data;
|
||||
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $navigation->page_count);
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
return $buff;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,20 @@
|
|||
|
||||
class DBSqlite3_pdo extends DB {
|
||||
|
||||
/**
|
||||
* DB를 이용하기 위한 정보
|
||||
**/
|
||||
var $database = NULL; ///< database
|
||||
var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능)
|
||||
|
||||
/**
|
||||
* PDO 사용시 필요한 변수들
|
||||
**/
|
||||
var $handler = NULL;
|
||||
var $stmt = NULL;
|
||||
var $bind_idx = 0;
|
||||
var $bind_vars = array();
|
||||
|
||||
var $database = NULL; ///< database
|
||||
var $prefix = 'xe'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능)
|
||||
|
||||
/**
|
||||
* @brief sqlite3 에서 사용될 column type
|
||||
*
|
||||
|
|
@ -79,6 +85,14 @@
|
|||
$this->is_connected = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DB접속 해제
|
||||
**/
|
||||
function close() {
|
||||
if(!$this->isConnected()) return;
|
||||
$this->commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 트랜잭션 시작
|
||||
**/
|
||||
|
|
@ -105,14 +119,6 @@
|
|||
$this->transaction_started = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief DB접속 해제
|
||||
**/
|
||||
function close() {
|
||||
if(!$this->isConnected()) return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
|
||||
**/
|
||||
|
|
@ -128,22 +134,15 @@
|
|||
function _prepare($query) {
|
||||
if(!$this->isConnected()) return;
|
||||
|
||||
$this->query = $query;
|
||||
$this->setError(0,'success');
|
||||
// 쿼리 시작을 알림
|
||||
$this->actStart($query);
|
||||
|
||||
$this->stmt = $this->handler->prepare($query);
|
||||
|
||||
if($this->handler->errorCode() != '00000') {
|
||||
$this->setError($this->handler->errorCode(), print_r($this->handler->errorInfo(),true));
|
||||
|
||||
if(__DEBUG__) {
|
||||
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s\n\t Fail : %s\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $this->errno, $this->errstr);
|
||||
$this->actFinish();
|
||||
}
|
||||
|
||||
unset($this->stmt);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->bind_idx = 0;
|
||||
$this->bind_vars = array();
|
||||
}
|
||||
|
|
@ -165,34 +164,9 @@
|
|||
function _execute() {
|
||||
if(!$this->isConnected() || !$this->stmt) return;
|
||||
|
||||
if(__DEBUG__) $query_start = getMicroTime();
|
||||
|
||||
$this->stmt->execute();
|
||||
|
||||
if(__DEBUG__) {
|
||||
$query_end = getMicroTime();
|
||||
$elapsed_time = $query_end - $query_start;
|
||||
$GLOBALS['__db_elapsed_time__'] += $elapsed_time;
|
||||
}
|
||||
|
||||
$this->bind_idx = 0;
|
||||
$this->bind_vars = 0;
|
||||
if($this->stmt->errorCode() != '00000') {
|
||||
$this->setError($this->stmt->errorCode(),print_r($this->stmt->errorInfo(),true));
|
||||
|
||||
if(__DEBUG__) {
|
||||
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr);
|
||||
}
|
||||
|
||||
$this->stmt = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(__DEBUG__) {
|
||||
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time);
|
||||
}
|
||||
|
||||
if($this->stmt->errorCode() === '00000') {
|
||||
$output = null;
|
||||
while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
unset($obj);
|
||||
|
|
@ -203,8 +177,12 @@
|
|||
}
|
||||
$output[] = $obj;
|
||||
}
|
||||
} else {
|
||||
$this->setError($this->stmt->errorCode(),print_r($this->stmt->errorInfo(),true));
|
||||
}
|
||||
|
||||
$this->stmt = null;
|
||||
$this->actFinish();
|
||||
|
||||
if(is_array($output) && count($output)==1) return $output[0];
|
||||
return $output;
|
||||
|
|
@ -325,99 +303,115 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 삭제
|
||||
* @brief 조건문 작성하여 return
|
||||
**/
|
||||
function dropTable($target_name) {
|
||||
$query = sprintf('DROP TABLE %s%s;', $this->prefix, $this->addQuotes($target_name));
|
||||
$this->_prepare($query);
|
||||
$this->_execute();
|
||||
function getCondition($output) {
|
||||
if(!$output->conditions) return;
|
||||
|
||||
foreach($output->conditions as $key => $val) {
|
||||
$sub_condition = '';
|
||||
foreach($val['condition'] as $k =>$v) {
|
||||
if(!$v['value']) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
$value = $v['value'];
|
||||
$type = $output->column_type[$name];
|
||||
$pipe = $v['pipe'];
|
||||
|
||||
$value = $this->getConditionValue($name, $value, $operation, $type);
|
||||
$str = $this->getConditionPart($name, $value, $operation);
|
||||
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
|
||||
$sub_condition .= $str;
|
||||
}
|
||||
if($sub_condition) {
|
||||
if($condition && $val['pipe']) $condition .= ' '.$val['pipe'].' ';
|
||||
$condition .= '('.$sub_condition.')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블의 이름 변경
|
||||
**/
|
||||
function renameTable($source_name, $targe_name) {
|
||||
$query = sprintf("ALTER TABLE %s%s RENAME TO %s%s;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name));
|
||||
$this->_prepare($query);
|
||||
$this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블을 비움
|
||||
**/
|
||||
function truncateTable($target_name) {
|
||||
$query = sprintf("VACUUM %s%s;", $this->prefix, $this->addQuotes($target_name));
|
||||
$this->_prepare($query);
|
||||
$this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 데이터 Dump
|
||||
*
|
||||
* @todo 아직 미구현
|
||||
**/
|
||||
function dumpTable($target_name) {
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insertAct 처리
|
||||
**/
|
||||
function _executeInsertAct($tables, $column, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
function _executeInsertAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
|
||||
$key_list[] = $name;
|
||||
|
||||
if($output->column_type[$name]!='number') $val_list[] = $this->addQuotes($value);
|
||||
else $val_list[] = (int)$value;
|
||||
|
||||
foreach($column as $key => $val) {
|
||||
$key_list[] = $key;
|
||||
$val_list[] = $this->addQuotes($val);
|
||||
$prepare_list[] = '?';
|
||||
}
|
||||
|
||||
$query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$key_list), implode(',',$prepare_list));
|
||||
$query = sprintf("INSERT INTO %s (%s) VALUES (%s);", implode(',',$table_list), implode(',',$key_list), implode(',',$prepare_list));
|
||||
|
||||
$this->_prepare($query);
|
||||
|
||||
$val_count = count($val_list);
|
||||
for($i=0;$i<$val_count;$i++) $this->_bind($val_list[$i]);
|
||||
|
||||
$this->_execute();
|
||||
return $this->isError();
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief updateAct 처리
|
||||
**/
|
||||
function _executeUpdateAct($tables, $column, $args, $condition, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
|
||||
foreach($column as $key => $val) {
|
||||
// args에 아예 해당 key가 없으면 패스
|
||||
if(!isset($args->{$key})) continue;
|
||||
$val = $this->addQuotes($val);
|
||||
if(is_numeric($val) || in_array($key, $pass_quotes)) $update_list[] = sprintf('`%s` = %s', $key, $val);
|
||||
else $update_list[] = sprintf('`%s` = \'%s\'', $key, $this->addQuotes($val));
|
||||
function _executeUpdateAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
}
|
||||
if(!count($update_list)) return;
|
||||
$update_query = implode(',',$update_list);
|
||||
if($condition) $condition = ' where '.$condition;
|
||||
$query = sprintf("update `%s%s` set %s %s;", $this->prefix, $table, $update_query, $condition);
|
||||
|
||||
// 컬럼 정리
|
||||
foreach($output->columns as $key => $val) {
|
||||
if(!isset($val['value'])) continue;
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
|
||||
else $value = (int)$value;
|
||||
|
||||
$column_list[] = sprintf("%s = %s", $name, $value);
|
||||
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("update %s set %s %s", implode(',',$table_list), implode(',',$column_list), $condition);
|
||||
|
||||
$this->_prepare($query);
|
||||
$this->_execute();
|
||||
return $this->isError();
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief deleteAct 처리
|
||||
**/
|
||||
function _executeDeleteAct($tables, $condition, $pass_quotes) {
|
||||
$table = array_pop($tables);
|
||||
function _executeDeleteAct($output) {
|
||||
// 테이블 정리
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key;
|
||||
}
|
||||
|
||||
if($condition) $condition = ' WHERE '.$condition;
|
||||
// 조건절 정리
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
|
||||
|
||||
$query = sprintf("DELETE FROM %s%s %s;", $this->prefix, $table, $condition);
|
||||
$this->_prepare($query);
|
||||
$this->_execute();
|
||||
|
||||
return $this->isError();
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -426,34 +420,44 @@
|
|||
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
|
||||
* navigation이라는 method를 제공
|
||||
**/
|
||||
function _executeSelectAct($tables, $column, $invert_columns, $condition, $navigation, $group_script, $pass_quotes) {
|
||||
if(!count($tables)) $table = $this->prefix.array_pop($tables);
|
||||
else {
|
||||
foreach($tables as $key => $val) $table_list[] = sprintf('%s%s as %s', $this->prefix, $key, $val);
|
||||
function _executeSelectAct($output) {
|
||||
// 테이블 정리
|
||||
$table_list = array();
|
||||
foreach($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix.$key.' as '.$val;
|
||||
}
|
||||
$table = implode(',',$table_list);
|
||||
|
||||
if(!$column) $columns = '*';
|
||||
else {
|
||||
foreach($invert_columns as $key => $val) {
|
||||
$column_list[] = sprintf('%s as %s',$val, $key);
|
||||
if(!$output->columns) {
|
||||
$columns = '*';
|
||||
} else {
|
||||
$column_list = array();
|
||||
foreach($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$alias = $val['alias'];
|
||||
if($name == '*') {
|
||||
$column_list[] = '*';
|
||||
} elseif(strpos($name,'.')===false && strpos($name,'(')===false) {
|
||||
if($alias) $column_list[] = sprintf('%s as %s', $name, $alias);
|
||||
else $column_list[] = sprintf('%s',$name);
|
||||
} else {
|
||||
if($alias) $column_list[] = sprintf('%s as %s', $name, $alias);
|
||||
else $column_list[] = sprintf('%s',$name);
|
||||
}
|
||||
}
|
||||
$columns = implode(',',$column_list);
|
||||
}
|
||||
|
||||
if($condition) $condition = ' WHERE '.$condition;
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
if($navigation->list_count) return $this->_getNavigationData($table, $columns, $condition, $navigation);
|
||||
if($output->list_count) return $this->_getNavigationData($table_list, $columns, $condition, $output);
|
||||
|
||||
$query = sprintf("SELECT %s FROM %s %s", $columns, $table, $condition);
|
||||
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
|
||||
|
||||
$query .= ' '.$group_script;
|
||||
|
||||
if($navigation->index) {
|
||||
foreach($navigation->index as $index_obj) {
|
||||
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
|
||||
if($output->order) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
|
||||
}
|
||||
if(count($index_list)) $query .= ' ORDER BY '.implode(',',$index_list);
|
||||
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
|
||||
}
|
||||
|
||||
$this->_prepare($query);
|
||||
|
|
@ -470,50 +474,78 @@
|
|||
*
|
||||
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
|
||||
**/
|
||||
function _getNavigationData($table, $columns, $condition, $navigation) {
|
||||
function _getNavigationData($table_list, $columns, $condition, $output) {
|
||||
require_once('./classes/page/PageHandler.class.php');
|
||||
|
||||
// 전체 개수를 구함
|
||||
$count_query = sprintf("select count(*) as count from %s %s", $table, $condition);
|
||||
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
|
||||
$this->_prepare($count_query);
|
||||
$count_output = $this->_execute();
|
||||
$total_count = (int)$count_output->count;
|
||||
|
||||
$list_count = $output->list_count['value'];
|
||||
if(!$list_count) $list_count = 20;
|
||||
$page_count = $output->page_count['value'];
|
||||
if(!$page_count) $page_count = 10;
|
||||
$page = $output->page->value;
|
||||
if(!$page) $page = 1;
|
||||
|
||||
// 전체 페이지를 구함
|
||||
$total_page = (int)(($total_count-1)/$navigation->list_count) +1;
|
||||
$total_page = (int)(($total_count-1)/$list_count) +1;
|
||||
|
||||
// 페이지 변수를 체크
|
||||
if($navigation->page > $total_page) $page = $navigation->page;
|
||||
else $page = $navigation->page;
|
||||
$start_count = ($page-1)*$navigation->list_count;
|
||||
if($page > $total_page) $page = $total_page;
|
||||
$start_count = ($page-1)*$list_count;
|
||||
|
||||
foreach($navigation->index as $index_obj) {
|
||||
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
|
||||
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
|
||||
|
||||
if($output->order) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
|
||||
}
|
||||
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
|
||||
}
|
||||
|
||||
$index = implode(',',$index_list);
|
||||
$query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
|
||||
$this->_prepare($query);
|
||||
$tmp_data = $this->_execute();
|
||||
if($this->isError()) {
|
||||
// return 결과물 생성
|
||||
$buff = new Object();
|
||||
$buff->total_count = 0;
|
||||
$buff->total_page = 0;
|
||||
$buff->page = 1;
|
||||
$buff->data = array();
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $navigation->page_count);
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
|
||||
// 쿼리 실행
|
||||
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
|
||||
$this->_prepare($query);
|
||||
|
||||
if($this->isError()) {
|
||||
$this->setError($this->handler->errorCode(), print_r($this->handler->errorInfo(),true));
|
||||
$this->actFinish();
|
||||
return $buff;
|
||||
}
|
||||
|
||||
$virtual_no = $total_count - ($page-1)*$navigation->list_count;
|
||||
if($tmp_data) {
|
||||
if(!is_array($tmp_data)) $tmp_data = array($tmp_data);
|
||||
foreach($tmp_data as $tmp) {
|
||||
$data[$virtual_no--] = $tmp;
|
||||
$this->stmt->execute();
|
||||
|
||||
if($this->stmt->errorCode() != '00000') {
|
||||
$this->setError($this->stmt->errorCode(), print_r($this->stmt->errorInfo(),true));
|
||||
$this->actFinish();
|
||||
return $buff;
|
||||
}
|
||||
} else {
|
||||
$data = null;
|
||||
|
||||
$output = null;
|
||||
$virtual_no = $total_count - ($page-1)*$list_count;
|
||||
while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
unset($obj);
|
||||
foreach($tmp as $key => $val) {
|
||||
$pos = strpos($key, '.');
|
||||
if($pos) $key = substr($key, $pos+1);
|
||||
$obj->{$key} = $val;
|
||||
}
|
||||
$data[$virtual_no--] = $obj;
|
||||
}
|
||||
|
||||
$this->stmt = null;
|
||||
$this->actFinish();
|
||||
|
||||
$buff = new Object();
|
||||
$buff->total_count = $total_count;
|
||||
|
|
@ -521,7 +553,7 @@
|
|||
$buff->page = $page;
|
||||
$buff->data = $data;
|
||||
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $navigation->page_count);
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
|
||||
return $buff;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
function _toXmlDoc(&$oModule) {
|
||||
$xmlDoc = "<response>\n";
|
||||
$xmlDoc .= sprintf("<error>%s</error>\n",$oModule->getError());
|
||||
$xmlDoc .= sprintf("<message>%s</message>\n",$oModule->getMessage());
|
||||
$xmlDoc .= sprintf("<message>%s</message>\n",str_replace(array('<','>','&'),array('<','>','&'),$oModule->getMessage()));
|
||||
|
||||
$variables = $oModule->getVariables();
|
||||
|
||||
|
|
|
|||
|
|
@ -166,13 +166,17 @@
|
|||
foreach($output->columns as $key => $val) {
|
||||
$val['default'] = $this->getDefault($val['name'], $val['default']);
|
||||
if($val['var'] && strpos($val['var'],'.')===false) {
|
||||
$buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s?$args->%s:%s),%s', $val['name'], $val['alias'], $val['var'], $val['var'], $val['default'] ,"\n");
|
||||
|
||||
if($val['default']) $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s?$args->%s:%s),%s', $val['name'], $val['alias'], $val['var'], $val['var'], $val['default'] ,"\n");
|
||||
else $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>$args->%s),%s', $val['name'], $val['alias'], $val['var'], "\n");
|
||||
|
||||
if($val['default']) $default_list[$val['var']] = $val['default'];
|
||||
if($val['notnull']) $notnull_list[] = $val['var'];
|
||||
if($val['minlength']) $minlength_list[$val['var']] = $val['minlength'];
|
||||
if($val['maxlength']) $maxlength_list[$val['var']] = $val['maxlength'];
|
||||
} else {
|
||||
$buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>%s),%s', $val['name'], $val['alias'], $val['default'] ,"\n");
|
||||
if($val['default']) $buff .= sprintf('array("name"=>"%s", "alias"=>"%s", "value"=>%s),%s', $val['name'], $val['alias'], $val['default'] ,"\n");
|
||||
else $buff .= sprintf('array("name"=>"%s", "alias"=>"%s",),%s', $val['name'], $val['alias'], "\n");
|
||||
}
|
||||
}
|
||||
$buff .= ' );'."\n";
|
||||
|
|
@ -189,12 +193,14 @@
|
|||
if(strpos($v->var,".")===false) {
|
||||
if($v->default) $default_list[$v->var] = $v->default;
|
||||
if($v->filter) $filter_list[] = $v;
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n");
|
||||
if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s?$args->%s:%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->var, $v->default, $v->pipe, $v->operation, "\n");
|
||||
else $buff .= sprintf('array("column"=>"%s", "value"=>$args->%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
|
||||
} else {
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>"%s","pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->var, $v->pipe, $v->operation, "\n");
|
||||
}
|
||||
} else {
|
||||
$buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n");
|
||||
if($v->default) $buff .= sprintf('array("column"=>"%s", "value"=>%s,"pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->default ,$v->pipe, $v->operation,"\n");
|
||||
else $buff .= sprintf('array("column"=>"%s", "pipe"=>"%s","operation"=>"%s",),%s', $v->column, $v->pipe, $v->operation,"\n");
|
||||
}
|
||||
}
|
||||
$buff .= ')),'."\n";
|
||||
|
|
@ -278,6 +284,7 @@
|
|||
* @brief column, condition등의 key에 default 값을 세팅
|
||||
**/
|
||||
function getDefault($name, $value) {
|
||||
if(!$value) return;
|
||||
$str_pos = strpos($value, '(');
|
||||
if($str_pos===false) return '"'.$value.'"';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue