left/right outer join 지원 추가

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5199 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ngleader 2009-01-02 06:47:42 +00:00
parent 56acdeca75
commit 9a029e0f8d
9 changed files with 530 additions and 260 deletions

View file

@ -129,7 +129,7 @@
}
/**
* @brief 로그 남김
* @brief 로그 남김
**/
function actStart($query) {
$this->setError(0,'success');
@ -149,7 +149,7 @@
// 에러 발생시 에러 로그를 남김 (__DEBUG_DB_OUTPUT__이 지정되어 있을경우)
if($this->isError()) {
$str .= sprintf("\t Query Failed : %d\n\t\t\t %s\n", $this->errno, $this->errstr);
$str .= sprintf("\t Query Failed : %d\n\t\t\t %s\n", $this->errno, $this->errstr);
if(__DEBUG_DB_OUTPUT__==1) {
$debug_file = _XE_PATH_."files/_debug_db_query.php";
@ -207,7 +207,7 @@
/**
* @brief query xml 파일을 실행하여 결과를 return
*
* query_id = module.queryname
* query_id = module.queryname
* query_id에 해당하는 xml문(or 캐싱파일) 찾아서 컴파일 실행
**/
function executeQuery($query_id, $args = NULL) {
@ -229,6 +229,20 @@
$xml_file = sprintf('%s%s/%s/queries/%s.xml', _XE_PATH_, $target, $module, $id);
if(!file_exists($xml_file)) return new Object(-1, 'msg_invalid_queryid');
// 캐쉬파일을 찾아 본다
$cache_file = $this->checkQueryCacheFile($query_id,$xml_file);
// 쿼리를 실행한다
return $this->_executeQuery($cache_file, $args, $query_id);
}
/**
* @brief 캐쉬파일을 찾아 본다
*
**/
function checkQueryCacheFile($query_id,$xml_file){
// 일단 cache 파일을 찾아본다
$cache_file = sprintf('%s%s%s.cache.php', _XE_PATH_, $this->cache_file, $query_id);
if(file_exists($cache_file)) $cache_time = filemtime($cache_file);
@ -236,15 +250,14 @@
// 캐시 파일이 없거나 시간 비교하여 최근것이 아니면 원본 쿼리 xml파일을 찾아서 파싱을 한다
if($cache_time<filemtime($xml_file) || $cache_time < filemtime(_XE_PATH_.'classes/db/DB.class.php')) {
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
require_once(_XE_PATH_.'classes/xml/XmlQueryParser.class.php');
$oParser = new XmlQueryParser();
$oParser->parse($query_id, $xml_file, $cache_file);
}
// 쿼리를 실행한다
return $this->_executeQuery($cache_file, $args, $query_id);
return $cache_file;
}
/**
* @brief 쿼리문을 실행하고 결과를 return한다
**/
@ -258,6 +271,7 @@
$output = @include($cache_file);
if( (is_a($output, 'Object')||is_subclass_of($output,'Object'))&&!$output->toBool()) return $output;
$output->_tables = ($output->_tables && is_array($output->_tables)) ? $output->_tables : array();
// action값에 따라서 쿼리 생성으로 돌입
@ -349,13 +363,13 @@
$value = preg_replace('/(^\'|\'$){1}/','',$value);
switch($operation) {
case 'like_prefix' :
case 'like_prefix' :
$value = $value.'%';
break;
case 'like_tail' :
case 'like_tail' :
$value = '%'.$value;
break;
case 'like' :
case 'like' :
$value = '%'.$value.'%';
break;
case 'in' :
@ -454,7 +468,7 @@
if(!is_array($tables)) $tables_str = $tables;
else $tables_str = implode('.',$tables);
$cache_path = sprintf('%s/%s%s', $this->count_cache_path, $this->prefix, $tables_str);
if(!is_dir($cache_path)) FileHandler::makeDir($cache_path);
@ -511,5 +525,17 @@
return true;
}
function getSupportedDatabase(){
$result = array();
if(function_exists('mysql_connect')) $result[] = 'MySQL';
if(function_exists('cubrid_connect')) $result[] = 'Cubrid';
if(function_exists('ibase_connect')) $result[] = 'FireBird';
if(function_exists('pg_connect')) $result[] = 'Postgre';
if(function_exists('sqlite_open')) $result[] = 'sqlite2';
if(function_exists('PDO')) $result[] = 'sqlite3(PDO)';
return $result;
}
}
?>

View file

@ -18,7 +18,7 @@
var $userid = NULL; ///< user id
var $password = NULL; ///< password
var $database = NULL; ///< database
var $port = 33000; ///< db server port
var $port = 33000; ///< db server port
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능)
var $cutlen = 12000; ///< 큐브리드의 최대 상수 크기(스트링이 이보다 크면 '...'+'...' 방식을 사용해야 한다
@ -75,7 +75,7 @@
// db 정보가 없으면 무시
if(!$this->hostname || !$this->userid || !$this->password || !$this->database || !$this->port) return;
// 접속시도
// 접속시도
$this->fd = @cubrid_connect($this->hostname, $this->port, $this->database, $this->userid, $this->password);
// 접속체크
@ -385,9 +385,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($output->conditions as $val) {
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -397,30 +407,24 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
if(strpos($name,'.')===false) $name = '"'.$name.'"';
else $name = str_replace('.','."',$name).'"';
$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.')';
}
}
if($condition) $condition = ' where '.$condition;
return $condition;
}
/**
* @brief insertAct 처리
**/
@ -430,7 +434,7 @@
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 컬럼 정리
// 컬럼 정리
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -471,15 +475,15 @@
$table_list[] = "\"".$this->prefix.$val."\" as ".$key;
}
// 컬럼 정리
// 컬럼 정리
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
$value = $val['value'];
for ($i = 0; $i < $key; $i++) { // 한문장에 같은 속성에 대한 중복 설정은 큐브리드에서는 허용치 않음
if ($output->columns[$i]['name'] == $name) break;
}
if ($i < $key) continue; // 중복이 발견되면 이후의 설정은 무시
for ($i = 0; $i < $key; $i++) { // 한문장에 같은 속성에 대한 중복 설정은 큐브리드에서는 허용치 않음
if ($output->columns[$i]['name'] == $name) break;
}
if ($i < $key) continue; // 중복이 발견되면 이후의 설정은 무시
if(strpos($name,'.')!==false&&strpos($value,'.')!==false) $column_list[] = $name.' = '.$value;
else {
if($output->column_type[$name]!='number') {
@ -543,6 +547,17 @@
$table_list[] = '"'.$this->prefix.$val.'" as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' "'.$this->prefix.$output->tables[$key].'" as '.$key . ' on (' . $condition . ')';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -572,9 +587,9 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -597,7 +612,7 @@
else {
if ($condition)
$query = sprintf('%s and inst_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count);
else
else
$query = sprintf('%s where inst_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count);
}
}
@ -630,7 +645,7 @@
$output = "<div style='text-align: left;'>\n";
$output .= "<b>Backtrace:</b><br />\n";
$backtrace = debug_backtrace();
foreach ($backtrace as $bt) {
$args = '';
foreach ($bt['args'] as $a) {
@ -672,18 +687,18 @@
$output .= "</div>\n";
return $output;
}
/**
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf('select count(*) as "count" from %s %s', implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$result = $this->_query($count_query);
@ -707,7 +722,7 @@
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -724,7 +739,7 @@
else {
if ($condition)
$query = sprintf('%s and inst_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count);
else
else
$query = sprintf('%s where inst_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count);
}
}

View file

@ -89,7 +89,7 @@
// get server version and implementation strings
$server_info = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
ibase_service_detach($service);
}
}
else {
$this->setError(ibase_errcode(), ibase_errmsg());
return;
@ -341,7 +341,7 @@
/**
* @brief 1 증가되는 sequence값을 return (firebird의 generator 값을 증가)
**/
function getNextSequence() {
function getNextSequence() {
$gen = "GEN_".$this->prefix."sequence_ID";
$sequence = ibase_gen_id($gen, 1);
return $sequence;
@ -509,7 +509,7 @@
if($this->column_type[$type]=='INTEGER') $size = null;
else if($this->column_type[$type]=='VARCHAR' && !$size) $size = 256;
$column_schema[] = sprintf('"%s" %s%s %s %s',
$name,
$this->column_type[$type],
@ -540,8 +540,8 @@
//commit();
@ibase_commit($this->fd);
if(!$output) return false;
if(count($index_list)) {
if(count($index_list)) {
foreach($index_list as $key => $val) {
// index name = prefix + table name + index_list
// index name 크기가 31byte로 제한되어 있어 중복되지 않을만큼 테이블명을 줄임
@ -567,7 +567,7 @@
if(!$output) return false;
}
}
foreach($auto_increment_list as $increment) {
$schema = sprintf('CREATE GENERATOR GEN_%s_ID;', $table_name);
$output = $this->_query($schema);
@ -598,8 +598,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
foreach($output->conditions as $val) {
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -609,15 +620,11 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue('"'.$name.'"', $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$name = $this->autoQuotes($name);
$value = $this->autoValueQuotes($value, $output);
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
$sub_condition .= $str;
@ -627,8 +634,6 @@
$condition .= '('.$sub_condition.')';
}
}
if($condition) $condition = ' Where '.$condition;
return $condition;
}
@ -641,7 +646,7 @@
$table_list[] = '"'.$this->prefix.$val.'"';
}
// 컬럼 정리
// 컬럼 정리
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -752,9 +757,21 @@
// 테이블 정리
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = sprintf("\"%s%s\" as \"%s\"", $this->prefix, $val, $key);
$table_list[] = sprintf("\"%s%s\" as \"%s\"", $this->prefix, $val, $key);
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' "'.$this->prefix.$output->_tables[$key].'" as '.$key . ' on (' . $condition . ')';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -762,7 +779,7 @@
foreach($output->columns as $key => $val) {
$name = $val['name'];
$alias = $val['alias'];
if($alias == "")
$column_list[] = $this->autoQuotes($name);
else
@ -773,7 +790,7 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
if($output->order) {
@ -792,7 +809,7 @@
if($output->list_count['value']) $limit = sprintf('FIRST %d', $output->list_count['value']);
else $limit = '';
$query = sprintf("select %s %s from %s %s", $limit, $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if($output->groups) {
foreach($output->groups as $key => $val) {
@ -825,11 +842,11 @@
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf('select count(*) as "count" from %s %s;', implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$result = $this->_query($count_query);
@ -868,8 +885,8 @@
}
}
$limit = sprintf('FIRST %d SKIP %d ', $list_count, $start_count);
$query = sprintf('SELECT %s %s FROM %s %s', $limit, $columns, implode(',',$table_list), $condition);
$limit = sprintf('FIRST %d SKIP %d ', $list_count, $start_count);
$query = sprintf('SELECT %s %s FROM %s %s %s', $limit, $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if($output->groups) {
foreach($output->groups as $key => $val) {

View file

@ -376,8 +376,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
foreach($output->conditions as $val) {
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -387,10 +398,9 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
@ -401,8 +411,6 @@
$condition .= '('.$sub_condition.')';
}
}
if($condition) $condition = ' where '.$condition;
return $condition;
}
@ -493,6 +501,16 @@
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' `'.$this->prefix.$output->_tables[$key].'` as '.$key . ' on (' . $condition . ')';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -515,7 +533,7 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
if($output->order) {
@ -530,7 +548,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -558,11 +576,11 @@
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$result = $this->_query($count_query);
@ -599,7 +617,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -611,7 +629,6 @@
}
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
$result = $this->_query($query);
if($this->isError()) {
$buff = new Object();

View file

@ -385,8 +385,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
foreach($output->conditions as $val) {
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -396,10 +407,10 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
@ -410,8 +421,6 @@
$condition .= '('.$sub_condition.')';
}
}
if($condition) $condition = ' where '.$condition;
return $condition;
}
@ -502,6 +511,17 @@
$table_list[] = '`'.$this->prefix.$val.'` as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' `'.$this->prefix.$output->_tables[$key].'` as '.$key . ' on (' . $condition . ')';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -524,7 +544,8 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
if($output->order) {
@ -539,7 +560,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -567,11 +588,11 @@
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$result = $this->_query($count_query);
@ -608,7 +629,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
if($output->order) {

View file

@ -69,20 +69,20 @@
* @brief DB 접속
**/
function _connect() {
// pg용 connection string
$conn_string = "";
// pg용 connection string
$conn_string = "";
// db 정보가 없으면 무시
if(!$this->hostname || !$this->userid || !$this->database) return;
// 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" : "";
// 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" : "";
// 접속시도
// 접속시도
$this->fd = @pg_connect($conn_string);
if(!$this->fd || pg_connection_status($this->fd) != PGSQL_CONNECTION_OK) {
$this->setError(-1, "CONNECTION FAILURE");
@ -314,10 +314,10 @@
// 테이블 생성 schema 작성
$table_name = $xml_obj->table->attrs->name;
if($table_name == 'sequence') {
if($table_name == 'sequence') {
$query = sprintf('create sequence %s', $this->prefix.$table_name);
return $this->_query($query);
}
return $this->_query($query);
}
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;
@ -336,7 +336,7 @@
$default = $column->attrs->default;
$auto_increment = $column->attrs->auto_increment;
if($type == "bignumber" || $type == "number") $size = 0;
if($type == "bignumber" || $type == "number") $size = 0;
$column_schema[] = sprintf('%s %s%s %s %s',
$name,
@ -361,7 +361,7 @@
}
}
$schema = sprintf('create table %s (%s%s);', $this->addQuotes($table_name), "\n", implode($column_schema,",\n"));
$output = $this->_query($schema);
@ -381,8 +381,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
foreach($output->conditions as $val) {
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -392,10 +403,10 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
@ -406,11 +417,10 @@
$condition .= '('.$sub_condition.')';
}
}
if($condition) $condition = ' where '.$condition;
return $condition;
}
/**
* @brief insertAct 처리
**/
@ -420,7 +430,7 @@
$table_list[] = $this->prefix.$val;
}
// 컬럼 정리
// 컬럼 정리
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
@ -446,7 +456,7 @@
$table_list[] = $this->prefix.$val.' as '.$key;
}
// 컬럼 정리
// 컬럼 정리
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
@ -498,6 +508,18 @@
$table_list[] = $this->prefix.$val.' as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' '.$this->prefix.$output->_tables[$key].' as '.$key . ' on (' . $condition . ')';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -520,7 +542,7 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
if($output->order) {
@ -535,7 +557,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -560,11 +582,11 @@
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$result = $this->_query($count_query);
@ -601,7 +623,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));

View file

@ -357,8 +357,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
foreach($output->conditions as $val) {
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -368,10 +379,10 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
@ -382,8 +393,6 @@
$condition .= '('.$sub_condition.')';
}
}
if($condition) $condition = ' where '.$condition;
return $condition;
}
@ -509,6 +518,17 @@
$table_list[] = $this->prefix.$val.' as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' '.$this->prefix.$output->_tables[$key].' as '.$key . ' on ' . $condition . '';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -531,7 +551,7 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
if($output->order) {
@ -546,7 +566,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -574,12 +594,14 @@
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$result = $this->_query($count_query);
$count_output = $this->_fetch($result);
@ -615,7 +637,8 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));

View file

@ -386,8 +386,19 @@
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
foreach($output->conditions as $val) {
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
@ -397,12 +408,11 @@
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($output->column_type,$name);
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $output->column_type);
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
$sub_condition .= $str;
@ -412,8 +422,6 @@
$condition .= '('.$sub_condition.')';
}
}
if($condition) $condition = ' where '.$condition;
return $condition;
}
@ -550,6 +558,19 @@
$table_list[] = $this->prefix.$val.' as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' '.$this->prefix.$output->_tables[$key].' as '.$key . ' on (' . $condition . ')';
}
}
if(!$output->columns) {
$columns = '*';
} else {
@ -572,7 +593,7 @@
$condition = $this->getCondition($output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $condition, $output);
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, ,$left_join, $condition, $output);
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
if($output->order) {
@ -587,7 +608,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
@ -615,11 +636,11 @@
*
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
**/
function _getNavigationData($table_list, $columns, $condition, $output) {
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
// 전체 개수를 구함
$count_query = sprintf("select count(*) as count from %s %s", implode(',',$table_list), $condition);
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$total_count = $this->getCountCache($output->tables, $condition);
if($total_count === false) {
$this->_prepare($count_query);
@ -656,7 +677,7 @@
}
}
$query = sprintf("select %s from %s %s", $columns, implode(',',$table_list), $condition);
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));