CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * AdoDB layer for DBO.
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs.model.datasources.dbo
 20:  * @since         CakePHP(tm) v 0.2.9
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * Include AdoDB files.
 28:  */
 29: App::import('Vendor', 'NewADOConnection', array('file' => 'adodb' . DS . 'adodb.inc.php'));
 30: /**
 31:  * AdoDB DBO implementation.
 32:  *
 33:  * Database abstraction implementation for the AdoDB library.
 34:  *
 35:  * @package       cake
 36:  * @subpackage    cake.cake.libs.model.datasources.dbo
 37:  */
 38: class DboAdodb extends DboSource {
 39: /**
 40:  * Enter description here...
 41:  *
 42:  * @var string
 43:  */
 44:     var $description = "ADOdb DBO Driver";
 45: /**
 46:  * ADOConnection object with which we connect.
 47:  *
 48:  * @var ADOConnection The connection object.
 49:  * @access private
 50:  */
 51:     var $_adodb = null;
 52: /**
 53:  * Array translating ADOdb column MetaTypes to cake-supported metatypes
 54:  *
 55:  * @var array
 56:  * @access private
 57:  */
 58:     var $_adodbColumnTypes = array(
 59:         'string' => 'C',
 60:         'text' => 'X',
 61:         'date' => 'D',
 62:         'timestamp' => 'T',
 63:         'time' => 'T',
 64:         'datetime' => 'T',
 65:         'boolean' => 'L',
 66:         'float' => 'N',
 67:         'integer' => 'I',
 68:         'binary' => 'R',
 69:     );
 70: /**
 71:  * ADOdb column definition
 72:  *
 73:  * @var array
 74:  */
 75:     var $columns = array(
 76:         'primary_key' => array('name' => 'R', 'limit' => 11),
 77:         'string' => array('name' => 'C', 'limit' => '255'),
 78:         'text' => array('name' => 'X'),
 79:         'integer' => array('name' => 'I', 'limit' => '11', 'formatter' => 'intval'),
 80:         'float' => array('name' => 'N', 'formatter' => 'floatval'),
 81:         'timestamp' => array('name' => 'T', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
 82:         'time' => array('name' => 'T',  'format' => 'H:i:s', 'formatter' => 'date'),
 83:         'datetime' => array('name' => 'T', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
 84:         'date' => array('name' => 'D', 'format' => 'Y-m-d', 'formatter' => 'date'),
 85:         'binary' => array('name' => 'B'),
 86:         'boolean' => array('name' => 'L', 'limit' => '1')
 87:     );
 88: /**
 89:  * Connects to the database using options in the given configuration array.
 90:  *
 91:  * @param array $config Configuration array for connecting
 92:  */
 93:     function connect() {
 94:         $config = $this->config;
 95:         $persistent = strrpos($config['connect'], '|p');
 96: 
 97:         if ($persistent === false) {
 98:             $adodb_driver = $config['connect'];
 99:             $connect = 'Connect';
100:         } else {
101:             $adodb_driver = substr($config['connect'], 0, $persistent);
102:             $connect = 'PConnect';
103:         }
104:         if (!$this->enabled()) {
105:             return false;
106:         }
107:         $this->_adodb = NewADOConnection($adodb_driver);
108: 
109:         $this->_adodbDataDict = NewDataDictionary($this->_adodb, $adodb_driver);
110: 
111:         $this->startQuote = $this->_adodb->nameQuote;
112:         $this->endQuote = $this->_adodb->nameQuote;
113: 
114:         $this->connected = $this->_adodb->$connect($config['host'], $config['login'], $config['password'], $config['database']);
115:         $this->_adodbMetatyper = &$this->_adodb->execute('Select 1');
116:         return $this->connected;
117:     }
118: /**
119:  * Check that AdoDB is available.
120:  *
121:  * @return boolean
122:  **/
123:     function enabled() {
124:         return function_exists('NewADOConnection');
125:     }
126: /**
127:  * Disconnects from database.
128:  *
129:  * @return boolean True if the database could be disconnected, else false
130:  */
131:     function disconnect() {
132:         return $this->_adodb->Close();
133:     }
134: /**
135:  * Executes given SQL statement.
136:  *
137:  * @param string $sql SQL statement
138:  * @return resource Result resource identifier
139:  */
140:     function _execute($sql) {
141:         global $ADODB_FETCH_MODE;
142:         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
143:         return $this->_adodb->execute($sql);
144:     }
145: /**
146:  * Returns a row from current resultset as an array .
147:  *
148:  * @return array The fetched row as an array
149:  */
150:     function fetchRow($sql = null) {
151:         if (!empty($sql) && is_string($sql) && strlen($sql) > 5) {
152:             if (!$this->execute($sql)) {
153:                 return null;
154:             }
155:         }
156: 
157:         if (!$this->hasResult()) {
158:             return null;
159:         } else {
160:             $resultRow = $this->_result->FetchRow();
161:             $this->resultSet($resultRow);
162:             return $this->fetchResult();
163:         }
164:     }
165: /**
166:  * Begin a transaction
167:  *
168:  * @param unknown_type $model
169:  * @return boolean True on success, false on fail
170:  * (i.e. if the database/model does not support transactions).
171:  */
172:     function begin(&$model) {
173:         if (parent::begin($model)) {
174:             if ($this->_adodb->BeginTrans()) {
175:                 $this->_transactionStarted = true;
176:                 return true;
177:             }
178:         }
179:         return false;
180:     }
181: /**
182:  * Commit a transaction
183:  *
184:  * @param unknown_type $model
185:  * @return boolean True on success, false on fail
186:  * (i.e. if the database/model does not support transactions,
187:  * or a transaction has not started).
188:  */
189:     function commit(&$model) {
190:         if (parent::commit($model)) {
191:             $this->_transactionStarted = false;
192:             return $this->_adodb->CommitTrans();
193:         }
194:         return false;
195:     }
196: /**
197:  * Rollback a transaction
198:  *
199:  * @param unknown_type $model
200:  * @return boolean True on success, false on fail
201:  * (i.e. if the database/model does not support transactions,
202:  * or a transaction has not started).
203:  */
204:     function rollback(&$model) {
205:         if (parent::rollback($model)) {
206:             return $this->_adodb->RollbackTrans();
207:         }
208:         return false;
209:     }
210: /**
211:  * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
212:  *
213:  * @return array Array of tablenames in the database
214:  */
215:     function listSources() {
216:         $tables = $this->_adodb->MetaTables('TABLES');
217: 
218:         if (!count($tables) > 0) {
219:             trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
220:             exit;
221:         }
222:         return $tables;
223:     }
224: /**
225:  * Returns an array of the fields in the table used by the given model.
226:  *
227:  * @param AppModel $model Model object
228:  * @return array Fields in table. Keys are name and type
229:  */
230:     function describe(&$model) {
231:         $cache = parent::describe($model);
232:         if ($cache != null) {
233:             return $cache;
234:         }
235: 
236:         $fields = false;
237:         $cols = $this->_adodb->MetaColumns($this->fullTableName($model, false));
238: 
239:         foreach ($cols as $column) {
240:             $fields[$column->name] = array(
241:                                         'type' => $this->column($column->type),
242:                                         'null' => !$column->not_null,
243:                                         'length' => $column->max_length,
244:                                     );
245:             if ($column->has_default) {
246:                 $fields[$column->name]['default'] = $column->default_value;
247:             }
248:             if ($column->primary_key == 1) {
249:                 $fields[$column->name]['key'] = 'primary';
250:             }
251:         }
252: 
253:         $this->__cacheDescription($this->fullTableName($model, false), $fields);
254:         return $fields;
255:     }
256: /**
257:  * Returns a formatted error message from previous database operation.
258:  *
259:  * @return string Error message
260:  */
261:     function lastError() {
262:         return $this->_adodb->ErrorMsg();
263:     }
264: /**
265:  * Returns number of affected rows in previous database operation, or false if no previous operation exists.
266:  *
267:  * @return integer Number of affected rows
268:  */
269:     function lastAffected() {
270:         return $this->_adodb->Affected_Rows();
271:     }
272: /**
273:  * Returns number of rows in previous resultset, or false if no previous resultset exists.
274:  *
275:  * @return integer Number of rows in resultset
276:  */
277:     function lastNumRows() {
278:         return $this->_result ? $this->_result->RecordCount() : false;
279:     }
280: /**
281:  * Returns the ID generated from the previous INSERT operation.
282:  *
283:  * @return int
284:  *
285:  * @Returns the last autonumbering ID inserted. Returns false if function not supported.
286:  */
287:     function lastInsertId() {
288:         return $this->_adodb->Insert_ID();
289:     }
290: /**
291:  * Returns a LIMIT statement in the correct format for the particular database.
292:  *
293:  * @param integer $limit Limit of results returned
294:  * @param integer $offset Offset from which to start results
295:  * @return string SQL limit/offset statement
296:  * @todo Please change output string to whatever select your database accepts. adodb doesn't allow us to get the correct limit string out of it.
297:  */
298:     function limit($limit, $offset = null) {
299:         if ($limit) {
300:             $rt = '';
301:             if (!strpos(strtolower($limit), 'limit') || strpos(strtolower($limit), 'limit') === 0) {
302:                 $rt = ' LIMIT';
303:             }
304: 
305:             if ($offset) {
306:                 $rt .= ' ' . $offset . ',';
307:             }
308: 
309:             $rt .= ' ' . $limit;
310:             return $rt;
311:         }
312:         return null;
313:         // please change to whatever select your database accepts
314:         // adodb doesn't allow us to get the correct limit string out of it
315:     }
316: /**
317:  * Converts database-layer column types to basic types
318:  *
319:  * @param string $real Real database-layer column type (i.e. "varchar(255)")
320:  * @return string Abstract column type (i.e. "string")
321:  */
322:     function column($real) {
323:         $metaTypes = array_flip($this->_adodbColumnTypes);
324: 
325:         $interpreted_type = $this->_adodbMetatyper->MetaType($real);
326: 
327:         if (!isset($metaTypes[$interpreted_type])) {
328:             return 'text';
329:         }
330:         return $metaTypes[$interpreted_type];
331:     }
332: /**
333:  * Returns a quoted and escaped string of $data for use in an SQL statement.
334:  *
335:  * @param string $data String to be prepared for use in an SQL statement
336:  * @param string $column_type The type of the column into which this data will be inserted
337:  * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
338:  * @return string Quoted and escaped data
339:  */
340:     function value($data, $column = null, $safe = false) {
341:         $parent = parent::value($data, $column, $safe);
342:         if ($parent != null) {
343:             return $parent;
344:         }
345: 
346:         if ($data === null) {
347:             return 'NULL';
348:         }
349: 
350:         if ($data === '') {
351:             return "''";
352:         }
353:         return $this->_adodb->qstr($data);
354:     }
355: 
356: /**
357:  * Generates the fields list of an SQL query.
358:  *
359:  * @param Model $model
360:  * @param string $alias Alias tablename
361:  * @param mixed $fields
362:  * @return array
363:  */
364:     function fields(&$model, $alias = null, $fields = array(), $quote = true) {
365:         if (empty($alias)) {
366:             $alias = $model->alias;
367:         }
368:         $fields = parent::fields($model, $alias, $fields, false);
369: 
370:         if (!$quote) {
371:             return $fields;
372:         }
373:         $count = count($fields);
374: 
375:         if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
376:             for ($i = 0; $i < $count; $i++) {
377:                 if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) {
378:                     $prepend = '';
379:                     if (strpos($fields[$i], 'DISTINCT') !== false) {
380:                         $prepend = 'DISTINCT ';
381:                         $fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
382:                     }
383: 
384:                     if (strrpos($fields[$i], '.') === false) {
385:                         $fields[$i] = $prepend . $this->name($alias) . '.' . $this->name($fields[$i]) . ' AS ' . $this->name($alias . '__' . $fields[$i]);
386:                     } else {
387:                         $build = explode('.', $fields[$i]);
388:                         $fields[$i] = $prepend . $this->name($build[0]) . '.' . $this->name($build[1]) . ' AS ' . $this->name($build[0] . '__' . $build[1]);
389:                     }
390:                 }
391:             }
392:         }
393:         return $fields;
394:     }
395: /**
396:  * Build ResultSets and map data
397:  *
398:  * @param array $results
399:  */
400:     function resultSet(&$results) {
401:         $num_fields = count($results);
402:         $fields = array_keys($results);
403:         $this->results =& $results;
404:         $this->map = array();
405:         $index = 0;
406:         $j = 0;
407: 
408:         while ($j < $num_fields) {
409:             $columnName = $fields[$j];
410: 
411:             if (strpos($columnName, '__')) {
412:                 $parts = explode('__', $columnName);
413:                 $this->map[$index++] = array($parts[0], $parts[1]);
414:             } else {
415:                 $this->map[$index++] = array(0, $columnName);
416:             }
417:             $j++;
418:         }
419:     }
420: /**
421:  * Fetches the next row from the current result set
422:  *
423:  * @return unknown
424:  */
425:     function fetchResult() {
426:         if (!empty($this->results)) {
427:             $row = $this->results;
428:             $this->results = null;
429:         } else {
430:             $row = $this->_result->FetchRow();
431:         }
432: 
433:         if (empty($row)) {
434:             return false;
435:         }
436: 
437:         $resultRow = array();
438:         $fields = array_keys($row);
439:         $count = count($fields);
440:         $i = 0;
441:         for ($i = 0; $i < $count; $i++) { //$row as $index => $field) {
442:             list($table, $column) = $this->map[$i];
443:             $resultRow[$table][$column] = $row[$fields[$i]];
444:         }
445:         return $resultRow;
446:     }
447: /**
448:  * Generate a database-native column schema string
449:  *
450:  * @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
451:  *                      where options can be 'default', 'length', or 'key'.
452:  * @return string
453:  */
454:     function buildColumn($column) {
455:         $name = $type = null;
456:         extract(array_merge(array('null' => true), $column));
457: 
458:         if (empty($name) || empty($type)) {
459:             trigger_error('Column name or type not defined in schema', E_USER_WARNING);
460:             return null;
461:         }
462: 
463:         //$metaTypes = array_flip($this->_adodbColumnTypes);
464:         if (!isset($this->_adodbColumnTypes[$type])) {
465:             trigger_error("Column type {$type} does not exist", E_USER_WARNING);
466:             return null;
467:         }
468:         $metaType = $this->_adodbColumnTypes[$type];
469:         $concreteType = $this->_adodbDataDict->ActualType($metaType);
470:         $real = $this->columns[$type];
471: 
472:         //UUIDs are broken so fix them.
473:         if ($type == 'string' && isset($real['length']) && $real['length'] == 36) {
474:             $concreteType = 'CHAR';
475:         }
476: 
477:         $out = $this->name($name) . ' ' . $concreteType;
478: 
479:         if (isset($real['limit']) || isset($real['length']) || isset($column['limit']) || isset($column['length'])) {
480:             if (isset($column['length'])) {
481:                 $length = $column['length'];
482:             } elseif (isset($column['limit'])) {
483:                 $length = $column['limit'];
484:             } elseif (isset($real['length'])) {
485:                 $length = $real['length'];
486:             } else {
487:                 $length = $real['limit'];
488:             }
489:             $out .= '(' . $length . ')';
490:         }
491:         $_notNull = $_default = $_autoInc = $_constraint = $_unsigned = false;
492: 
493:         if (isset($column['key']) && $column['key'] == 'primary' && $type == 'integer') {
494:             $_constraint = '';
495:             $_autoInc = true;
496:         } elseif (isset($column['key']) && $column['key'] == 'primary') {
497:             $_notNull = '';
498:         } elseif (isset($column['default']) && isset($column['null']) && $column['null'] == false) {
499:             $_notNull = true;
500:             $_default = $column['default'];
501:         } elseif ( isset($column['null']) && $column['null'] == true) {
502:             $_notNull = false;
503:             $_default = 'NULL';
504:         }
505:         if (isset($column['default']) && $_default == false) {
506:             $_default = $this->value($column['default']);
507:         }
508:         if (isset($column['null']) && $column['null'] == false) {
509:             $_notNull = true;
510:         }
511:         //use concrete instance of DataDict to make the suffixes for us.
512:         $out .= $this->_adodbDataDict->_CreateSuffix($out, $metaType, $_notNull, $_default, $_autoInc, $_constraint, $_unsigned);
513:         return $out;
514: 
515:     }
516: /**
517:  * Checks if the result is valid
518:  *
519:  * @return boolean True if the result is valid, else false
520:  */
521:     function hasResult() {
522:         return is_object($this->_result) && !$this->_result->EOF;
523:     }
524: }
525: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs