mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding patches from andy__ to dbo_odbc
Schema related functions will not work due to the way odbc works. Closes #5398 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7646 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
caa4e321f2
commit
676459224c
1 changed files with 131 additions and 82 deletions
|
@ -76,7 +76,6 @@ class DboOdbc extends DboSource{
|
|||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
|
||||
var $columns = array();
|
||||
|
||||
// var $columns = array('primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
||||
|
@ -189,6 +188,13 @@ class DboOdbc extends DboSource{
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name
|
||||
*
|
||||
* @param string $data
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function name($data) {
|
||||
if ($data == '*') {
|
||||
return '*';
|
||||
|
@ -244,13 +250,11 @@ class DboOdbc extends DboSource{
|
|||
if ($data === true) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
if (intval($data !== 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +273,6 @@ class DboOdbc extends DboSource{
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -288,7 +291,6 @@ class DboOdbc extends DboSource{
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -305,7 +307,6 @@ class DboOdbc extends DboSource{
|
|||
$this->_transactionStarted=false;
|
||||
return odbc_rollback($this->connection);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -315,10 +316,9 @@ class DboOdbc extends DboSource{
|
|||
* @return string Error message with error number
|
||||
*/
|
||||
function lastError() {
|
||||
if (odbc_error($this->connection)) {
|
||||
if (odbc_errormsg($this->connection)) {
|
||||
return odbc_error($this->connection) . ': ' . odbc_errormsg($this->connection);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -329,26 +329,30 @@ class DboOdbc extends DboSource{
|
|||
* @return integer Number of affected rows
|
||||
*/
|
||||
function lastAffected() {
|
||||
if ($this->_result) {
|
||||
return null;
|
||||
if ($this->hasResult()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||
* this returns false.
|
||||
*
|
||||
* @return integer Number of rows in resultset
|
||||
* @return int Number of rows in resultset
|
||||
*/
|
||||
function lastNumRows() {
|
||||
if ($this->_result) {
|
||||
return@odbc_num_rows($this->_result);
|
||||
}
|
||||
|
||||
if($this->hasResult()) {
|
||||
$counter = 0;
|
||||
if(@odbc_fetch_into($this->_result, $results)) {
|
||||
return count($results);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID generated from the previous INSERT operation.
|
||||
|
@ -369,14 +373,11 @@ class DboOdbc extends DboSource{
|
|||
function column($real) {
|
||||
if (is_array($real)) {
|
||||
$col=$real['name'];
|
||||
|
||||
if (isset($real['limit'])) {
|
||||
$col .= '(' . $real['limit'] . ')';
|
||||
}
|
||||
|
||||
return $col;
|
||||
}
|
||||
|
||||
return $real;
|
||||
}
|
||||
|
||||
|
@ -387,29 +388,78 @@ class DboOdbc extends DboSource{
|
|||
*/
|
||||
function resultSet(&$results) {
|
||||
$this->results =& $results;
|
||||
$this->map=array();
|
||||
$num_fields = odbc_num_fields($results);
|
||||
$this->map = array();
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
|
||||
while($j < $num_fields) {
|
||||
$column = odbc_fetch_array($results, $j);
|
||||
$columnName = odbc_field_name($results, $j+1);
|
||||
|
||||
if (!empty($column->table)) {
|
||||
$this->map[$index++] = array($column->table,
|
||||
$column->name);
|
||||
if(strpos($columnName, '_dot_') !== false) {
|
||||
$parts = explode('_dot_', $columnName);
|
||||
$this->map[$index++] = array($parts[0], $parts[1]);
|
||||
} else {
|
||||
echo array(0,
|
||||
$column->name);
|
||||
|
||||
$this->map[$index++]=array(0,
|
||||
$column->name);
|
||||
$this->map[$index++] = array(0, $columnName);
|
||||
}
|
||||
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates the fields list of an SQL query.
|
||||
*
|
||||
* @param Model $model
|
||||
* @param string $alias Alias tablename
|
||||
* @param mixed $fields
|
||||
* @return array
|
||||
*/
|
||||
function fields(&$model, $alias = null, $fields = null, $quote = true) {
|
||||
if (empty($alias)) {
|
||||
$alias = $model->name;
|
||||
}
|
||||
if (!is_array($fields)) {
|
||||
if ($fields != null) {
|
||||
if (strpos($fields, ',')) {
|
||||
$fields = explode(',', $fields);
|
||||
} else {
|
||||
$fields = array($fields);
|
||||
}
|
||||
$fields = array_map('trim', $fields);
|
||||
} else {
|
||||
foreach($model->tableToModel as $tableName => $modelName) {
|
||||
foreach($this->__descriptions[$model->tablePrefix .$tableName] as $field => $type) {
|
||||
$fields[] = $modelName .'.' .$field;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($fields);
|
||||
|
||||
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (!preg_match('/^.+\\(.*\\)/', $fields[$i])) {
|
||||
$prepend = '';
|
||||
if (strpos($fields[$i], 'DISTINCT') !== false) {
|
||||
$prepend = 'DISTINCT ';
|
||||
$fields[$i] = trim(r('DISTINCT', '', $fields[$i]));
|
||||
}
|
||||
|
||||
if(strrpos($fields[$i], '.') === false) {
|
||||
$fields[$i] = $prepend . $this->name($alias) . '.' . $this->name($fields[$i]) . ' AS ' . $this->name($alias . '_dot_' . $fields[$i]);
|
||||
} else {
|
||||
$build = explode('.', $fields[$i]);
|
||||
$fields[$i] = $prepend . $this->name($build[0]) . '.' . $this->name($build[1]) . ' AS ' . $this->name($build[0] . '_dot_' . $build[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the next row from the current result set
|
||||
*
|
||||
|
@ -418,18 +468,17 @@ class DboOdbc extends DboSource{
|
|||
function fetchResult() {
|
||||
if($row = odbc_fetch_row($this->results)) {
|
||||
$resultRow = array();
|
||||
$numFields = odbc_num_fields($this->results);
|
||||
$i = 0;
|
||||
|
||||
foreach ($row as $index => $field) {
|
||||
list($table, $column) = $this->map[$index];
|
||||
$resultRow[$table][$column]=$row[$index];
|
||||
$i++;
|
||||
for($i = 0; $i < $numFields; $i++) {
|
||||
list($table, $column) = $this->map[$i];
|
||||
$resultRow[$table][$column] = odbc_result($this->results, $i +1);
|
||||
}
|
||||
|
||||
return $resultRow;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue