mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-29 15:22:15 +09:00
Merged 1.5.0-DB branch into 1.5.0 - added new DB classes.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8697 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
commit
c9203dc356
105 changed files with 6279 additions and 3467 deletions
|
|
@ -51,7 +51,7 @@
|
|||
$this->_setDBInfo();
|
||||
$this->_connect();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief create an instance of this class
|
||||
*/
|
||||
|
|
@ -190,7 +190,7 @@
|
|||
{
|
||||
if (!$query || !$this->isConnected ()) return;
|
||||
|
||||
// Notify to start a query execution
|
||||
// Notify to start a query execution
|
||||
$this->actStart ($query);
|
||||
|
||||
// Execute the query
|
||||
|
|
@ -207,16 +207,18 @@
|
|||
$this->actFinish ();
|
||||
|
||||
// Return the result
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fetch the result
|
||||
**/
|
||||
function _fetch($result)
|
||||
function _fetch($result, $arrayIndexEndValue = NULL)
|
||||
{
|
||||
if (!$this->isConnected() || $this->isError() || !$result) return;
|
||||
|
||||
// TODO Improve this piece of code
|
||||
// This code trims values from char type columns
|
||||
$col_types = cubrid_column_types ($result);
|
||||
$col_names = cubrid_column_names ($result);
|
||||
$max = count ($col_types);
|
||||
|
|
@ -234,14 +236,16 @@
|
|||
}
|
||||
}
|
||||
|
||||
$output[] = $tmp;
|
||||
if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $tmp;
|
||||
else $output[] = $tmp;
|
||||
}
|
||||
|
||||
unset ($char_type_fields);
|
||||
|
||||
if ($result) cubrid_close_request($result);
|
||||
|
||||
if (count ($output) == 1) return $output[0];
|
||||
if($arrayIndexEndValue !== null && count($output) == 1) return $output[$arrayIndexEndValue + 1];
|
||||
else if (count($output) == 1) return $output[0];
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -445,7 +449,6 @@
|
|||
if (!file_exists ($file_name)) return;
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile ($file_name);
|
||||
|
||||
return $this->_createTable ($buff);
|
||||
}
|
||||
|
||||
|
|
@ -561,132 +564,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return the condition
|
||||
**/
|
||||
function getCondition ($output)
|
||||
{
|
||||
if (!$output->conditions) return;
|
||||
$condition = $this->_getCondition ($output->conditions, $output->column_type, $output);
|
||||
if ($condition) $condition = ' where '.$condition;
|
||||
|
||||
return $condition;
|
||||
}
|
||||
|
||||
function _getCondition ($conditions, $column_type, &$output)
|
||||
{
|
||||
$condition = '';
|
||||
|
||||
foreach ($conditions as $val) {
|
||||
$sub_condition = '';
|
||||
|
||||
foreach ($val['condition'] as $v) {
|
||||
if (!isset ($v['value'])) continue;
|
||||
if ($v['value'] === '') continue;
|
||||
if(!in_array(gettype($v['value']), array('string', 'integer', 'double', 'array'))) continue;
|
||||
|
||||
$name = $v['column'];
|
||||
$operation = $v['operation'];
|
||||
$value = $v['value'];
|
||||
$type = $this->getColumnType ($column_type, $name);
|
||||
$pipe = $v['pipe'];
|
||||
$value = $this->getConditionValue ($name, $value, $operation, $type, $column_type);
|
||||
|
||||
if (!$value) {
|
||||
$value = $v['value'];
|
||||
if (strpos ($value, '(')) {
|
||||
$valuetmp = $value;
|
||||
}
|
||||
elseif (strpos ($value, ".") === false) {
|
||||
$valuetmp = $value;
|
||||
}
|
||||
else {
|
||||
$valuetmp = '"'.str_replace('.', '"."', $value).'"';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tmp = explode('.',$value);
|
||||
|
||||
if (count($tmp)==2) {
|
||||
$table = $tmp[0];
|
||||
$column = $tmp[1];
|
||||
|
||||
if ($column_type[$column] && (in_array ($table, $output->tables) ||
|
||||
array_key_exists($table, $output->tables))) {
|
||||
$valuetmp = sprintf('"%s"."%s"', $table, $column);
|
||||
}
|
||||
else {
|
||||
$valuetmp = $value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$valuetmp = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos ($name, '(') > 0) {
|
||||
$nametmp = $name;
|
||||
}
|
||||
elseif (strpos ($name, ".") === false) {
|
||||
$nametmp = '"'.$name.'"';
|
||||
}
|
||||
else {
|
||||
$nametmp = '"'.str_replace('.', '"."', $name).'"';
|
||||
}
|
||||
$str = $this->getConditionPart ($nametmp, $valuetmp, $operation);
|
||||
if ($sub_condition) $sub_condition .= ' '.$pipe.' ';
|
||||
$sub_condition .= $str;
|
||||
}
|
||||
|
||||
if ($sub_condition) {
|
||||
if ($condition && $val['pipe']) {
|
||||
$condition .= ' '.$val['pipe'].' ';
|
||||
}
|
||||
$condition .= '('.$sub_condition.')';
|
||||
}
|
||||
}
|
||||
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief handles insertAct
|
||||
**/
|
||||
function _executeInsertAct ($output)
|
||||
function _executeInsertAct($queryObject)
|
||||
{
|
||||
// tables
|
||||
foreach ($output->tables as $val) {
|
||||
$table_list[] = '"'.$this->prefix.$val.'"';
|
||||
}
|
||||
|
||||
// columns
|
||||
foreach ($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
//if ($this->getColumnType ($output->column_type, $name) != 'number')
|
||||
if ($output->column_type[$name] != 'number') {
|
||||
if (!is_null($value)) {
|
||||
$value = "'" . $this->addQuotes($value) ."'";
|
||||
}
|
||||
else {
|
||||
if ($val['notnull']=='notnull') {
|
||||
$value = "''";
|
||||
}
|
||||
else {
|
||||
//$value = 'null';
|
||||
$value = "''";
|
||||
}
|
||||
}
|
||||
}
|
||||
else $this->_filterNumber($value);
|
||||
|
||||
$column_list[] = '"'.$name.'"';
|
||||
$value_list[] = $value;
|
||||
}
|
||||
|
||||
$query = sprintf ("insert into %s (%s) values (%s);", implode(',', $table_list), implode(',', $column_list), implode(',', $value_list));
|
||||
$query = $this->getInsertSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
|
||||
$result = $this->_query ($query);
|
||||
if ($result && !$this->transaction_started) {
|
||||
@cubrid_commit ($this->fd);
|
||||
|
|
@ -698,109 +588,29 @@
|
|||
/**
|
||||
* @brief handles updateAct
|
||||
**/
|
||||
function _executeUpdateAct ($output)
|
||||
function _executeUpdateAct($queryObject)
|
||||
{
|
||||
// tables
|
||||
foreach ($output->tables as $key => $val) {
|
||||
$table_list[] = '"'.$this->prefix.$val.'" as "'.$key.'"';
|
||||
}
|
||||
$query = $this->getUpdateSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
$check_click_count = true;
|
||||
$result = $this->_query($query);
|
||||
|
||||
// columns
|
||||
foreach ($output->columns as $key => $val) {
|
||||
if (!isset ($val['value'])) continue;
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
|
||||
if (substr ($value, -2) != '+1' || $output->column_type[$name] != 'number') {
|
||||
$check_click_count = false;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $key; $i++) {
|
||||
// not allows to define the same property repeatedly in a single query in CUBRID
|
||||
if ($output->columns[$i]['name'] == $name) break;
|
||||
}
|
||||
if ($i < $key) continue; // ignore the rest of properties if duplicated property found
|
||||
|
||||
if (strpos ($name, '.') !== false && strpos ($value, '.') !== false) {
|
||||
$column_list[] = $name.' = '.$value;
|
||||
}
|
||||
else {
|
||||
if ($output->column_type[$name] != 'number') {
|
||||
$check_column = false;
|
||||
$value = "'".$this->addQuotes ($value)."'";
|
||||
}
|
||||
else $this->_filterNumber($value);
|
||||
|
||||
$column_list[] = sprintf ("\"%s\" = %s", $name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// conditional clause
|
||||
$condition = $this->getCondition ($output);
|
||||
|
||||
$check_click_count_condition = false;
|
||||
if ($check_click_count) {
|
||||
foreach ($output->conditions as $val) {
|
||||
if ($val['pipe'] == 'or') {
|
||||
$check_click_count_condition = false;
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($val['condition'] as $v) {
|
||||
if ($v['operation'] == 'equal') {
|
||||
$check_click_count_condition = true;
|
||||
}
|
||||
else {
|
||||
if ($v['operation'] == 'in' && !strpos ($v['value'], ',')) {
|
||||
$check_click_count_condition = true;
|
||||
}
|
||||
else {
|
||||
$check_click_count_condition = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($v['pipe'] == 'or') {
|
||||
$check_click_count_condition = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($check_click_count&& $check_click_count_condition && count ($output->tables) == 1 && count ($output->conditions) > 0 && count ($output->groups) == 0 && count ($output->order) == 0) {
|
||||
foreach ($output->columns as $v) {
|
||||
$incr_columns[] = 'incr("'.$v['name'].'")';
|
||||
}
|
||||
|
||||
$query = sprintf ('select %s from %s %s', join (',', $incr_columns), implode(',', $table_list), $condition);
|
||||
}
|
||||
else {
|
||||
$query = sprintf ("update %s set %s %s", implode (',', $table_list), implode (',', $column_list), $condition);
|
||||
}
|
||||
|
||||
$result = $this->_query ($query);
|
||||
if ($result && !$this->transaction_started) @cubrid_commit ($this->fd);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief handles deleteAct
|
||||
**/
|
||||
function _executeDeleteAct ($output)
|
||||
function _executeDeleteAct($queryObject)
|
||||
{
|
||||
// tables
|
||||
foreach ($output->tables as $val) {
|
||||
$table_list[] = '"'.$this->prefix.$val.'"';
|
||||
}
|
||||
$query = $this->getDeleteSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
// Conditional clauses
|
||||
$condition = $this->getCondition ($output);
|
||||
|
||||
$query = sprintf ("delete from %s %s", implode (',',$table_list), $condition);
|
||||
$result = $this->_query ($query);
|
||||
|
||||
if ($result && !$this->transaction_started) @cubrid_commit ($this->fd);
|
||||
|
||||
return $result;
|
||||
|
|
@ -810,454 +620,73 @@
|
|||
* @brief Handle selectAct
|
||||
*
|
||||
* to get a specific page list easily in select statement,\n
|
||||
* a method, navigation, is used
|
||||
* a method, navigation, is used
|
||||
**/
|
||||
function _executeSelectAct ($output)
|
||||
{
|
||||
// tables
|
||||
$table_list = array ();
|
||||
foreach ($output->tables as $key => $val) {
|
||||
$table_list[] = '"'.$this->prefix.$val.'" as "'.$key.'"';
|
||||
}
|
||||
$left_join = array ();
|
||||
// why???
|
||||
$left_tables = (array) $output->left_tables;
|
||||
// TODO Rewrite with Query object as input
|
||||
function _executeSelectAct($queryObject){
|
||||
$query = $this->getSelectSql($queryObject);
|
||||
if(is_a($query, 'Object')) return;
|
||||
|
||||
foreach ($left_tables as $key => $val) {
|
||||
$condition = $this->_getCondition ($output->left_conditions[$key], $output->column_type, $output);
|
||||
if ($condition) {
|
||||
$left_join[] = $val.' "'.$this->prefix.$output->_tables[$key]. '" "'.$key.'" on ('.$condition.')';
|
||||
}
|
||||
}
|
||||
|
||||
$click_count = array();
|
||||
if(!$output->columns){
|
||||
$output->columns = array(array('name'=>'*'));
|
||||
}
|
||||
|
||||
$column_list = array ();
|
||||
foreach ($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
|
||||
$click_count = '%s';
|
||||
if ($val['click_count'] && count ($output->conditions) > 0) {
|
||||
$click_count = 'incr(%s)';
|
||||
}
|
||||
|
||||
$alias = $val['alias'] ? sprintf ('"%s"', $val['alias']) : null;
|
||||
$_alias = $val['alias'];
|
||||
|
||||
if ($name == '*') {
|
||||
$column_list[] = $name;
|
||||
}
|
||||
elseif (strpos ($name, '.') === false && strpos ($name, '(') === false) {
|
||||
$name = sprintf ($click_count,$name);
|
||||
if ($alias) {
|
||||
$column_list[$alias] = sprintf('"%s" as %s', $name, $alias);
|
||||
}
|
||||
else {
|
||||
$column_list[] = sprintf ('"%s"', $name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (strpos ($name, '.') != false) {
|
||||
list ($prefix, $name) = explode('.', $name);
|
||||
if (($now_matchs = preg_match_all ("/\(/", $prefix, $xtmp)) > 0) {
|
||||
if ($now_matchs == 1) {
|
||||
$tmpval = explode ("(", $prefix);
|
||||
$tmpval[1] = sprintf ('"%s"', $tmpval[1]);
|
||||
$prefix = implode ("(", $tmpval);
|
||||
$tmpval = explode (")", $name);
|
||||
$tmpval[0] = sprintf ('"%s"', $tmpval[0]);
|
||||
$name = implode (")", $tmpval);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$prefix = sprintf ('"%s"', $prefix);
|
||||
$name = ($name == '*') ? $name : sprintf('"%s"',$name);
|
||||
}
|
||||
$xtmp = null;
|
||||
$now_matchs = null;
|
||||
if($alias) $column_list[$_alias] = sprintf ($click_count, sprintf ('%s.%s', $prefix, $name)) . ($alias ? sprintf (' as %s',$alias) : '');
|
||||
else $column_list[] = sprintf ($click_count, sprintf ('%s.%s', $prefix, $name));
|
||||
}
|
||||
elseif (($now_matchs = preg_match_all ("/\(/", $name, $xtmp)) > 0) {
|
||||
if ($now_matchs == 1 && preg_match ("/[a-zA-Z0-9]*\(\*\)/", $name) < 1) {
|
||||
$open_pos = strpos ($name, "(");
|
||||
$close_pos = strpos ($name, ")");
|
||||
|
||||
if (preg_match ("/,/", $name)) {
|
||||
$tmp_func_name = sprintf ('%s', substr ($name, 0, $open_pos));
|
||||
$tmp_params = sprintf ('%s', substr ($name, $open_pos + 1, $close_pos - $open_pos - 1));
|
||||
$tmpval = null;
|
||||
$tmpval = explode (',', $tmp_params);
|
||||
|
||||
foreach ($tmpval as $tmp_param) {
|
||||
$tmp_param_list[] = (!is_numeric ($tmp_param)) ? sprintf ('"%s"', $tmp_param) : $tmp_param;
|
||||
}
|
||||
|
||||
$tmpval = implode (',', $tmp_param_list);
|
||||
$name = sprintf ('%s(%s)', $tmp_func_name, $tmpval);
|
||||
}
|
||||
else {
|
||||
$name = sprintf ('%s("%s")', substr ($name, 0, $open_pos), substr ($name, $open_pos + 1, $close_pos - $open_pos - 1));
|
||||
}
|
||||
}
|
||||
|
||||
if($alias) $column_list[$_alias] = sprintf ($click_count, $name). ($alias ? sprintf (' as %s', $alias) : '');
|
||||
else $column_list[] = sprintf ($click_count, $name);
|
||||
}
|
||||
else {
|
||||
if($alias) $column_list[$_alias] = sprintf($click_count, $name). ($alias ? sprintf(' as %s',$alias) : '');
|
||||
else $column_list[] = sprintf($click_count, $name);
|
||||
}
|
||||
}
|
||||
$columns = implode (',', $column_list);
|
||||
}
|
||||
|
||||
$condition = $this->getCondition ($output);
|
||||
|
||||
$output->column_list = $column_list;
|
||||
if ($output->list_count && $output->page) {
|
||||
return ($this->_getNavigationData($table_list, $columns, $left_join, $condition, $output));
|
||||
}
|
||||
|
||||
if ($output->order) {
|
||||
$conditions = $this->getConditionList($output);
|
||||
//if(in_array('list_order', $conditions) || in_array('update_order', $conditions)) {
|
||||
foreach($output->order as $key => $val) {
|
||||
$col = $val[0];
|
||||
if(!in_array($col, array('list_order','update_order'))) continue;
|
||||
if ($condition) $condition .= sprintf(' and %s < 2100000000 ', $col);
|
||||
else $condition = sprintf(' where %s < 2100000000 ', $col);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
if (count ($output->groups)) {
|
||||
foreach ($output->groups as $key => $value) {
|
||||
if (strpos ($value, '.')) {
|
||||
$tmp = explode ('.', $value);
|
||||
$tmp[0] = sprintf ('"%s"', $tmp[0]);
|
||||
$tmp[1] = sprintf ('"%s"', $tmp[1]);
|
||||
$value = implode ('.', $tmp);
|
||||
}
|
||||
elseif (strpos ($value, '(')) {
|
||||
$value = $value;
|
||||
}
|
||||
else {
|
||||
$value = sprintf ('"%s"', $value);
|
||||
}
|
||||
$output->groups[$key] = $value;
|
||||
|
||||
|
||||
if(count($output->arg_columns))
|
||||
{
|
||||
if($column_list[$value]) $output->arg_columns[] = $column_list[$value];
|
||||
}
|
||||
}
|
||||
$groupby_query = sprintf ('group by %s', implode(',', $output->groups));
|
||||
}
|
||||
|
||||
|
||||
// apply when using list_count
|
||||
if ($output->list_count['value']) {
|
||||
$start_count = 0;
|
||||
$list_count = $output->list_count['value'];
|
||||
|
||||
if ($output->order) {
|
||||
foreach ($output->order as $val) {
|
||||
if (strpos ($val[0], '.')) {
|
||||
$tmpval = explode ('.', $val[0]);
|
||||
$tmpval[0] = sprintf ('"%s"', $tmpval[0]);
|
||||
$tmpval[1] = sprintf ('"%s"', $tmpval[1]);
|
||||
$val[0] = implode ('.', $tmpval);
|
||||
}
|
||||
elseif (strpos ($val[0], '(')) $val[0] = $val[0];
|
||||
elseif ($val[0] == 'count') $val[0] = 'count (*)';
|
||||
else $val[0] = sprintf ('"%s"', $val[0]);
|
||||
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
|
||||
}
|
||||
if (count($index_list))
|
||||
$orderby_query = ' order by '.implode(',', $index_list);
|
||||
$orderby_query = sprintf ('%s for orderby_num() between %d and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
else {
|
||||
if (count ($output->groups)) {
|
||||
$orderby_query = sprintf ('%s having groupby_num() between %d'. ' and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
else {
|
||||
if ($condition) {
|
||||
$orderby_query = sprintf ('%s and inst_num() between %d'. ' and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
else {
|
||||
$orderby_query = sprintf ('%s where inst_num() between %d'. ' and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($output->order) {
|
||||
foreach ($output->order as $val) {
|
||||
if (strpos ($val[0], '.')) {
|
||||
$tmpval = explode ('.', $val[0]);
|
||||
$tmpval[0] = sprintf ('"%s"', $tmpval[0]);
|
||||
$tmpval[1] = sprintf ('"%s"', $tmpval[1]);
|
||||
$val[0] = implode ('.', $tmpval);
|
||||
}
|
||||
elseif (strpos ($val[0], '(')) $val[0] = $val[0];
|
||||
elseif ($val[0] == 'count') $val[0] = 'count (*)';
|
||||
else $val[0] = sprintf ('"%s"', $val[0]);
|
||||
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
|
||||
|
||||
if(count($output->arg_columns) && $column_list[$val]) $output->arg_columns[] = $column_list[$key];
|
||||
}
|
||||
|
||||
if (count ($index_list)) {
|
||||
$orderby_query = ' order by '.implode(',', $index_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(count($output->arg_columns))
|
||||
{
|
||||
$columns = array();
|
||||
foreach($output->arg_columns as $col){
|
||||
unset($tmpCol);
|
||||
$tmpCol = explode('.', $col);
|
||||
if(isset($tmpCol[1])) $col = $tmpCol[1];
|
||||
|
||||
if(strpos($col,'"')===false && strpos($col,' ')==false) $col = '"'.$col.'"';
|
||||
if(isset($tmpCol[1])) $col = $tmpCol[0].'.'.$col;
|
||||
|
||||
$columns[] = $col;
|
||||
}
|
||||
|
||||
$columns = join(',',$columns);
|
||||
}
|
||||
|
||||
$query = sprintf ("select %s from %s %s %s %s", $columns, implode (',',$table_list), implode (' ',$left_join), $condition, $groupby_query.$orderby_query);
|
||||
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result = $this->_query ($query);
|
||||
if ($this->isError ()) return;
|
||||
$data = $this->_fetch ($result);
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->data = $data;
|
||||
|
||||
return $buff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief displays the current stack trace. Fetch the result
|
||||
**/
|
||||
function backtrace ()
|
||||
{
|
||||
$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) {
|
||||
if (!empty ($args)) {
|
||||
$args .= ', ';
|
||||
}
|
||||
switch (gettype ($a)) {
|
||||
case 'integer':
|
||||
case 'double':
|
||||
$args .= $a;
|
||||
break;
|
||||
case 'string':
|
||||
$a = htmlspecialchars (substr ($a, 0, 64)).
|
||||
((strlen ($a) > 64) ? '...' : '');
|
||||
$args .= "\"$a\"";
|
||||
break;
|
||||
case 'array':
|
||||
$args .= 'Array ('. count ($a).')';
|
||||
break;
|
||||
case 'object':
|
||||
$args .= 'Object ('.get_class ($a).')';
|
||||
break;
|
||||
case 'resource':
|
||||
$args .= 'Resource ('.strstr ($a, '#').')';
|
||||
break;
|
||||
case 'boolean':
|
||||
$args .= $a ? 'True' : 'False';
|
||||
break;
|
||||
case 'NULL':
|
||||
$args .= 'Null';
|
||||
break;
|
||||
default:
|
||||
$args .= 'Unknown';
|
||||
}
|
||||
}
|
||||
$output .= "<br />\n";
|
||||
$output .= "<b>file:</b> ".$bt['line']." - ". $bt['file']."<br />\n";
|
||||
$output .= "<b>call:</b> ".$bt['class']. $bt['type'].$bt['function'].$args."<br />\n";
|
||||
}
|
||||
$output .= "</div>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief paginates when navigation info exists in the query xml
|
||||
*
|
||||
* it is convenient although its structure is not good .. -_-;
|
||||
**/
|
||||
function _getNavigationData ($table_list, $columns, $left_join, $condition, $output) {
|
||||
require_once (_XE_PATH_.'classes/page/PageHandler.class.php');
|
||||
|
||||
$column_list = $output->column_list;
|
||||
|
||||
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
|
||||
$count_query = sprintf('select count(*) as "count" from %s %s %s', implode(', ', $table_list), implode(' ', $left_join), $count_condition);
|
||||
if (count($output->groups)) {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$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 pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $list_count) + 1;
|
||||
}
|
||||
else {
|
||||
$total_page = 1;
|
||||
}
|
||||
|
||||
// check the page variables
|
||||
if ($page > $total_page) $page = $total_page;
|
||||
$start_count = ($page - 1) * $list_count;
|
||||
|
||||
if ($output->order) {
|
||||
$conditions = $this->getConditionList($output);
|
||||
//if(in_array('list_order', $conditions) || in_array('update_order', $conditions)) {
|
||||
foreach ($output->order as $key => $val) {
|
||||
$col = $val[0];
|
||||
if(!in_array($col, array('list_order','update_order'))) continue;
|
||||
if($condition) $condition .= sprintf(' and %s < 2100000000 ', $col);
|
||||
else $condition = sprintf(' where %s < 2100000000 ', $col);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
if (count ($output->groups)) {
|
||||
foreach ($output->groups as $key => $value) {
|
||||
if (strpos ($value, '.')) {
|
||||
$tmp = explode ('.', $value);
|
||||
$tmp[0] = sprintf ('"%s"', $tmp[0]);
|
||||
$tmp[1] = sprintf ('"%s"', $tmp[1]);
|
||||
$value = implode ('.', $tmp);
|
||||
}
|
||||
elseif (strpos ($value, '(')) $value = $value;
|
||||
else $value = sprintf ('"%s"', $value);
|
||||
$output->groups[$key] = $value;
|
||||
}
|
||||
|
||||
$groupby_query = sprintf (' group by %s', implode (',', $output->groups));
|
||||
}
|
||||
|
||||
if ($output->order) {
|
||||
foreach ($output->order as $val) {
|
||||
if (strpos ($val[0], '.')) {
|
||||
$tmpval = explode ('.', $val[0]);
|
||||
$tmpval[0] = sprintf ('"%s"', $tmpval[0]);
|
||||
$tmpval[1] = sprintf ('"%s"', $tmpval[1]);
|
||||
$val[0] = implode ('.', $tmpval);
|
||||
}
|
||||
elseif (strpos ($val[0], '(')) $val[0] = $val[0];
|
||||
elseif ($val[0] == 'count') $val[0] = 'count (*)';
|
||||
else $val[0] = sprintf ('"%s"', $val[0]);
|
||||
$index_list[] = sprintf ('%s %s', $val[0], $val[1]);
|
||||
}
|
||||
|
||||
if (count ($index_list)) {
|
||||
$orderby_query = ' order by '.implode(',', $index_list);
|
||||
}
|
||||
|
||||
$orderby_query = sprintf ('%s for orderby_num() between %d and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
else {
|
||||
if (count($output->groups)) {
|
||||
$orderby_query = sprintf ('%s having groupby_num() between %d and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
else {
|
||||
if ($condition) {
|
||||
$orderby_query = sprintf ('%s and inst_num() between %d and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
else {
|
||||
$orderby_query = sprintf('%s where inst_num() between %d and %d', $orderby_query, $start_count + 1, $list_count + $start_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(count($output->arg_columns))
|
||||
{
|
||||
$columns = array();
|
||||
foreach($output->arg_columns as $col){
|
||||
unset($tmpCol);
|
||||
$tmpCol = explode('.', $col);
|
||||
if(isset($tmpCol[1])) $col = $tmpCol[1];
|
||||
|
||||
if(strpos($col,'"')===false && strpos($col,' ')==false) $col = '"'.$col.'"';
|
||||
if(isset($tmpCol[1])) $col = $tmpCol[0].'.'.$col;
|
||||
|
||||
$columns[] = $col;
|
||||
}
|
||||
|
||||
$columns = join(',',$columns);
|
||||
}
|
||||
|
||||
$query = sprintf ("select %s from %s %s %s %s", $columns, implode (',',$table_list), implode (' ',$left_join), $condition, $groupby_query.$orderby_query);
|
||||
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result = $this->_query ($query);
|
||||
|
||||
if ($this->isError ()) {
|
||||
if ($this->isError ())
|
||||
return $this->queryError($queryObject);
|
||||
else
|
||||
return $this->queryPageLimit($queryObject, $result);
|
||||
}
|
||||
|
||||
function queryError($queryObject){
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()){
|
||||
$buff = new Object ();
|
||||
$buff->total_count = 0;
|
||||
$buff->total_page = 0;
|
||||
$buff->page = 1;
|
||||
$buff->data = array ();
|
||||
$buff->page_navigation = new PageHandler (/*$total_count*/0, /*$total_page*/1, /*$page*/1, /*$page_count*/10);//default page handler values
|
||||
return $buff;
|
||||
}else
|
||||
return;
|
||||
}
|
||||
|
||||
function queryPageLimit($queryObject, $result){
|
||||
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
|
||||
// Total count
|
||||
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString()));
|
||||
if ($queryObject->getGroupByString() != '') {
|
||||
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
|
||||
}
|
||||
|
||||
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
|
||||
$result_count = $this->_query($count_query);
|
||||
$count_output = $this->_fetch($result_count);
|
||||
$total_count = (int)$count_output->count;
|
||||
|
||||
// Total pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
|
||||
} else $total_page = 1;
|
||||
|
||||
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
|
||||
$data = $this->_fetch($result, $virtual_no);
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $queryObject->getLimit()->page->getValue();
|
||||
$buff->data = $data;
|
||||
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page->getValue(), $queryObject->getLimit()->page_count);
|
||||
}else{
|
||||
$data = $this->_fetch($result);
|
||||
$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, $page_count);
|
||||
|
||||
return $buff;
|
||||
$buff->data = $data;
|
||||
}
|
||||
|
||||
$virtual_no = $total_count - ($page - 1) * $list_count;
|
||||
while ($tmp = cubrid_fetch ($result, CUBRID_OBJECT)) {
|
||||
if ($tmp) {
|
||||
foreach ($tmp as $k => $v) {
|
||||
$tmp->{$k} = rtrim($v);
|
||||
}
|
||||
}
|
||||
$data[$virtual_no--] = $tmp;
|
||||
}
|
||||
|
||||
$buff = new Object ();
|
||||
$buff->total_count = $total_count;
|
||||
$buff->total_page = $total_page;
|
||||
$buff->page = $page;
|
||||
$buff->data = $data;
|
||||
|
||||
$buff->page_navigation = new PageHandler ($total_count, $total_page, $page, $page_count);
|
||||
|
||||
return $buff;
|
||||
}
|
||||
|
||||
function getParser(){
|
||||
return new DBParser('"');
|
||||
}
|
||||
}
|
||||
|
||||
return new DBCubrid;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue