new DBClasses for SQLite3 and Firebird databases.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8555 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
lickawtl 2011-06-30 15:01:45 +00:00
parent 01d0925dd5
commit 5d1eb1c21e
7 changed files with 218 additions and 65 deletions

View file

@ -449,7 +449,6 @@
if (!file_exists ($file_name)) return; if (!file_exists ($file_name)) return;
// read xml file // read xml file
$buff = FileHandler::readFile ($file_name); $buff = FileHandler::readFile ($file_name);
return $this->_createTable ($buff); return $this->_createTable ($buff);
} }
@ -629,10 +628,14 @@
if(is_a($query, 'Object')) return; if(is_a($query, 'Object')) return;
$query .= (__DEBUG_QUERY__&1 && $queryObject->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); $result = $this->_query ($query);
if ($this->isError ()) {
if ($limit && $output->limit->isPageHandler()){ 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 = new Object ();
$buff->total_count = 0; $buff->total_count = 0;
$buff->total_page = 0; $buff->total_page = 0;
@ -644,6 +647,7 @@
return; return;
} }
function queryPageLimit($queryObject, $result){
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) { if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
// Total count // Total count
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString())); $count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString()));
@ -661,7 +665,6 @@
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1; $total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
} else $total_page = 1; } else $total_page = 1;
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count; $virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
$data = $this->_fetch($result, $virtual_no); $data = $this->_fetch($result, $virtual_no);
@ -676,7 +679,6 @@
$buff = new Object (); $buff = new Object ();
$buff->data = $data; $buff->data = $data;
} }
return $buff; return $buff;
} }

View file

@ -291,7 +291,7 @@
// Notify to start a query execution // Notify to start a query execution
$this->actStart($query); $this->actStart($query);
// Execute the query statement // Execute the query statement
$result = ibase_query($this->fd, $query); $result = @ibase_query($this->fd, $query);
} }
else { else {
// Notify to start a query execution // Notify to start a query execution
@ -592,6 +592,7 @@
} }
} }
if($auto_increment_list)
foreach($auto_increment_list as $increment) { foreach($auto_increment_list as $increment) {
$schema = sprintf('CREATE GENERATOR GEN_%s_ID;', $table_name); $schema = sprintf('CREATE GENERATOR GEN_%s_ID;', $table_name);
$output = $this->_query($schema); $output = $this->_query($schema);
@ -620,22 +621,28 @@
/** /**
* @brief Handle the insertAct * @brief Handle the insertAct
**/ **/
function _executeInsertAct($output) { function _executeInsertAct($queryObject) {
$query = $this->getInsertSql($queryObject);
if(is_a($query, 'Object')) return;
return $this->_query($query);
} }
/** /**
* @brief handles updateAct * @brief handles updateAct
**/ **/
function _executeUpdateAct($output) { function _executeUpdateAct($queryObject) {
$query = $this->getUpdateSql($queryObject);
if(is_a($query, 'Object')) return;
return $this->_query($query);
} }
/** /**
* @brief handles deleteAct * @brief handles deleteAct
**/ **/
function _executeDeleteAct($output) { function _executeDeleteAct($queryObject) {
$query = $this->getDeleteSql($queryObject);
if(is_a($query, 'Object')) return;
return $this->_query($query);
} }
/** /**
@ -644,8 +651,63 @@
* In order to get a list of pages easily when selecting \n * In order to get a list of pages easily when selecting \n
* it supports a method as navigation * it supports a method as navigation
**/ **/
function _executeSelectAct($output) { function _executeSelectAct($queryObject) {
$query = $this->getSelectSql($queryObject);
if(is_a($query, 'Object')) return;
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
$result = $this->_query ($query);
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;
$buff->data = $data;
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page, $queryObject->getLimit()->page_count);
}else{
$data = $this->_fetch($result);
$buff = new Object ();
$buff->data = $data;
}
return $buff;
} }
} }

View file

@ -489,7 +489,15 @@
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):''; $query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
$result = $this->_query($query); $result = $this->_query($query);
if ($this->isError ()) { if ($this->isError ()) return $this->queryError($queryObject);
else return $this->queryPageLimit($queryObject, $result);
}
function getParser(){
return new DBParser("[", "]");
}
function queryError($queryObject){
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()){ if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()){
$buff = new Object (); $buff = new Object ();
$buff->total_count = 0; $buff->total_count = 0;
@ -502,6 +510,7 @@
return; return;
} }
function queryPageLimit($queryObject, $result){
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) { if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
// Total count // Total count
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString())); $count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString()));
@ -519,7 +528,6 @@
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1; $total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
} else $total_page = 1; } else $total_page = 1;
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count; $virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
$data = $this->_fetch($result, $virtual_no); $data = $this->_fetch($result, $virtual_no);
@ -534,14 +542,9 @@
$buff = new Object (); $buff = new Object ();
$buff->data = $data; $buff->data = $data;
} }
return $buff; return $buff;
} }
function getParser(){
return new DBParser("[", "]");
}
} }
return new DBMssql; return new DBMssql;

View file

