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
|
@ -36,7 +36,7 @@
|
|||
* @package cake
|
||||
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||
*/
|
||||
class DboOdbc extends DboSource{
|
||||
class DboOdbc extends DboSource {
|
||||
|
||||
/**
|
||||
* Driver description
|
||||
|
@ -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'),
|
||||
|
@ -104,7 +103,7 @@ class DboOdbc extends DboSource{
|
|||
$this->connection = $connect($config['database'], $config['login'], $config['password']);
|
||||
|
||||
if ($this->connection) {
|
||||
$this->connected = true;
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
return $this->connected;
|
||||
|
@ -188,7 +187,14 @@ class DboOdbc extends DboSource{
|
|||
$this->__cacheDescription($model->tablePrefix . $model->table, $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Name
|
||||
*
|
||||
* @param string $data
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function name($data) {
|
||||
if ($data == '*') {
|
||||
return '*';
|
||||
|
@ -241,17 +247,15 @@ class DboOdbc extends DboSource{
|
|||
*/
|
||||
function boolean($data) {
|
||||
if ($data === true || $data === false) {
|
||||
if ($data === true) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if ($data === true) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
if (intval($data !== 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (intval($data !== 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,12 +268,11 @@ class DboOdbc extends DboSource{
|
|||
*/
|
||||
function begin(&$model) {
|
||||
if (parent::begin($model)) {
|
||||
if (odbc_autocommit($this->connection, false)) {
|
||||
$this->_transactionStarted = true;
|
||||
return true;
|
||||
}
|
||||
if (odbc_autocommit($this->connection, false)) {
|
||||
$this->_transactionStarted = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -283,12 +286,11 @@ class DboOdbc extends DboSource{
|
|||
*/
|
||||
function commit(&$model) {
|
||||
if (parent::commit($model)) {
|
||||
if (odbc_commit($this->connection)) {
|
||||
$this->_transactionStarted = false;
|
||||
return true;
|
||||
}
|
||||
if (odbc_commit($this->connection)) {
|
||||
$this->_transactionStarted = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -302,10 +304,9 @@ class DboOdbc extends DboSource{
|
|||
*/
|
||||
function rollback(&$model) {
|
||||
if (parent::rollback($model)) {
|
||||
$this->_transactionStarted=false;
|
||||
return odbc_rollback($this->connection);
|
||||
$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)) {
|
||||
return odbc_error($this->connection) . ': ' . odbc_errormsg($this->connection);
|
||||
if (odbc_errormsg($this->connection)) {
|
||||
return odbc_error($this->connection) . ': ' . odbc_errormsg($this->connection);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -329,27 +329,31 @@ 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.
|
||||
*
|
||||
|
@ -368,68 +372,113 @@ class DboOdbc extends DboSource{
|
|||
*/
|
||||
function column($real) {
|
||||
if (is_array($real)) {
|
||||
$col=$real['name'];
|
||||
|
||||
if (isset($real['limit'])) {
|
||||
$col .= '(' . $real['limit'] . ')';
|
||||
}
|
||||
|
||||
return $col;
|
||||
$col=$real['name'];
|
||||
if (isset($real['limit'])) {
|
||||
$col .= '(' . $real['limit'] . ')';
|
||||
}
|
||||
return $col;
|
||||
}
|
||||
|
||||
return $real;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $results
|
||||
*/
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $results
|
||||
*/
|
||||
function resultSet(&$results) {
|
||||
$this->results=&$results;
|
||||
$this->map=array();
|
||||
$num_fields =odbc_num_fields($results);
|
||||
$index =0;
|
||||
$j =0;
|
||||
$this->results =& $results;
|
||||
$num_fields = odbc_num_fields($results);
|
||||
$this->map = array();
|
||||
$index = 0;
|
||||
$j = 0;
|
||||
while($j < $num_fields) {
|
||||
$columnName = odbc_field_name($results, $j+1);
|
||||
|
||||
while ($j < $num_fields) {
|
||||
$column = odbc_fetch_array($results, $j);
|
||||
|
||||
if (!empty($column->table)) {
|
||||
$this->map[$index++] = array($column->table,
|
||||
$column->name);
|
||||
} else {
|
||||
echo array(0,
|
||||
$column->name);
|
||||
|
||||
$this->map[$index++]=array(0,
|
||||
$column->name);
|
||||
}
|
||||
|
||||
$j++;
|
||||
if(strpos($columnName, '_dot_') !== false) {
|
||||
$parts = explode('_dot_', $columnName);
|
||||
$this->map[$index++] = array($parts[0], $parts[1]);
|
||||
} else {
|
||||
$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
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function fetchResult() {
|
||||
if ($row = odbc_fetch_row($this->results)) {
|
||||
$resultRow=array();
|
||||
$i=0;
|
||||
|
||||
foreach ($row as $index => $field) {
|
||||
list($table, $column) = $this->map[$index];
|
||||
$resultRow[$table][$column]=$row[$index];
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $resultRow;
|
||||
if($row = odbc_fetch_row($this->results)) {
|
||||
$resultRow = array();
|
||||
$numFields = odbc_num_fields($this->results);
|
||||
$i = 0;
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue