mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 19:42:15 +09:00
Updated DB classes for supporting prepared statements - SQL string can now be returned with '?' instead of argument values.
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8458 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
313bfca8e8
commit
b6a1088995
14 changed files with 107 additions and 52 deletions
|
|
@ -457,16 +457,16 @@
|
|||
$this->_query($query);
|
||||
}
|
||||
|
||||
function getSelectSql($query){
|
||||
$select = $query->getSelectString();
|
||||
function getSelectSql($query, $with_values = true){
|
||||
$select = $query->getSelectString($with_values);
|
||||
if($select == '') return new Object(-1, "Invalid query");
|
||||
$select = 'SELECT ' .$select;
|
||||
|
||||
$from = $query->getFromString();
|
||||
$from = $query->getFromString($with_values);
|
||||
if($from == '') return new Object(-1, "Invalid query");
|
||||
$from = ' FROM '.$from;
|
||||
|
||||
$where = $query->getWhereString();
|
||||
$where = $query->getWhereString($with_values);
|
||||
if($where != '') $where = ' WHERE ' . $where;
|
||||
|
||||
$groupBy = $query->getGroupByString();
|
||||
|
|
@ -481,7 +481,7 @@
|
|||
return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit;
|
||||
}
|
||||
|
||||
function getDeleteSql($query){
|
||||
function getDeleteSql($query, $with_values = true){
|
||||
$sql = 'DELETE ';
|
||||
|
||||
// TODO Add support for deleting based on alias, for both simple FROM and multi table join FROM clause
|
||||
|
|
@ -489,32 +489,32 @@
|
|||
|
||||
$sql .= $tables[0]->getAlias();
|
||||
|
||||
$from = $query->getFromString();
|
||||
$from = $query->getFromString($with_values);
|
||||
if($from == '') return new Object(-1, "Invalid query");
|
||||
$sql .= ' FROM '.$from;
|
||||
|
||||
$where = $query->getWhereString();
|
||||
$where = $query->getWhereString($with_values);
|
||||
if($where != '') $sql .= ' WHERE ' . $where;
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
function getUpdateSql($query){
|
||||
function getUpdateSql($query, $with_values = true){
|
||||
$columnsList = $query->getSelectString();
|
||||
if($columnsList == '') return new Object(-1, "Invalid query");
|
||||
|
||||
$tableName = $query->getFirstTableName();
|
||||
if($tableName == '') return new Object(-1, "Invalid query");
|
||||
|
||||
$where = $query->getWhereString();
|
||||
$where = $query->getWhereString($with_values);
|
||||
if($where != '') $where = ' WHERE ' . $where;
|
||||
|
||||
return "UPDATE $tableName SET $columnsList ".$where;
|
||||
}
|
||||
|
||||
function getInsertSql($query){
|
||||
function getInsertSql($query, $with_values = true){
|
||||
$tableName = $query->getFirstTableName();
|
||||
$values = $query->getInsertString();
|
||||
$values = $query->getInsertString($with_values);
|
||||
|
||||
return "INSERT INTO $tableName \n $values";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -434,6 +434,42 @@
|
|||
return $this->_query($query);
|
||||
}
|
||||
|
||||
function getSelectSql($query){
|
||||
$with_value = false;
|
||||
|
||||
//$limitOffset = $query->getLimit()->getOffset();
|
||||
//if($limitOffset)
|
||||
// TODO Implement Limit with offset with subquery
|
||||
$limit = '';$limitCount = '';
|
||||
if($query->getLimit())
|
||||
$limitCount = $query->getLimit()->getLimit();
|
||||
if($limitCount != '') $limit = 'SELECT TOP ' . $limitCount;
|
||||
|
||||
$select = $query->getSelectString($with_values);
|
||||
if($select == '') return new Object(-1, "Invalid query");
|
||||
if($limit != '')
|
||||
$select = $limit.' '.$select;
|
||||
else
|
||||
$select = 'SELECT ' .$select;
|
||||
|
||||
$from = $query->getFromString($with_values);
|
||||
if($from == '') return new Object(-1, "Invalid query");
|
||||
$from = ' FROM '.$from;
|
||||
|
||||
$where = $query->getWhereString($with_values);
|
||||
if($where != '') $where = ' WHERE ' . $where;
|
||||
|
||||
$groupBy = $query->getGroupByString();
|
||||
if($groupBy != '') $groupBy = ' GROUP BY ' . $groupBy;
|
||||
|
||||
$orderBy = $query->getOrderByString();
|
||||
if($orderBy != '') $orderBy = ' ORDER BY ' . $orderBy;
|
||||
|
||||
|
||||
|
||||
return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle selectAct
|
||||
*
|
||||
|
|
@ -451,6 +487,9 @@
|
|||
return $buff;
|
||||
}
|
||||
|
||||
function getParser(){
|
||||
return new DBParser("[", "]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
var $orderby;
|
||||
var $limit;
|
||||
|
||||
var $arguments = array();
|
||||
|
||||
function addArgument($argument){
|
||||
$this->arguments[] = $argument;
|
||||
}
|
||||
|
||||
function setQueryId($queryID){
|
||||
$this->queryID = $queryID;
|
||||
|
|
@ -106,28 +111,28 @@
|
|||
return $this->action;
|
||||
}
|
||||
|
||||
function getSelectString(){
|
||||
function getSelectString($with_values = true){
|
||||
$select = '';
|
||||
foreach($this->columns as $column){
|
||||
if($column->show())
|
||||
$select .= $column->getExpression() . ', ';
|
||||
$select .= $column->getExpression($with_values) . ', ';
|
||||
}
|
||||
if(trim($select) == '') return '';
|
||||
$select = substr($select, 0, -2);
|
||||
return $select;
|
||||
}
|
||||
|
||||
function getUpdateString(){
|
||||
return $this->getSelectString();
|
||||
function getUpdateString($with_values = true){
|
||||
return $this->getSelectString($with_values);
|
||||
}
|
||||
|
||||
function getInsertString(){
|
||||
function getInsertString($with_values = true){
|
||||
$columnsList = '';
|
||||
$valuesList = '';
|
||||
foreach($this->columns as $column){
|
||||
if($column->show()){
|
||||
$columnsList .= $column->getColumnName() . ', ';
|
||||
$valuesList .= $column->getValue() . ', ';
|
||||
$valuesList .= $column->getValue($with_values) . ', ';
|
||||
}
|
||||
}
|
||||
$columnsList = substr($columnsList, 0, -2);
|
||||
|
|
@ -140,23 +145,23 @@
|
|||
return $this->tables;
|
||||
}
|
||||
|
||||
function getFromString(){
|
||||
function getFromString($with_values = true){
|
||||
$from = '';
|
||||
$simple_table_count = 0;
|
||||
foreach($this->tables as $table){
|
||||
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString() . ' ';
|
||||
else $from .= ', '.$table->toString() . ' ';
|
||||
if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
|
||||
else $from .= ', '.$table->toString($with_values) . ' ';
|
||||
$simple_table_count++;
|
||||
}
|
||||
if(trim($from) == '') return '';
|
||||
return $from;
|
||||
}
|
||||
|
||||
function getWhereString(){
|
||||
function getWhereString($with_values = true){
|
||||
$where = '';
|
||||
if(count($this->conditions) > 0){
|
||||
foreach($this->conditions as $conditionGroup){
|
||||
$where .= $conditionGroup->toString();
|
||||
$where .= $conditionGroup->toString($with_values);
|
||||
}
|
||||
if(trim($where) == '') return '';
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@
|
|||
return is_a($this->argument, 'Argument');
|
||||
}
|
||||
|
||||
function toString(){
|
||||
return $this->toStringWithValue();
|
||||
function toString($withValue = true){
|
||||
if($withValue)
|
||||
return $this->toStringWithValue();
|
||||
return $this->toStringWithoutValue();
|
||||
}
|
||||
|
||||
function toStringWithoutValue(){
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
var $conditions;
|
||||
var $pipe;
|
||||
|
||||
function ConditionGroup($conditions, $pipe = ""){
|
||||
function ConditionGroup($conditions, $pipe = "") {
|
||||
$this->conditions = $conditions;
|
||||
$this->pipe = $pipe;
|
||||
}
|
||||
|
||||
function toString(){
|
||||
function toString($with_value = true){
|
||||
if($this->pipe !== "")
|
||||
$group = $this->pipe .' (';
|
||||
else $group = '';
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
foreach($this->conditions as $condition){
|
||||
if($condition->show()){
|
||||
if($cond_indx === 0) $condition->setPipe("");
|
||||
$group .= $condition->toString() . ' ';
|
||||
$group .= $condition->toString($with_value) . ' ';
|
||||
$cond_indx++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@
|
|||
$this->argument = $argument;
|
||||
}
|
||||
|
||||
function getValue(){
|
||||
return $this->argument->getValue();
|
||||
function getValue($with_values = true){
|
||||
if($with_values)
|
||||
return $this->argument->getValue();
|
||||
return '?';
|
||||
}
|
||||
|
||||
function show(){
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@
|
|||
$this->argument = $argument;
|
||||
}
|
||||
|
||||
function getExpression(){
|
||||
return $this->getExpressionWithValue();
|
||||
function getExpression($with_value = true){
|
||||
if($with_value)
|
||||
return $this->getExpressionWithValue();
|
||||
return $this->getExpressionWithoutValue();
|
||||
}
|
||||
|
||||
function getExpressionWithValue(){
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@
|
|||
$this->conditions = $conditions;
|
||||
}
|
||||
|
||||
function toString(){
|
||||
function toString($with_value = true){
|
||||
$part = $this->join_type . ' ' . $this->name ;
|
||||
$part .= $this->alias ? ' as ' . $this->alias : '';
|
||||
$part .= ' on ';
|
||||
foreach($this->conditions as $conditionGroup)
|
||||
$part .= $conditionGroup->toString();
|
||||
$part .= $conditionGroup->toString($with_value);
|
||||
return $part;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue