Fix for DELETE statement. MySql class refactoring to use new DBClasses.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8449 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-06-03 14:50:12 +00:00
parent 9ef9069ba2
commit 69bca759f6
6 changed files with 89 additions and 20 deletions

View file

@ -483,6 +483,11 @@
function getDeleteSql($query){
$sql = 'DELETE ';
// TODO Add support for deleting based on alias, for both simple FROM and multi table join FROM clause
$tables = $query->getTables();
$sql .= $tables[0]->getAlias();
$from = $query->getFromString();
if($from == '') return new Object(-1, "Invalid query");

View file

@ -574,7 +574,8 @@
function _executeInsertAct($queryObject)
{
$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);
@ -591,6 +592,8 @@
function _executeUpdateAct($queryObject)
{
$query = $this->getUpdateSql($queryObject);
if(is_a($query, 'Object')) return;
$result = $this->_query($query);
if ($result && !$this->transaction_started) @cubrid_commit ($this->fd);
@ -605,6 +608,8 @@
function _executeDeleteAct($queryObject)
{
$query = $this->getDeleteSql($queryObject);
if(is_a($query, 'Object')) return;
$result = $this->_query ($query);
if ($result && !$this->transaction_started) @cubrid_commit ($this->fd);
@ -621,7 +626,8 @@
// TODO Rewrite with Query object as input
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);

View file

@ -152,7 +152,7 @@
// Notify to start a query execution
$this->actStart($query);
// Run the query statement
$result = @mysql_query($query, $this->fd);
$result = mysql_query($query, $this->fd);
// Error Check
if(mysql_error($this->fd)) $this->setError(mysql_errno($this->fd), mysql_error($this->fd));
// Notify to complete a query execution
@ -164,12 +164,16 @@
/**
* @brief Fetch results
**/
function _fetch($result) {
function _fetch($result, $arrayIndexEndValue = NULL) {
if(!$this->isConnected() || $this->isError() || !$result) return;
while($tmp = $this->db_fetch_object($result)) {
$output[] = $tmp;
if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $tmp;
else $output[] = $tmp;
}
if(count($output)==1){
if(isset($arrayIndexEndValue)) return $output;
else return $output[0];
}
if(count($output)==1) return $output[0];
return $output;
}
@ -384,6 +388,7 @@
//if($output->priority) $priority = $output->priority['type'].'_priority';
$query = $this->getInsertSql($queryObject);
if(is_a($query, 'Object')) return;
return $this->_query($query);
}
@ -397,6 +402,7 @@
//if($output->priority) $priority = $output->priority['type'].'_priority';
$query = $this->getUpdateSql($queryObject);
if(is_a($query, 'Object')) return;
return $this->_query($query);
}
@ -404,8 +410,10 @@
* @brief Handle deleteAct
**/
function _executeDeleteAct($queryObject) {
$query = $this->getDeleteSql($queryObject);
$query = $this->getDeleteSql($queryObject);
if(is_a($query, 'Object')) return;
//priority setting
// TODO Check what priority does
//$priority = '';
@ -421,19 +429,62 @@
**/
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;
// TODO Add support for click count
// TODO Add code for pagination
$data = $this->_fetch($result);
// TODO Add code for pagination
$result = $this->_query ($query);
if ($this->isError ()) {
if ($limit && $output->limit->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;
}
$buff = new Object();
$buff->data = $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);
}
return $buff;
$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;
}
function db_insert_id()

View file

@ -136,6 +136,10 @@
return "($columnsList) \n VALUES ($valuesList)";
}
function getTables(){
return $this->tables;
}
function getFromString(){
$from = '';
$simple_table_count = 0;

View file

@ -17,6 +17,10 @@
return $this->name;
}
function getAlias(){
return $this->alias;
}
function isJoinTable(){
if(in_array($tableName,array('left join','left outer join','right join','right outer join'))) return true;
return false;

View file

@ -32,9 +32,8 @@
function &getDBParser(){
static $dbParser;
if(!$dbParser){
//$oDB = &DB::getParser();
//self::$dbParser = $oDB->getParser();
$dbParser = new DBParser('"');
$oDB = &DB::getInstance();
$dbParser = $oDB->getParser();
}
return $dbParser;
}