@ -438,7 +438,25 @@
// TODO Add code for pagination // TODO Add code for pagination
$result = $this->_query ($query); $result = $this->_query ($query);
if ($this->isError ()) { if ($this->isError ()) return $this->queryError($queryObject);
else return $this->queryPageLimit($queryObject, $result);
}
function db_insert_id()
{
return mysql_insert_id($this->fd);
}
function db_fetch_object(&$result)
{
return mysql_fetch_object($result);
}
function getParser(){
return new DBParser('`');
}
function queryError($queryObject){
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()){ if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()){
$buff = new Object (); $buff = new Object ();
$buff->total_count = 0; $buff->total_count = 0;
@ -451,6 +469,7 @@
return; return;
} }
function queryPageLimit($queryObject, $result){
if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) { if ($queryObject->getLimit() && $queryObject->getLimit()->isPageHandler()) {
// Total count // Total count
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString())); $count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($queryObject->getWhereString() === '' ? '' : ' WHERE '. $queryObject->getWhereString()));
@ -468,7 +487,6 @@
$total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1; $total_page = (int) (($total_count - 1) / $queryObject->getLimit()->list_count) + 1;
} else $total_page = 1; } else $total_page = 1;
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count; $virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
$data = $this->_fetch($result, $virtual_no); $data = $this->_fetch($result, $virtual_no);
@ -483,23 +501,8 @@
$buff = new Object (); $buff = new Object ();
$buff->data = $data; $buff->data = $data;
} }
return $buff; return $buff;
} }
function db_insert_id()
{
return mysql_insert_id($this->fd);
}
function db_fetch_object(&$result)
{
return mysql_fetch_object($result);
}
function getParser(){
return new DBParser('`');
}
} }
return new DBMysql; return new DBMysql;

View file

@ -402,7 +402,10 @@
/** /**
* @brief insertAct * @brief insertAct
**/ **/
function _executeInsertAct($output) { function _executeInsertAct($queryObject) {
$query = $this->getInsertSql($queryObject);
if(is_a($query, 'Object')) return;
$this->_prepare($query); $this->_prepare($query);
$val_count = count($val_list); $val_count = count($val_list);
@ -414,7 +417,10 @@
/** /**
* @brief updateAct * @brief updateAct
**/ **/
function _executeUpdateAct($output) { function _executeUpdateAct($queryObject) {
$query = $this->getUpdateSql($queryObject);
if(is_a($query, 'Object')) return;
$this->_prepare($query); $this->_prepare($query);
return $this->_execute(); return $this->_execute();
} }
@ -422,7 +428,10 @@
/** /**
* @brief deleteAct * @brief deleteAct
**/ **/
function _executeDeleteAct($output) { function _executeDeleteAct($queryObject) {
$query = $this->getDeleteSql($queryObject);
if(is_a($query, 'Object')) return;
$this->_prepare($query); $this->_prepare($query);
return $this->_execute(); return $this->_execute();
} }
@ -433,9 +442,84 @@
* To fetch a list of the page conveniently when selecting, \n * To fetch a list of the page conveniently when selecting, \n
* navigation method supported * navigation method supported
**/ **/
function _executeSelectAct($output) { function _executeSelectAct($queryObject) {
$query = $this->getSelectSql($queryObject);
if(is_a($query, 'Object')) return;
$this->_prepare($query);
$data = $this->_execute();
if($this->isError()) return;
if ($this->isError ()) return $this->queryError($queryObject);
else return $this->queryPageLimit($queryObject, $data);
}
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, $data){
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):'';
$this->_prepare($count_query);
$count_output = $this->_execute();
$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;
$this->_prepare($this->getSelectSql($queryObject));
$this->stmt->execute();
if($this->stmt->errorCode() != '00000') {
$this->setError($this->stmt->errorCode(), print_r($this->stmt->errorInfo(),true));
$this->actFinish();
return $buff;
}
$output = null;
$virtual_no = $total_count - ($queryObject->getLimit()->page - 1) * $queryObject->getLimit()->list_count;
//$data = $this->_fetch($result, $virtual_no);
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;
$buff->total_page = $total_page;
$buff->page = $queryObject->getLimit()->page;
$buff->data = $data;
$buff->page_navigation = new PageHandler($total_count, $total_page, $queryObject->getLimit()->page, $queryObject->getLimit()->page_count);
}else{
//$data = $this->_fetch($result);
$buff = new Object (); $buff = new Object ();
$buff->data = $data; $buff->data = $data;
}
return $buff; return $buff;
} }
} }

View file

@ -133,7 +133,6 @@
function getSelectString($with_values = true){ function getSelectString($with_values = true){
$select = ''; $select = '';
foreach($this->columns as $column){ foreach($this->columns as $column){
var_dump($column);
if($column->show()) if($column->show())
if(is_a($column, 'Subquery')){ if(is_a($column, 'Subquery')){
$oDB = &DB::getInstance(); $oDB = &DB::getInstance();

View file

@ -1,4 +1,4 @@
<? <?php
// ko/en/... // ko/en/...
$lang = Context::getLangType(); $lang = Context::getLangType();