mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 19:42:15 +09:00
Issue 1778: DB Classes: Add prepared statements support - MSSQL
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10492 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
f1a80e7bbd
commit
0665b24aee
1 changed files with 79 additions and 40 deletions
|
|
@ -153,17 +153,56 @@
|
|||
// Run the query statement
|
||||
$result = false;
|
||||
if(count($_param)){
|
||||
$result = @sqlsrv_query($connection, $query, $_param);
|
||||
$args = $this->_getParametersByReference($_param);
|
||||
$stmt = sqlsrv_prepare($connection, $query, $args);
|
||||
}else{
|
||||
$result = @sqlsrv_query($connection, $query);
|
||||
$stmt = sqlsrv_prepare($connection, $query);
|
||||
}
|
||||
// Error Check
|
||||
|
||||
if(!$result) $this->setError(print_r(sqlsrv_errors(),true));
|
||||
if(!$stmt)
|
||||
{
|
||||
$result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = sqlsrv_execute($stmt);
|
||||
}
|
||||
|
||||
// Error Check
|
||||
if(!$result)
|
||||
$this->setError(print_r(sqlsrv_errors(),true));
|
||||
|
||||
$this->param = array();
|
||||
|
||||
return $result;
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters to sqlsrv_prepare need to be references, and not literals
|
||||
* Parameters are sent as an array, where each parameter can be:
|
||||
* - a PHP variable (by reference)
|
||||
* - a PHP array (containng param value, type and direction) -> also needs to be sent by reference
|
||||
*/
|
||||
function _getParametersByReference($_param)
|
||||
{
|
||||
$copy = array(); $args = array(); $i = 0;
|
||||
foreach($_param as $key => $value) {
|
||||
if(is_array($value))
|
||||
{
|
||||
$value_copy = $value;
|
||||
$value_arg = array();
|
||||
$value_arg[] = &$value_copy[0];
|
||||
$value_arg[] = $value_copy[1];
|
||||
$value_arg[] = $value_copy[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$value_arg = $value;
|
||||
}
|
||||
$copy[$key] = $value_arg;
|
||||
$args[$i++] = &$copy[$key];
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -439,7 +478,7 @@
|
|||
}
|
||||
|
||||
function getSelectSql($query){
|
||||
$with_value = false;
|
||||
$with_values = false;
|
||||
|
||||
//$limitOffset = $query->getLimit()->getOffset();
|
||||
//if($limitOffset)
|
||||
|
|
@ -531,15 +570,19 @@
|
|||
$total_count = (int) $count_output->count;
|
||||
|
||||
$list_count = $limit->list_count->getValue();
|
||||
if (!$list_count) $list_count = 20;
|
||||
if (!$list_count)
|
||||
$list_count = 20;
|
||||
$page_count = $limit->page_count->getValue();
|
||||
if (!$page_count) $page_count = 10;
|
||||
if (!$page_count)
|
||||
$page_count = 10;
|
||||
$page = $limit->page->getValue();
|
||||
if (!$page) $page = 1;
|
||||
if (!$page)
|
||||
$page = 1;
|
||||
// Total pages
|
||||
if ($total_count) {
|
||||
$total_page = (int) (($total_count - 1) / $list_count) + 1;
|
||||
} else $total_page = 1;
|
||||
} else
|
||||
$total_page = 1;
|
||||
|
||||
// check the page variables
|
||||
if ($page > $total_page) {
|
||||
|
|
@ -557,10 +600,6 @@
|
|||
|
||||
$query .= (__DEBUG_QUERY__ & 1 && $queryObject->query_id) ? sprintf(' ' . $this->comment_syntax, $this->query_id) : '';
|
||||
$this->param = $queryObject->getArguments();
|
||||
$result = $this->_query ($query, $connection);
|
||||
if ($this->isError ())
|
||||
return $this->queryError($queryObject);
|
||||
|
||||
$virtual_no = $total_count - ($page - 1) * $list_count;
|
||||
$data = $this->_fetch($result, $virtual_no);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue