blob: 33038ad80e6d183cc45b31297c0621a1921f5578 [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
Timothy Warren95562142012-02-20 17:37:21 -050048 protected $_escape_char = '"';
Timothy Warren76e04352012-02-14 11:55:17 -050049
50 // clause and character used for LIKE escape sequences
Timothy Warren95562142012-02-20 17:37:21 -050051 protected $_like_escape_str = " ESCAPE '%s' ";
52 protected $_like_escape_chr = '!';
Timothy Warren76e04352012-02-14 11:55:17 -050053
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 */
Timothy Warren95562142012-02-20 17:37:21 -050059 protected $_count_string = "SELECT COUNT(*) AS ";
60 protected $_random_keyword = ' Random()'; // database specific random keyword
Timothy Warren76e04352012-02-14 11:55:17 -050061
62 // Keeps track of the resource for the current transaction
63 protected $trans;
64
65 /**
66 * Non-persistent database connection
67 *
Timothy Warren7221f942012-02-14 15:02:33 -050068 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050069 */
Timothy Warren4be822b2012-02-14 12:07:34 -050070 public function db_connect()
Timothy Warren76e04352012-02-14 11:55:17 -050071 {
Timothy Warren3c4281f2012-02-16 19:00:10 -050072 return @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
Timothy Warren76e04352012-02-14 11:55:17 -050073 }
74
75 // --------------------------------------------------------------------
76
77 /**
78 * Persistent database connection
79 *
Timothy Warren7221f942012-02-14 15:02:33 -050080 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050081 */
Timothy Warren4be822b2012-02-14 12:07:34 -050082 public function db_pconnect()
Timothy Warren76e04352012-02-14 11:55:17 -050083 {
Timothy Warren3c4281f2012-02-16 19:00:10 -050084 return @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
Timothy Warren76e04352012-02-14 11:55:17 -050085 }
86
87 // --------------------------------------------------------------------
88
89 /**
90 * Reconnect
91 *
92 * Keep / reestablish the db connection if no queries have been
93 * sent for a length of time exceeding the server's idle timeout
94 *
Timothy Warren7221f942012-02-14 15:02:33 -050095 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -050096 */
Timothy Warren4be822b2012-02-14 12:07:34 -050097 public function reconnect()
Timothy Warren76e04352012-02-14 11:55:17 -050098 {
99 // not implemented in Interbase/Firebird
100 }
101
102 // --------------------------------------------------------------------
103
104 /**
105 * Select the database
106 *
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500107 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500108 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500109 public function db_select()
Timothy Warren76e04352012-02-14 11:55:17 -0500110 {
111 // Connection selects the database
112 return TRUE;
113 }
114
115 // --------------------------------------------------------------------
116
117 /**
118 * Set client character set
119 *
Timothy Warren7221f942012-02-14 15:02:33 -0500120 * @param string
121 * @param string
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500122 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500123 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500124 public function db_set_charset($charset, $collation)
Timothy Warren76e04352012-02-14 11:55:17 -0500125 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500126 // Must be determined at connection
Timothy Warren76e04352012-02-14 11:55:17 -0500127 return TRUE;
128 }
129
130 // --------------------------------------------------------------------
131
132 /**
133 * Version number query string
134 *
Timothy Warren7221f942012-02-14 15:02:33 -0500135 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500136 */
Timothy Warren95562142012-02-20 17:37:21 -0500137 protected function _version()
Timothy Warren76e04352012-02-14 11:55:17 -0500138 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500139 if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
140 {
141 $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
142 return $version;
143 }
144
145 return FALSE;
Timothy Warren76e04352012-02-14 11:55:17 -0500146 }
147
148 // --------------------------------------------------------------------
149
150 /**
151 * Execute the query
152 *
Timothy Warren7221f942012-02-14 15:02:33 -0500153 * @param string an SQL query
154 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500155 */
Timothy Warren95562142012-02-20 17:37:21 -0500156 protected function _execute($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500157 {
158 $sql = $this->_prep_query($sql);
Timothy Warren7221f942012-02-14 15:02:33 -0500159 return @ibase_query($this->conn_id, $sql);
Timothy Warren76e04352012-02-14 11:55:17 -0500160 }
161
162 // --------------------------------------------------------------------
163
164 /**
165 * Prep the query
166 *
167 * If needed, each database adapter can prep the query string
168 *
Timothy Warren7221f942012-02-14 15:02:33 -0500169 * @param string an SQL query
170 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500171 */
Timothy Warren95562142012-02-20 17:37:21 -0500172 protected function _prep_query($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500173 {
174 return $sql;
175 }
176
177 // --------------------------------------------------------------------
178
179 /**
180 * Begin Transaction
181 *
Timothy Warren7221f942012-02-14 15:02:33 -0500182 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500183 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500184 public function trans_begin($test_mode = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500185 {
186 if ( ! $this->trans_enabled)
187 {
188 return TRUE;
189 }
190
191 // When transactions are nested we only begin/commit/rollback the outermost ones
192 if ($this->_trans_depth > 0)
193 {
194 return TRUE;
195 }
196
197 // Reset the transaction failure flag.
198 // If the $test_mode flag is set to TRUE transactions will be rolled back
199 // even if the queries produce a successful result.
200 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
201
Timothy Warren7221f942012-02-14 15:02:33 -0500202 $this->trans = @ibase_trans($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500203
204 return TRUE;
205 }
206
207 // --------------------------------------------------------------------
208
209 /**
210 * Commit Transaction
211 *
Timothy Warren7221f942012-02-14 15:02:33 -0500212 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500213 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500214 public function trans_commit()
Timothy Warren76e04352012-02-14 11:55:17 -0500215 {
216 if ( ! $this->trans_enabled)
217 {
218 return TRUE;
219 }
220
221 // When transactions are nested we only begin/commit/rollback the outermost ones
222 if ($this->_trans_depth > 0)
223 {
224 return TRUE;
225 }
226
Timothy Warren2062a862012-02-20 19:38:10 -0500227 return @ibase_commit($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500228 }
229
230 // --------------------------------------------------------------------
231
232 /**
233 * Rollback Transaction
234 *
Timothy Warren7221f942012-02-14 15:02:33 -0500235 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500236 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500237 public function trans_rollback()
Timothy Warren76e04352012-02-14 11:55:17 -0500238 {
239 if ( ! $this->trans_enabled)
240 {
241 return TRUE;
242 }
243
244 // When transactions are nested we only begin/commit/rollback the outermost ones
245 if ($this->_trans_depth > 0)
246 {
247 return TRUE;
248 }
249
Timothy Warren2062a862012-02-20 19:38:10 -0500250 return @ibase_rollback($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500251 }
252
253 // --------------------------------------------------------------------
254
255 /**
256 * Escape String
257 *
Timothy Warren7221f942012-02-14 15:02:33 -0500258 * @param string
259 * @param bool whether or not the string will be used in a LIKE condition
260 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500261 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500262 public function escape_str($str, $like = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500263 {
264 if (is_array($str))
265 {
266 foreach ($str as $key => $val)
267 {
268 $str[$key] = $this->escape_str($val, $like);
269 }
270
271 return $str;
272 }
273
274 // escape LIKE condition wildcards
275 if ($like === TRUE)
276 {
277 $str = str_replace( array('%', '_', $this->_like_escape_chr),
278 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
279 $str);
280 }
281
282 return $str;
283 }
284
285 // --------------------------------------------------------------------
286
287 /**
288 * Affected Rows
289 *
Timothy Warren7221f942012-02-14 15:02:33 -0500290 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500291 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500292 public function affected_rows()
Timothy Warren76e04352012-02-14 11:55:17 -0500293 {
Timothy Warren7221f942012-02-14 15:02:33 -0500294 return @ibase_affected_rows($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500295 }
296
297 // --------------------------------------------------------------------
298
299 /**
300 * Insert ID
301 *
Timothy Warren125fe732012-02-21 07:58:25 -0500302 * @param string $generator_name
303 * @param integer $inc_by
Timothy Warren7221f942012-02-14 15:02:33 -0500304 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500305 */
Timothy Warren817af192012-02-16 08:28:00 -0500306 public function insert_id($generator_name, $inc_by=0)
Timothy Warren76e04352012-02-14 11:55:17 -0500307 {
Timothy Warren07b660b2012-02-20 13:23:06 -0500308 //If a generator hasn't been used before it will return 0
Timothy Warrenfed2d1d2012-02-20 15:42:45 -0500309 return ibase_gen_id('"'.$generator_name.'"', $inc_by);
Timothy Warren76e04352012-02-14 11:55:17 -0500310 }
311
312 // --------------------------------------------------------------------
313
314 /**
315 * "Count All" query
316 *
317 * Generates a platform-specific query string that counts all records in
318 * the specified database
319 *
Timothy Warren7221f942012-02-14 15:02:33 -0500320 * @param string
321 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500322 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500323 public function count_all($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500324 {
325 if ($table == '')
326 {
327 return 0;
328 }
329
Timothy Warren817af192012-02-16 08:28:00 -0500330 $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 -0500331
332 if ($query->num_rows() == 0)
333 {
334 return 0;
335 }
336
337 $row = $query->row();
338 $this->_reset_select();
339 return (int) $row->numrows;
340 }
341
342 // --------------------------------------------------------------------
343
344 /**
345 * List table query
346 *
347 * Generates a platform-specific query string so that the table names can be fetched
348 *
Timothy Warren7221f942012-02-14 15:02:33 -0500349 * @param boolean
350 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500351 */
Timothy Warren95562142012-02-20 17:37:21 -0500352 protected function _list_tables($prefix_limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500353 {
354 $sql = <<<SQL
355 SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
356 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
357 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
358SQL;
359
360 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
361 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500362 $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 -0500363 }
364 return $sql;
365 }
366
367 // --------------------------------------------------------------------
368
369 /**
370 * Show column query
371 *
372 * Generates a platform-specific query string so that the column names can be fetched
373 *
Timothy Warren7221f942012-02-14 15:02:33 -0500374 * @param string the table name
375 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500376 */
Timothy Warren95562142012-02-20 17:37:21 -0500377 protected function _list_columns($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500378 {
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500379 return <<<SQL
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500380 SELECT "RDB\$FIELD_NAME" FROM "RDB\$RELATION_FIELDS"
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500381 WHERE "RDB\$RELATION_NAME"='{$table}';
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500382SQL;
Timothy Warren76e04352012-02-14 11:55:17 -0500383 }
384
385 // --------------------------------------------------------------------
386
387 /**
388 * Field data query
389 *
390 * Generates a platform-specific query so that the column data can be retrieved
391 *
Timothy Warren7221f942012-02-14 15:02:33 -0500392 * @param string the table name
393 * @return object
Timothy Warren76e04352012-02-14 11:55:17 -0500394 */
Timothy Warren95562142012-02-20 17:37:21 -0500395 protected function _field_data($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500396 {
Timothy Warren8be31a92012-02-15 11:48:57 -0500397 // Need to find a more efficient way to do this
398 // but Interbase/Firebird seems to lack the
399 // limit clause
400 return "SELECT * FROM {$table}";
Timothy Warren76e04352012-02-14 11:55:17 -0500401 }
402
403 // --------------------------------------------------------------------
404
405 /**
406 * The error message string
407 *
Timothy Warren7221f942012-02-14 15:02:33 -0500408 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500409 */
Timothy Warren95562142012-02-20 17:37:21 -0500410 protected function _error_message()
Timothy Warren76e04352012-02-14 11:55:17 -0500411 {
412 return ibase_errmsg();
413 }
414
415 // --------------------------------------------------------------------
416
417 /**
418 * The error message number
419 *
Timothy Warren7221f942012-02-14 15:02:33 -0500420 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500421 */
Timothy Warren95562142012-02-20 17:37:21 -0500422 protected function _error_number()
Timothy Warren76e04352012-02-14 11:55:17 -0500423 {
424 return ibase_errcode();
425 }
426
427 // --------------------------------------------------------------------
428
429 /**
430 * Escape the SQL Identifiers
431 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500432 * This public function escapes column and table names
Timothy Warren76e04352012-02-14 11:55:17 -0500433 *
Timothy Warren7221f942012-02-14 15:02:33 -0500434 * @param string
435 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500436 */
Timothy Warren95562142012-02-20 17:37:21 -0500437 protected function _escape_identifiers($item)
Timothy Warren76e04352012-02-14 11:55:17 -0500438 {
439 foreach ($this->_reserved_identifiers as $id)
440 {
441 if (strpos($item, '.'.$id) !== FALSE)
442 {
443 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
444
445 // remove duplicates if the user already included the escape
446 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
447 }
448 }
449
450 if (strpos($item, '.') !== FALSE)
451 {
452 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
453 }
454 else
455 {
456 $str = $this->_escape_char.$item.$this->_escape_char;
457 }
458
459 // remove duplicates if the user already included the escape
Timothy Warrend19e47a2012-02-14 23:40:40 -0500460 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Timothy Warren76e04352012-02-14 11:55:17 -0500461 }
462
463 // --------------------------------------------------------------------
464
465 /**
466 * From Tables
467 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500468 * This public function implicitly groups FROM tables so there is no confusion
Timothy Warren76e04352012-02-14 11:55:17 -0500469 * about operator precedence in harmony with SQL standards
470 *
Timothy Warren7221f942012-02-14 15:02:33 -0500471 * @param type
472 * @return type
Timothy Warren76e04352012-02-14 11:55:17 -0500473 */
Timothy Warren95562142012-02-20 17:37:21 -0500474 protected function _from_tables($tables)
Timothy Warren76e04352012-02-14 11:55:17 -0500475 {
476 if ( ! is_array($tables))
477 {
478 $tables = array($tables);
479 }
480
Timothy Warren817af192012-02-16 08:28:00 -0500481 //Interbase/Firebird doesn't like grouped tables
Timothy Warrend19e47a2012-02-14 23:40:40 -0500482 return implode(', ', $tables);
Timothy Warren76e04352012-02-14 11:55:17 -0500483 }
484
485 // --------------------------------------------------------------------
486
487 /**
488 * Insert statement
489 *
490 * Generates a platform-specific insert string from the supplied data
491 *
Timothy Warren7221f942012-02-14 15:02:33 -0500492 * @param string the table name
493 * @param array the insert keys
494 * @param array the insert values
495 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500496 */
Timothy Warren95562142012-02-20 17:37:21 -0500497 protected function _insert($table, $keys, $values)
Timothy Warren76e04352012-02-14 11:55:17 -0500498 {
Timothy Warren817af192012-02-16 08:28:00 -0500499 return "INSERT INTO {$table} (".implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
Timothy Warren76e04352012-02-14 11:55:17 -0500500 }
501
502 // --------------------------------------------------------------------
503
504 /**
505 * Update statement
506 *
507 * Generates a platform-specific update string from the supplied data
508 *
Timothy Warren7221f942012-02-14 15:02:33 -0500509 * @param string the table name
510 * @param array the update data
511 * @param array the where clause
512 * @param array the orderby clause
513 * @param array the limit clause
514 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500515 */
Timothy Warren95562142012-02-20 17:37:21 -0500516 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500517 {
518 foreach ($values as $key => $val)
519 {
520 $valstr[] = $key." = ".$val;
521 }
522
Timothy Warren8be31a92012-02-15 11:48:57 -0500523 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500524
525 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
526
Timothy Warren817af192012-02-16 08:28:00 -0500527 $sql = "UPDATE {$table} SET ".implode(', ', $valstr);
Timothy Warren76e04352012-02-14 11:55:17 -0500528
Timothy Warren817af192012-02-16 08:28:00 -0500529 $sql .= ($where != '' AND count($where) >=1) ? ' WHERE '.implode(' ', $where) : '';
Timothy Warren76e04352012-02-14 11:55:17 -0500530
Timothy Warren8be31a92012-02-15 11:48:57 -0500531 $sql .= $orderby;
Timothy Warren76e04352012-02-14 11:55:17 -0500532
533 return $sql;
534 }
535
536
537 // --------------------------------------------------------------------
538
539 /**
540 * Truncate statement
541 *
542 * Generates a platform-specific truncate string from the supplied data
543 * If the database does not support the truncate() command
Timothy Warren4be822b2012-02-14 12:07:34 -0500544 * This public function maps to "DELETE FROM table"
Timothy Warren76e04352012-02-14 11:55:17 -0500545 *
Timothy Warren7221f942012-02-14 15:02:33 -0500546 * @param string the table name
547 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500548 */
Timothy Warren95562142012-02-20 17:37:21 -0500549 protected function _truncate($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500550 {
551 return $this->_delete($table);
552 }
553
554 // --------------------------------------------------------------------
555
556 /**
557 * Delete statement
558 *
559 * Generates a platform-specific delete string from the supplied data
560 *
Timothy Warren7221f942012-02-14 15:02:33 -0500561 * @param string the table name
562 * @param array the where clause
563 * @param string the limit clause
564 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500565 */
Timothy Warren95562142012-02-20 17:37:21 -0500566 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500567 {
568 $conditions = '';
569
570 if (count($where) > 0 OR count($like) > 0)
571 {
572 $conditions = "\nWHERE ";
573 $conditions .= implode("\n", $this->ar_where);
574
575 if (count($where) > 0 && count($like) > 0)
576 {
Timothy Warren817af192012-02-16 08:28:00 -0500577 $conditions .= ' AND ';
Timothy Warren76e04352012-02-14 11:55:17 -0500578 }
579 $conditions .= implode("\n", $like);
580 }
581
Timothy Warren3d985a12012-02-15 11:38:00 -0500582 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500583
Timothy Warren8be31a92012-02-15 11:48:57 -0500584 return "DELETE FROM {$table}{$conditions}";
Timothy Warren76e04352012-02-14 11:55:17 -0500585 }
586
587 // --------------------------------------------------------------------
588
589 /**
590 * Limit string
591 *
592 * Generates a platform-specific LIMIT clause
593 *
Timothy Warren7221f942012-02-14 15:02:33 -0500594 * @param string the sql query string
595 * @param integer the number of rows to limit the query to
596 * @param integer the offset value
597 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500598 */
Timothy Warren95562142012-02-20 17:37:21 -0500599 protected function _limit($sql, $limit, $offset)
Timothy Warren76e04352012-02-14 11:55:17 -0500600 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500601 //There doesn't seem to be a limit clause?
602 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500603 }
604
605 // --------------------------------------------------------------------
606
607 /**
608 * Close DB Connection
609 *
Timothy Warren7221f942012-02-14 15:02:33 -0500610 * @param resource
611 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500612 */
Timothy Warren95562142012-02-20 17:37:21 -0500613 protected function _close($conn_id)
Timothy Warren76e04352012-02-14 11:55:17 -0500614 {
Timothy Warren7221f942012-02-14 15:02:33 -0500615 @ibase_close($conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500616 }
Timothy Warren76e04352012-02-14 11:55:17 -0500617}
618
Timothy Warren76e04352012-02-14 11:55:17 -0500619/* End of file interbase_driver.php */
620/* Location: ./system/database/drivers/interbase/interbase_driver.php */