blob: a6f192ad15290d9496534e071ac872c6497f303d [file] [log] [blame]
Timothy Warren817af192012-02-16 08:28:00 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Timothy Warren76e04352012-02-14 11:55:17 -05002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
7 * NOTICE OF LICENSE
Timothy Warren817af192012-02-16 08:28:00 -05008 *
Timothy Warren76e04352012-02-14 11:55:17 -05009 * Licensed under the Open Software License version 3.0
Timothy Warren817af192012-02-16 08:28:00 -050010 *
Timothy Warren76e04352012-02-14 11:55:17 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
Timothy Warren7221f942012-02-14 15:02:33 -050017 * licensing@ellislab.com so we can send you a copy immediately.
Timothy Warren76e04352012-02-14 11:55:17 -050018 *
Timothy Warren7221f942012-02-14 15:02:33 -050019 * @package CodeIgniter
20 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
23 * @link http://codeigniter.com
24 * @since Version 3.0
25 * @filesource
Timothy Warren76e04352012-02-14 11:55:17 -050026 */
27
28// ------------------------------------------------------------------------
29
Timothy Warren76e04352012-02-14 11:55:17 -050030/**
31 * Firebird/Interbase Database Adapter Class
32 *
33 * Note: _DB is an extender class that the app controller
34 * creates dynamically based on whether the active record
35 * class is being used or not.
36 *
Timothy Warren7221f942012-02-14 15:02:33 -050037 * @package CodeIgniter
38 * @subpackage Drivers
39 * @category Database
40 * @author EllisLab Dev Team
41 * @link http://codeigniter.com/user_guide/database/
Timothy Warren76e04352012-02-14 11:55:17 -050042 */
43class CI_DB_interbase_driver extends CI_DB {
44
45 public $dbdriver = 'interbase';
46
47 // The character used to escape with
48 public $_escape_char = '"';
49
50 // clause and character used for LIKE escape sequences
51 public $_like_escape_str = " ESCAPE '%s' ";
52 public $_like_escape_chr = '!';
53
54 /**
55 * The syntax to count rows is slightly different across different
56 * database engines, so this string appears in each driver and is
57 * used for the count_all() and count_all_results() functions.
58 */
59 public $_count_string = "SELECT COUNT(*) AS ";
60 public $_random_keyword = ' Random()'; // database specific random keyword
61
62 // Keeps track of the resource for the current transaction
63 protected $trans;
Timothy Warren817af192012-02-16 08:28:00 -050064
65 /**
66 * Constructor for some overall setup
67 */
68 public function __construct()
69 {
70 if( ! empty($this->hostname) && $this->hostname !== "localhost")
71 {
72 $this->database = $this->hostname.':'.$this->database;
73 }
74 }
Timothy Warren76e04352012-02-14 11:55:17 -050075
76 /**
77 * Non-persistent database connection
78 *
Timothy Warren7221f942012-02-14 15:02:33 -050079 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050080 */
Timothy Warren4be822b2012-02-14 12:07:34 -050081 public function db_connect()
Timothy Warren76e04352012-02-14 11:55:17 -050082 {
Timothy Warren817af192012-02-16 08:28:00 -050083 return @ibase_connect($this->database, $this->username, $this->password, $this->char_set);
Timothy Warren76e04352012-02-14 11:55:17 -050084 }
85
86 // --------------------------------------------------------------------
87
88 /**
89 * Persistent database connection
90 *
Timothy Warren7221f942012-02-14 15:02:33 -050091 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050092 */
Timothy Warren4be822b2012-02-14 12:07:34 -050093 public function db_pconnect()
Timothy Warren76e04352012-02-14 11:55:17 -050094 {
Timothy Warren817af192012-02-16 08:28:00 -050095 return @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set);
Timothy Warren76e04352012-02-14 11:55:17 -050096 }
97
98 // --------------------------------------------------------------------
99
100 /**
101 * Reconnect
102 *
103 * Keep / reestablish the db connection if no queries have been
104 * sent for a length of time exceeding the server's idle timeout
105 *
Timothy Warren7221f942012-02-14 15:02:33 -0500106 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500107 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500108 public function reconnect()
Timothy Warren76e04352012-02-14 11:55:17 -0500109 {
110 // not implemented in Interbase/Firebird
111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Select the database
117 *
Timothy Warren7221f942012-02-14 15:02:33 -0500118 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500119 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500120 public function db_select()
Timothy Warren76e04352012-02-14 11:55:17 -0500121 {
122 // Connection selects the database
123 return TRUE;
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Set client character set
130 *
Timothy Warren7221f942012-02-14 15:02:33 -0500131 * @param string
132 * @param string
133 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500134 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500135 public function db_set_charset($charset, $collation)
Timothy Warren76e04352012-02-14 11:55:17 -0500136 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500137 // Must be determined at connection
Timothy Warren76e04352012-02-14 11:55:17 -0500138 return TRUE;
139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Version number query string
145 *
Timothy Warren7221f942012-02-14 15:02:33 -0500146 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500147 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500148 public function _version()
Timothy Warren76e04352012-02-14 11:55:17 -0500149 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500150 if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
151 {
152 $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
153 return $version;
154 }
155
156 return FALSE;
Timothy Warren76e04352012-02-14 11:55:17 -0500157 }
158
159 // --------------------------------------------------------------------
160
161 /**
162 * Execute the query
163 *
Timothy Warren7221f942012-02-14 15:02:33 -0500164 * @param string an SQL query
165 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500166 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500167 public function _execute($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500168 {
169 $sql = $this->_prep_query($sql);
Timothy Warren7221f942012-02-14 15:02:33 -0500170 return @ibase_query($this->conn_id, $sql);
Timothy Warren76e04352012-02-14 11:55:17 -0500171 }
172
173 // --------------------------------------------------------------------
174
175 /**
176 * Prep the query
177 *
178 * If needed, each database adapter can prep the query string
179 *
Timothy Warren7221f942012-02-14 15:02:33 -0500180 * @param string an SQL query
181 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500182 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500183 public function _prep_query($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500184 {
185 return $sql;
186 }
187
188 // --------------------------------------------------------------------
189
190 /**
191 * Begin Transaction
192 *
Timothy Warren7221f942012-02-14 15:02:33 -0500193 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500194 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500195 public function trans_begin($test_mode = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500196 {
197 if ( ! $this->trans_enabled)
198 {
199 return TRUE;
200 }
201
202 // When transactions are nested we only begin/commit/rollback the outermost ones
203 if ($this->_trans_depth > 0)
204 {
205 return TRUE;
206 }
207
208 // Reset the transaction failure flag.
209 // If the $test_mode flag is set to TRUE transactions will be rolled back
210 // even if the queries produce a successful result.
211 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
212
Timothy Warren7221f942012-02-14 15:02:33 -0500213 $this->trans = @ibase_trans($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500214
215 return TRUE;
216 }
217
218 // --------------------------------------------------------------------
219
220 /**
221 * Commit Transaction
222 *
Timothy Warren7221f942012-02-14 15:02:33 -0500223 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500224 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500225 public function trans_commit()
Timothy Warren76e04352012-02-14 11:55:17 -0500226 {
227 if ( ! $this->trans_enabled)
228 {
229 return TRUE;
230 }
231
232 // When transactions are nested we only begin/commit/rollback the outermost ones
233 if ($this->_trans_depth > 0)
234 {
235 return TRUE;
236 }
237
Timothy Warren7221f942012-02-14 15:02:33 -0500238 @ibase_commit($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500239
240 return TRUE;
241 }
242
243 // --------------------------------------------------------------------
244
245 /**
246 * Rollback Transaction
247 *
Timothy Warren7221f942012-02-14 15:02:33 -0500248 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500249 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500250 public function trans_rollback()
Timothy Warren76e04352012-02-14 11:55:17 -0500251 {
252 if ( ! $this->trans_enabled)
253 {
254 return TRUE;
255 }
256
257 // When transactions are nested we only begin/commit/rollback the outermost ones
258 if ($this->_trans_depth > 0)
259 {
260 return TRUE;
261 }
262
Timothy Warren7221f942012-02-14 15:02:33 -0500263 @ibase_rollback($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500264
265 return TRUE;
266 }
267
268 // --------------------------------------------------------------------
269
270 /**
271 * Escape String
272 *
Timothy Warren7221f942012-02-14 15:02:33 -0500273 * @param string
274 * @param bool whether or not the string will be used in a LIKE condition
275 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500276 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500277 public function escape_str($str, $like = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500278 {
279 if (is_array($str))
280 {
281 foreach ($str as $key => $val)
282 {
283 $str[$key] = $this->escape_str($val, $like);
284 }
285
286 return $str;
287 }
288
289 // escape LIKE condition wildcards
290 if ($like === TRUE)
291 {
292 $str = str_replace( array('%', '_', $this->_like_escape_chr),
293 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
294 $str);
295 }
296
297 return $str;
298 }
299
300 // --------------------------------------------------------------------
301
302 /**
303 * Affected Rows
304 *
Timothy Warren7221f942012-02-14 15:02:33 -0500305 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500306 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500307 public function affected_rows()
Timothy Warren76e04352012-02-14 11:55:17 -0500308 {
Timothy Warren7221f942012-02-14 15:02:33 -0500309 return @ibase_affected_rows($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500310 }
311
312 // --------------------------------------------------------------------
313
314 /**
315 * Insert ID
316 *
Timothy Warren6e821ce2012-02-15 18:40:39 -0500317 * @param string $generator_name
318 * @param integer $inc_by
Timothy Warren7221f942012-02-14 15:02:33 -0500319 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500320 */
Timothy Warren817af192012-02-16 08:28:00 -0500321 public function insert_id($generator_name, $inc_by=0)
Timothy Warren76e04352012-02-14 11:55:17 -0500322 {
Timothy Warren6e821ce2012-02-15 18:40:39 -0500323 return ibase_gen_id($generator_name, $inc_by);
Timothy Warren76e04352012-02-14 11:55:17 -0500324 }
325
326 // --------------------------------------------------------------------
327
328 /**
329 * "Count All" query
330 *
331 * Generates a platform-specific query string that counts all records in
332 * the specified database
333 *
Timothy Warren7221f942012-02-14 15:02:33 -0500334 * @param string
335 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500336 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500337 public function count_all($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500338 {
339 if ($table == '')
340 {
341 return 0;
342 }
343
Timothy Warren817af192012-02-16 08:28:00 -0500344 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . ' FROM ' . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
Timothy Warren76e04352012-02-14 11:55:17 -0500345
346 if ($query->num_rows() == 0)
347 {
348 return 0;
349 }
350
351 $row = $query->row();
352 $this->_reset_select();
353 return (int) $row->numrows;
354 }
355
356 // --------------------------------------------------------------------
357
358 /**
359 * List table query
360 *
361 * Generates a platform-specific query string so that the table names can be fetched
362 *
Timothy Warren7221f942012-02-14 15:02:33 -0500363 * @param boolean
364 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500365 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500366 public function _list_tables($prefix_limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500367 {
368 $sql = <<<SQL
369 SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
370 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
371 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
372SQL;
373
374 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
375 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500376 $sql .= ' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Timothy Warren76e04352012-02-14 11:55:17 -0500377 }
378 return $sql;
379 }
380
381 // --------------------------------------------------------------------
382
383 /**
384 * Show column query
385 *
386 * Generates a platform-specific query string so that the column names can be fetched
387 *
Timothy Warren7221f942012-02-14 15:02:33 -0500388 * @param string the table name
389 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500390 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500391 public function _list_columns($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500392 {
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500393 $sql = <<<SQL
394 SELECT "RDB\$FIELD_NAME" FROM "RDB\$RELATION_FIELDS"
395 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
396 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
397SQL;
398 if($table !== '')
399 {
400 $sql .= ' AND "RDB$RELATION_NAME"='.$table;
401 }
402
403 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500404 }
405
406 // --------------------------------------------------------------------
407
408 /**
409 * Field data query
410 *
411 * Generates a platform-specific query so that the column data can be retrieved
412 *
Timothy Warren7221f942012-02-14 15:02:33 -0500413 * @param string the table name
414 * @return object
Timothy Warren76e04352012-02-14 11:55:17 -0500415 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500416 public function _field_data($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500417 {
Timothy Warren8be31a92012-02-15 11:48:57 -0500418 // Need to find a more efficient way to do this
419 // but Interbase/Firebird seems to lack the
420 // limit clause
421 return "SELECT * FROM {$table}";
Timothy Warren76e04352012-02-14 11:55:17 -0500422 }
423
424 // --------------------------------------------------------------------
425
426 /**
427 * The error message string
428 *
Timothy Warren7221f942012-02-14 15:02:33 -0500429 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500430 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500431 public function _error_message()
Timothy Warren76e04352012-02-14 11:55:17 -0500432 {
433 return ibase_errmsg();
434 }
435
436 // --------------------------------------------------------------------
437
438 /**
439 * The error message number
440 *
Timothy Warren7221f942012-02-14 15:02:33 -0500441 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500442 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500443 public function _error_number()
Timothy Warren76e04352012-02-14 11:55:17 -0500444 {
445 return ibase_errcode();
446 }
447
448 // --------------------------------------------------------------------
449
450 /**
451 * Escape the SQL Identifiers
452 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500453 * This public function escapes column and table names
Timothy Warren76e04352012-02-14 11:55:17 -0500454 *
Timothy Warren7221f942012-02-14 15:02:33 -0500455 * @param string
456 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500457 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500458 public function _escape_identifiers($item)
Timothy Warren76e04352012-02-14 11:55:17 -0500459 {
460 foreach ($this->_reserved_identifiers as $id)
461 {
462 if (strpos($item, '.'.$id) !== FALSE)
463 {
464 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
465
466 // remove duplicates if the user already included the escape
467 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
468 }
469 }
470
471 if (strpos($item, '.') !== FALSE)
472 {
473 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
474 }
475 else
476 {
477 $str = $this->_escape_char.$item.$this->_escape_char;
478 }
479
480 // remove duplicates if the user already included the escape
Timothy Warrend19e47a2012-02-14 23:40:40 -0500481 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Timothy Warren76e04352012-02-14 11:55:17 -0500482 }
483
484 // --------------------------------------------------------------------
485
486 /**
487 * From Tables
488 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500489 * This public function implicitly groups FROM tables so there is no confusion
Timothy Warren76e04352012-02-14 11:55:17 -0500490 * about operator precedence in harmony with SQL standards
491 *
Timothy Warren7221f942012-02-14 15:02:33 -0500492 * @param type
493 * @return type
Timothy Warren76e04352012-02-14 11:55:17 -0500494 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500495 public function _from_tables($tables)
Timothy Warren76e04352012-02-14 11:55:17 -0500496 {
497 if ( ! is_array($tables))
498 {
499 $tables = array($tables);
500 }
501
Timothy Warren817af192012-02-16 08:28:00 -0500502 //Interbase/Firebird doesn't like grouped tables
Timothy Warrend19e47a2012-02-14 23:40:40 -0500503 return implode(', ', $tables);
Timothy Warren76e04352012-02-14 11:55:17 -0500504 }
505
506 // --------------------------------------------------------------------
507
508 /**
509 * Insert statement
510 *
511 * Generates a platform-specific insert string from the supplied data
512 *
Timothy Warren7221f942012-02-14 15:02:33 -0500513 * @param string the table name
514 * @param array the insert keys
515 * @param array the insert values
516 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500517 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500518 public function _insert($table, $keys, $values)
Timothy Warren76e04352012-02-14 11:55:17 -0500519 {
Timothy Warren817af192012-02-16 08:28:00 -0500520 return "INSERT INTO {$table} (".implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
Timothy Warren76e04352012-02-14 11:55:17 -0500521 }
522
523 // --------------------------------------------------------------------
524
525 /**
526 * Update statement
527 *
528 * Generates a platform-specific update string from the supplied data
529 *
Timothy Warren7221f942012-02-14 15:02:33 -0500530 * @param string the table name
531 * @param array the update data
532 * @param array the where clause
533 * @param array the orderby clause
534 * @param array the limit clause
535 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500536 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500537 public function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500538 {
539 foreach ($values as $key => $val)
540 {
541 $valstr[] = $key." = ".$val;
542 }
543
Timothy Warren8be31a92012-02-15 11:48:57 -0500544 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500545
546 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
547
Timothy Warren817af192012-02-16 08:28:00 -0500548 $sql = "UPDATE {$table} SET ".implode(', ', $valstr);
Timothy Warren76e04352012-02-14 11:55:17 -0500549
Timothy Warren817af192012-02-16 08:28:00 -0500550 $sql .= ($where != '' AND count($where) >=1) ? ' WHERE '.implode(' ', $where) : '';
Timothy Warren76e04352012-02-14 11:55:17 -0500551
Timothy Warren8be31a92012-02-15 11:48:57 -0500552 $sql .= $orderby;
Timothy Warren76e04352012-02-14 11:55:17 -0500553
554 return $sql;
555 }
556
557
558 // --------------------------------------------------------------------
559
560 /**
561 * Truncate statement
562 *
563 * Generates a platform-specific truncate string from the supplied data
564 * If the database does not support the truncate() command
Timothy Warren4be822b2012-02-14 12:07:34 -0500565 * This public function maps to "DELETE FROM table"
Timothy Warren76e04352012-02-14 11:55:17 -0500566 *
Timothy Warren7221f942012-02-14 15:02:33 -0500567 * @param string the table name
568 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500569 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500570 public function _truncate($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500571 {
572 return $this->_delete($table);
573 }
574
575 // --------------------------------------------------------------------
576
577 /**
578 * Delete statement
579 *
580 * Generates a platform-specific delete string from the supplied data
581 *
Timothy Warren7221f942012-02-14 15:02:33 -0500582 * @param string the table name
583 * @param array the where clause
584 * @param string the limit clause
585 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500586 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500587 public function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500588 {
589 $conditions = '';
590
591 if (count($where) > 0 OR count($like) > 0)
592 {
593 $conditions = "\nWHERE ";
594 $conditions .= implode("\n", $this->ar_where);
595
596 if (count($where) > 0 && count($like) > 0)
597 {
Timothy Warren817af192012-02-16 08:28:00 -0500598 $conditions .= ' AND ';
Timothy Warren76e04352012-02-14 11:55:17 -0500599 }
600 $conditions .= implode("\n", $like);
601 }
602
Timothy Warren3d985a12012-02-15 11:38:00 -0500603 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500604
Timothy Warren8be31a92012-02-15 11:48:57 -0500605 return "DELETE FROM {$table}{$conditions}";
Timothy Warren76e04352012-02-14 11:55:17 -0500606 }
607
608 // --------------------------------------------------------------------
609
610 /**
611 * Limit string
612 *
613 * Generates a platform-specific LIMIT clause
614 *
Timothy Warren7221f942012-02-14 15:02:33 -0500615 * @param string the sql query string
616 * @param integer the number of rows to limit the query to
617 * @param integer the offset value
618 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500619 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500620 public function _limit($sql, $limit, $offset)
Timothy Warren76e04352012-02-14 11:55:17 -0500621 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500622 //There doesn't seem to be a limit clause?
623 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500624 }
625
626 // --------------------------------------------------------------------
627
628 /**
629 * Close DB Connection
630 *
Timothy Warren7221f942012-02-14 15:02:33 -0500631 * @param resource
632 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500633 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500634 public function _close($conn_id)
Timothy Warren76e04352012-02-14 11:55:17 -0500635 {
Timothy Warren7221f942012-02-14 15:02:33 -0500636 @ibase_close($conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500637 }
Timothy Warren76e04352012-02-14 11:55:17 -0500638}
639
Timothy Warren76e04352012-02-14 11:55:17 -0500640/* End of file interbase_driver.php */
641/* Location: ./system/database/drivers/interbase/interbase_driver.php */