dbo_odbc.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class DboOdbc extends DboSource{
00040
00041
00042
00043
00044
00045
00046 var $description = "ODBC DBO Driver";
00047
00048
00049
00050
00051
00052
00053 var $startQuote = "`";
00054
00055
00056
00057
00058
00059
00060 var $endQuote = "`";
00061
00062
00063
00064
00065
00066
00067 var $_baseConfig = array('persistent' => true,
00068 'login' => 'root',
00069 'password' => '',
00070 'database' => 'cake',
00071 'connect' => 'odbc_pconnect'
00072 );
00073
00074
00075
00076
00077
00078
00079
00080 var $columns = array();
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 function connect() {
00100 $config = $this->config;
00101 $connect = $config['connect'];
00102
00103 $this->connected = false;
00104 $this->connection = $connect($config['database'], $config['login'], $config['password']);
00105
00106 if ($this->connection) {
00107 $this->connected = true;
00108 }
00109
00110 return $this->connected;
00111 }
00112
00113
00114
00115
00116
00117
00118 function disconnect() {
00119 return @odbc_close($this->connection);
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 function _execute($sql) {
00129 return odbc_exec($this->connection, $sql);
00130 }
00131
00132
00133
00134
00135
00136 function listSources() {
00137
00138 $cache = parent::listSources();
00139 if ($cache != null) {
00140 return $cache;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150 $result = odbc_tables($this->connection);
00151
00152 $tables = array();
00153 while (odbc_fetch_row($result)) {
00154 array_push($tables, odbc_result($result, "TABLE_NAME"));
00155 }
00156
00157 parent::listSources($tables);
00158 return $tables;
00159 }
00160
00161
00162
00163
00164
00165
00166 function &describe(&$model) {
00167 $cache=parent::describe($model);
00168
00169 if ($cache != null) {
00170 return $cache;
00171 }
00172
00173 $fields = array();
00174 $sql = 'SELECT * FROM ' . $this->fullTableName($model);
00175 $result = odbc_exec($this->connection, $sql);
00176
00177 $count = odbc_num_fields($result);
00178
00179 for ($i = 1; $i <= $count; $i++) {
00180 $cols[$i - 1] = odbc_field_name($result, $i);
00181 }
00182
00183 foreach ($cols as $column) {
00184 $type = odbc_field_type(odbc_exec($this->connection, "SELECT " . $column . " FROM " . $this->fullTableName($model)), 1);
00185 $fields[$column] = array('type' => $type);
00186 }
00187
00188 $this->__cacheDescription($model->tablePrefix . $model->table, $fields);
00189 return $fields;
00190 }
00191
00192 function name($data) {
00193 if ($data == '*') {
00194 return '*';
00195 }
00196
00197 $pos = strpos($data, '`');
00198
00199 if ($pos === false) {
00200 $data = '' . str_replace('.', '.', $data) . '';
00201
00202 }
00203
00204 return $data;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 function value($data, $column = null) {
00216 $parent=parent::value($data, $column);
00217
00218 if ($parent != null) {
00219 return $parent;
00220 }
00221
00222 if ($data === null) {
00223 return 'NULL';
00224 }
00225
00226
00227
00228 if (!is_numeric($data)) {
00229 $return = "'" . $data . "'";
00230 } else {
00231 $return = $data;
00232 }
00233
00234 return $return;
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244 function boolean($data) {
00245 if ($data === true || $data === false) {
00246 if ($data === true) {
00247 return 1;
00248 }
00249
00250 return 0;
00251 } else {
00252 if (intval($data !== 0)) {
00253 return true;
00254 }
00255
00256 return false;
00257 }
00258 }
00259
00260
00261
00262
00263
00264
00265
00266
00267 function begin(&$model) {
00268 if (parent::begin($model)) {
00269 if (odbc_autocommit($this->connection, false)) {
00270 $this->_transactionStarted = true;
00271 return true;
00272 }
00273 }
00274
00275 return false;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 function commit(&$model) {
00287 if (parent::commit($model)) {
00288 if (odbc_commit($this->connection)) {
00289 $this->_transactionStarted = false;
00290 return true;
00291 }
00292 }
00293
00294 return false;
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 function rollback(&$model) {
00306 if (parent::rollback($model)) {
00307 $this->_transactionStarted=false;
00308 return odbc_rollback($this->connection);
00309 }
00310
00311 return false;
00312 }
00313
00314
00315
00316
00317
00318
00319 function lastError() {
00320 if (odbc_error($this->connection)) {
00321 return odbc_error($this->connection) . ': ' . odbc_errormsg($this->connection);
00322 }
00323
00324 return null;
00325 }
00326
00327
00328
00329
00330
00331
00332
00333 function lastAffected() {
00334 if ($this->_result) {
00335 return null;
00336 }
00337
00338 return null;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347 function lastNumRows() {
00348 if ($this->_result) {
00349 return@odbc_num_rows($this->_result);
00350 }
00351
00352 return null;
00353 }
00354
00355
00356
00357
00358
00359
00360
00361 function lastInsertId($source = null) {
00362 $result=$this->fetchRow('SELECT @@IDENTITY');
00363 return $result[0];
00364 }
00365
00366
00367
00368
00369
00370
00371 function column($real) {
00372 if (is_array($real)) {
00373 $col=$real['name'];
00374
00375 if (isset($real['limit'])) {
00376 $col .= '(' . $real['limit'] . ')';
00377 }
00378
00379 return $col;
00380 }
00381
00382 return $real;
00383 }
00384
00385
00386
00387
00388
00389
00390 function resultSet(&$results) {
00391 $this->results=&$results;
00392 $this->map=array();
00393 $num_fields =odbc_num_fields($results);
00394 $index =0;
00395 $j =0;
00396
00397 while ($j < $num_fields) {
00398 $column = odbc_fetch_array($results, $j);
00399
00400 if (!empty($column->table)) {
00401 $this->map[$index++] = array($column->table,
00402 $column->name);
00403 } else {
00404 echo array(0,
00405 $column->name);
00406
00407 $this->map[$index++]=array(0,
00408 $column->name);
00409 }
00410
00411 $j++;
00412 }
00413 }
00414
00415
00416
00417
00418
00419
00420 function fetchResult() {
00421 if ($row = odbc_fetch_row($this->results)) {
00422 $resultRow=array();
00423 $i=0;
00424
00425 foreach ($row as $index => $field) {
00426 list($table, $column) = $this->map[$index];
00427 $resultRow[$table][$column]=$row[$index];
00428 $i++;
00429 }
00430
00431 return $resultRow;
00432 } else {
00433 return false;
00434 }
00435 }
00436 }
00437 ?>