37 'bignumber' =>
'numeric(20)',
38 'number' =>
'integer',
39 'varchar' =>
'character varying',
40 'char' =>
'character',
41 'tinytext' =>
'character varying(256)',
42 'text' =>
'character varying(1073741823)',
43 'bigtext' =>
'character varying(1073741823)',
44 'date' =>
'character varying(14)',
81 $this->
setError(-1,
'database connect fail');
85 if(!defined(
'__CUBRID_VERSION__'))
87 $cubrid_version = cubrid_get_server_info(
$result);
88 $cubrid_version_elem = explode(
'.', $cubrid_version);
89 $cubrid_version = $cubrid_version_elem[0] .
'.' . $cubrid_version_elem[1] .
'.' . $cubrid_version_elem[2];
90 define(
'__CUBRID_VERSION__', $cubrid_version);
93 if(__CUBRID_VERSION__ >=
'8.4.0')
94 cubrid_set_autocommit(
$result, CUBRID_AUTOCOMMIT_TRUE);
109 $this->transaction_started = FALSE;
119 if(version_compare(PHP_VERSION,
"5.4.0",
"<") &&
120 get_magic_quotes_gpc())
122 $string = stripslashes(str_replace(
"\\",
"\\\\", $string));
125 if(!is_numeric($string))
136 $string = str_replace(
"'",
"''", $string);
149 if(__CUBRID_VERSION__ >=
'8.4.0')
153 if(!$transactionLevel)
155 cubrid_set_autocommit(
$connection, CUBRID_AUTOCOMMIT_FALSE);
174 $point = $transactionLevel - 1;
209 if($this->use_prepared_statements ==
'Y')
221 foreach($this->param as $param)
223 $value = $param->getUnescapedValue();
224 $type = $param->getType();
226 if($param->isColumnName())
234 $bind_type =
'numeric';
237 $bind_type =
'string';
240 $bind_type =
'string';
245 foreach($value as $v)
247 $bound = @cubrid_bind($req, ++$position, $v, $bind_type);
257 $bound = @cubrid_bind($req, ++$position, $value, $bind_type);
267 $result = @cubrid_execute($req);
294 $code = cubrid_error_code();
295 $msg = cubrid_error_msg();
314 if($this->use_prepared_statements ==
'Y')
321 $col_types = cubrid_column_types(
$result);
322 $col_names = cubrid_column_names(
$result);
323 $max = count($col_types);
325 for($count = 0; $count < $max; $count++)
327 if(preg_match(
"/^char/", $col_types[$count]) > 0)
329 $char_type_fields[] = $col_names[$count];
333 while($tmp = cubrid_fetch(
$result, CUBRID_OBJECT))
335 if(is_array($char_type_fields))
337 foreach($char_type_fields as $val)
339 $tmp->{$val} = rtrim($tmp->{$val});
343 if($arrayIndexEndValue)
345 $output[$arrayIndexEndValue--] = $tmp;
353 unset($char_type_fields);
357 cubrid_close_request($result);
363 if(isset($arrayIndexEndValue))
383 $this->_makeSequence();
385 $query = sprintf(
"select \"%ssequence\".\"nextval\" as \"seq\" from db_root", $this->prefix);
386 $result = $this->_query($query);
387 $output = $this->_fetch($result);
398 if($_GLOBALS[
'XE_EXISTS_SEQUENCE'])
402 $query = sprintf(
'select count(*) as "count" from "db_serial" where name=\'%ssequence\'', $this->prefix);
403 $result = $this->_query($query);
404 $output = $this->_fetch($result);
409 $query = sprintf(
'select max("a"."srl") as "srl" from ' .
410 '( select max("document_srl") as "srl" from ' .
411 '"%sdocuments" UNION ' .
412 'select max("comment_srl") as "srl" from ' .
413 '"%scomments" UNION ' .
414 'select max("member_srl") as "srl" from ' .
416 ') as "a"', $this->prefix, $this->prefix, $this->prefix);
418 $result = $this->_query($query);
419 $output = $this->_fetch($result);
427 $start = $srl + 1000000;
431 $query = sprintf(
'create serial "%ssequence" start with %s increment by 1 minvalue 1 maxvalue 10000000000000000000000000000000000000 nocycle;', $this->prefix, $start);
432 $this->_query($query);
435 $_GLOBALS[
'XE_EXISTS_SEQUENCE'] = TRUE;
445 if($target_name ==
'sequence')
447 $query = sprintf(
"select \"name\" from \"db_serial\" where \"name\" = '%s%s'", $this->prefix, $target_name);
451 $query = sprintf(
"select \"class_name\" from \"db_class\" where \"class_name\" = '%s%s'", $this->prefix, $target_name);
454 $result = $this->_query($query);
455 if(cubrid_num_rows($result) > 0)
466 cubrid_close_request($result);
482 function addColumn($table_name, $column_name, $type =
'number', $size =
'', $default = null, $notnull = FALSE)
484 $type = strtoupper($this->column_type[$type]);
485 if($type ==
'INTEGER')
490 $query = sprintf(
"alter class \"%s%s\" add \"%s\" ", $this->prefix, $table_name, $column_name);
492 if($type ==
'char' || $type ==
'varchar')
502 $query .= sprintf(
"%s(%s) ", $type, $size);
506 $query .= sprintf(
"%s ", $type);
511 if($type ==
'INTEGER' || $type ==
'BIGINT' || $type ==
'INT')
513 $query .= sprintf(
"default %d ", $default);
517 $query .= sprintf(
"default '%s' ", $default);
523 $query .=
"not null ";
526 return $this->_query($query);
537 $query = sprintf(
"alter class \"%s%s\" drop \"%s\" ", $this->prefix, $table_name, $column_name);
539 $this->_query($query);
550 $query = sprintf(
"select \"attr_name\" from \"db_attribute\" where " .
"\"attr_name\" ='%s' and \"class_name\" = '%s%s'", $column_name, $this->prefix, $table_name);
551 $result = $this->_query($query);
553 if(cubrid_num_rows($result) > 0)
564 cubrid_close_request($result);
580 function addIndex($table_name, $index_name, $target_columns, $is_unique = FALSE)
582 if(!is_array($target_columns))
584 $target_columns = array($target_columns);
587 $query = sprintf(
"create %s index \"%s\" on \"%s%s\" (%s);", $is_unique ?
'unique' :
'', $index_name, $this->prefix, $table_name,
'"' . implode(
'","', $target_columns) .
'"');
589 $this->_query($query);
599 function dropIndex($table_name, $index_name, $is_unique = FALSE)
601 $query = sprintf(
"drop %s index \"%s\" on \"%s%s\"", $is_unique ?
'unique' :
'', $index_name, $this->prefix, $table_name);
603 $this->_query($query);
614 $query = sprintf(
"select \"index_name\" from \"db_index\" where " .
"\"class_name\" = '%s%s' and (\"index_name\" = '%s' or \"index_name\" = '%s') ", $this->prefix, $table_name, $this->prefix . $index_name, $index_name);
615 $result = $this->_query($query);
622 $output = $this->_fetch($result);
638 select \"class_name\"
640 when substr(\"index_name\", 0, %d) = '%s'
641 then substr(\"index_name\", %d)
642 else \"index_name\" end as unprefixed_index_name
645 where \"class_name\" like %s
646 group by \"class_name\"
648 when substr(\"index_name\", 0, %d) = '%s'
649 then substr(\"index_name\", %d)
653 ", strlen($this->prefix)
655 , strlen($this->prefix) + 1
656 ,
"'" . $this->prefix .
'%' .
"'"
657 , strlen($this->prefix)
659 , strlen($this->prefix) + 1
661 $result = $this->_query($query);
668 $output = $this->_fetch($result);
676 $indexes_to_be_deleted = array(
$output);
680 $indexes_to_be_deleted =
$output;
683 foreach($indexes_to_be_deleted as $index)
685 $this->dropIndex(substr($index->class_name, strlen($this->prefix))
686 , $this->prefix . $index->unprefixed_index_name
687 , $index->is_unique ==
'YES' ? TRUE : FALSE);
700 return $this->_createTable($xml_doc);
710 if(!file_exists($file_name))
716 return $this->_createTable($buff);
732 $xml_obj = $oXml->parse($xml_doc);
734 $table_name = $xml_obj->table->attrs->name;
737 if($this->isTableExists($table_name))
743 if($table_name ==
'sequence')
745 $query = sprintf(
'create serial "%s" start with 1 increment by 1' .
747 'maxvalue 10000000000000000000000000000000000000' .
' nocycle;', $this->prefix . $table_name);
749 return $this->_query($query);
753 $table_name = $this->prefix . $table_name;
755 $query = sprintf(
'create class "%s";', $table_name);
756 $this->_query($query);
758 if(!is_array($xml_obj->table->column))
760 $columns[] = $xml_obj->table->column;
764 $columns = $xml_obj->table->column;
767 $query = sprintf(
"alter class \"%s\" add attribute ", $table_name);
769 $primary_list = array();
770 $unique_list = array();
771 $index_list = array();
773 foreach($columns as $column)
775 $name = $column->attrs->name;
776 $type = $column->attrs->type;
777 $size = $column->attrs->size;
778 $notnull = $column->attrs->notnull;
779 $primary_key = $column->attrs->primary_key;
780 $index = $column->attrs->index;
781 $unique = $column->attrs->unique;
782 $default = $column->attrs->default;
784 switch($this->column_type[$type])
794 if(isset($default) && ($type ==
'varchar' || $type ==
'char' ||
795 $type ==
'text' || $type ==
'tinytext' || $type ==
'bigtext'))
797 $default = sprintf(
"'%s'", $default);
800 if($type ==
'varchar' || $type ==
'char')
807 $column_schema[] = sprintf(
'"%s" %s%s %s %s', $name, $this->column_type[$type], $size ?
'(' . $size .
')' :
'', isset($default) ?
"default " . $default :
'', $notnull ?
'not null' :
'');
811 $primary_list[] = $name;
815 $unique_list[$unique][] = $name;
819 $index_list[$index][] = $name;
823 $query .= implode(
',', $column_schema) .
';';
824 $this->_query($query);
826 if(count($primary_list))
828 $query = sprintf(
"alter class \"%s\" add attribute constraint " .
"\"pkey_%s\" PRIMARY KEY(%s);", $table_name, $table_name,
'"' . implode(
'","', $primary_list) .
'"');
829 $this->_query($query);
832 if(count($unique_list))
834 foreach($unique_list as $key => $val)
836 $query = sprintf(
"create unique index \"%s\" on \"%s\" " .
"(%s);", $key, $table_name,
'"' . implode(
'","', $val) .
'"');
837 $this->_query($query);
841 if(count($index_list))
843 foreach($index_list as $key => $val)
845 $query = sprintf(
"create index \"%s\" on \"%s\" (%s);", $key, $table_name,
'"' . implode(
'","', $val) .
'"');
846 $this->_query($query);
859 if($this->use_prepared_statements ==
'Y')
861 $this->param = $queryObject->getArguments();
862 $with_values = FALSE;
864 $query = $this->getInsertSql($queryObject, $with_values);
865 if(is_a($query,
'BaseObject'))
871 $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(
' ' . $this->comment_syntax, $this->query_id) :
'';
873 $result = $this->_query($query);
874 if($result && !$this->transaction_started)
890 if($this->use_prepared_statements ==
'Y')
892 $this->param = $queryObject->getArguments();
893 $with_values = FALSE;
895 $query = $this->getUpdateSql($queryObject, $with_values);
896 if(is_a($query,
'BaseObject'))
902 $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(
' ' . $this->comment_syntax, $this->query_id) :
'';
904 $result = $this->_query($query);
906 if($result && !$this->transaction_started)
922 if($this->use_prepared_statements ==
'Y')
924 $this->param = $queryObject->getArguments();
925 $with_values = FALSE;
927 $query = $this->getDeleteSql($queryObject, $with_values);
928 if(is_a($query,
'BaseObject'))
934 $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(
' ' . $this->comment_syntax, $this->query_id) :
'';
936 $result = $this->_query($query);
938 if($result && !$this->transaction_started)
958 if($this->use_prepared_statements ==
'Y')
960 $this->param = $queryObject->getArguments();
961 $with_values = FALSE;
963 $limit = $queryObject->getLimit();
964 if($limit && $limit->isPageHandler())
966 return $this->queryPageLimit($queryObject, $connection, $with_values);
970 $query = $this->getSelectSql($queryObject, $with_values);
971 if(is_a($query,
'BaseObject'))
977 $query .= (__DEBUG_QUERY__ & 1 && $this->query_id) ? sprintf(
' ' . $this->comment_syntax, $this->query_id) :
'';
978 $result = $this->_query($query, $connection);
983 return $this->queryError($queryObject);
986 $data = $this->_fetch($result);
1002 $limit = $queryObject->getLimit();
1003 if($limit && $limit->isPageHandler())
1006 $buff->total_count = 0;
1007 $buff->total_page = 0;
1009 $buff->data = array();
1010 $buff->page_navigation =
new PageHandler(0, 1, 1, 10);
1025 $limit = $queryObject->getLimit();
1027 $temp_where = $queryObject->getWhereString($with_values, FALSE);
1028 $count_query = sprintf(
'select count(*) as "count" %s %s',
'FROM ' . $queryObject->getFromString($with_values), ($temp_where ===
'' ?
'' :
' WHERE ' . $temp_where));
1031 $temp_select = $queryObject->getSelectString($with_values);
1032 $uses_distinct = stripos($temp_select,
"distinct") !== FALSE;
1033 $uses_groupby = $queryObject->getGroupByString() !=
'';
1034 if($uses_distinct || $uses_groupby)
1036 $count_query = sprintf(
'select %s %s %s %s'
1038 ,
'FROM ' . $queryObject->getFromString($with_values)
1039 , ($temp_where ===
'' ?
'' :
' WHERE ' . $temp_where)
1040 , ($uses_groupby ?
' GROUP BY ' . $queryObject->getGroupByString() :
'')
1044 $count_query = sprintf(
'select count(*) as "count" from (%s) xet', $count_query);
1047 $count_query .= (__DEBUG_QUERY__ & 1 && $queryObject->queryID) ? sprintf(
' ' . $this->comment_syntax, $queryObject->queryID) :
'';
1048 $result = $this->_query($count_query, $connection);
1049 $count_output = $this->_fetch($result);
1050 $total_count = (int) (isset($count_output->count) ? $count_output->count : NULL);
1052 $list_count = $limit->list_count->getValue();
1057 $page_count = $limit->page_count->getValue();
1062 $page = $limit->page->getValue();
1063 if(!$page || $page < 1)
1071 $total_page = (int) (($total_count - 1) / $list_count) + 1;
1079 if($page > $total_page)
1084 $buff->total_count = $total_count;
1085 $buff->total_page = $total_page;
1086 $buff->page = $page;
1087 $buff->data = array();
1088 $buff->page_navigation =
new PageHandler($total_count, $total_page, $page, $page_count);
1089 unset($this->param);
1092 $start_count = ($page - 1) * $list_count;
1094 $query = $this->getSelectPageSql($queryObject, $with_values, $start_count, $list_count);
1095 $query .= (__DEBUG_QUERY__ & 1 && $queryObject->query_id) ? sprintf(
' ' . $this->comment_syntax, $this->query_id) :
'';
1096 $result = $this->_query($query, $connection);
1097 if($this->isError())
1099 unset($this->param);
1100 return $this->queryError($queryObject);
1103 $virtual_no = $total_count - ($page - 1) * $list_count;
1104 $data = $this->_fetch($result, $virtual_no);
1107 $buff->total_count = $total_count;
1108 $buff->total_page = $total_page;
1109 $buff->page = $page;
1110 $buff->data = $data;
1111 $buff->page_navigation =
new PageHandler($total_count, $total_page, $page, $page_count);
1112 unset($this->param);
1123 return new DBParser(
'"',
'"', $this->prefix);
1137 $select = $query->getSelectString($with_values);
1142 $select =
'SELECT ' . $select;
1144 $from = $query->getFromString($with_values);
1149 $from =
' FROM ' . $from;
1151 $where = $query->getWhereString($with_values);
1154 $where =
' WHERE ' . $where;
1157 $groupBy = $query->getGroupByString();
1160 $groupBy =
' GROUP BY ' . $groupBy;
1163 $orderBy = $query->getOrderByString();
1166 $orderBy =
' ORDER BY ' . $orderBy;
1169 $limit = $query->getLimitString();
1172 $limit = sprintf(
' LIMIT %d, %d', $start_count, $list_count);
1175 return $select .
' ' . $from .
' ' . $where .
' ' . $groupBy .
' ' . $orderBy .
' ' . $limit;
setError($errno=0, $errstr= 'success')
isColumnExists($table_name, $column_name)
isTableExists($target_name)
createTableByXml($xml_doc)
addIndex($table_name, $index_name, $target_columns, $is_unique=FALSE)
_fetch($result, $arrayIndexEndValue=NULL)
isConnected($type= 'master', $indx=0)
_rollback($transactionLevel=0)
_executeInsertAct($queryObject, $with_values=TRUE)
createTableByXmlFile($file_name)
__construct($auto_connect=TRUE)
addColumn($table_name, $column_name, $type= 'number', $size= '', $default=null, $notnull=FALSE)
_executeDeleteAct($queryObject, $with_values=TRUE)
dropColumn($table_name, $column_name)
queryPageLimit($queryObject, $connection, $with_values)
isIndexExists($table_name, $index_name)
_executeUpdateAct($queryObject, $with_values=TRUE)
_connect($type= 'master', $indx=0)
_getConnection($type= 'master', $indx=NULL)
_query($query, $connection=NULL)
_begin($transactionLevel=0)
__query($query, $connection)
_executeSelectAct($queryObject, $connection=NULL, $with_values=TRUE)
dropIndex($table_name, $index_name, $is_unique=FALSE)
getSelectPageSql($query, $with_values=TRUE, $start_count=0, $list_count=0)