blob: aeea00d7f1ac091cce9277b5cd02613e1b176f16 [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;
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 Warren4be822b2012-02-14 12:07:34 -0500137 public 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 Warren4be822b2012-02-14 12:07:34 -0500156 public 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 Warren4be822b2012-02-14 12:07:34 -0500172 public 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 Warren7221f942012-02-14 15:02:33 -0500227 @ibase_commit($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500228
229 return TRUE;
230 }
231
232 // --------------------------------------------------------------------
233
234 /**
235 * Rollback Transaction
236 *
Timothy Warren7221f942012-02-14 15:02:33 -0500237 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500238 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500239 public function trans_rollback()
Timothy Warren76e04352012-02-14 11:55:17 -0500240 {
241 if ( ! $this->trans_enabled)
242 {
243 return TRUE;
244 }
245
246 // When transactions are nested we only begin/commit/rollback the outermost ones
247 if ($this->_trans_depth > 0)
248 {
249 return TRUE;
250 }
251
Timothy Warren7221f942012-02-14 15:02:33 -0500252 @ibase_rollback($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500253
254 return TRUE;
255 }
256
257 // --------------------------------------------------------------------
258
259 /**
260 * Escape String
261 *
Timothy Warren7221f942012-02-14 15:02:33 -0500262 * @param string
263 * @param bool whether or not the string will be used in a LIKE condition
264 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500265 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500266 public function escape_str($str, $like = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500267 {
268 if (is_array($str))
269 {
270 foreach ($str as $key => $val)
271 {
272 $str[$key] = $this->escape_str($val, $like);
273 }
274
275 return $str;
276 }
277
278 // escape LIKE condition wildcards
279 if ($like === TRUE)
280 {
281 $str = str_replace( array('%', '_', $this->_like_escape_chr),
282 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
283 $str);
284 }
285
286 return $str;
287 }
288
289 // --------------------------------------------------------------------
290
291 /**
292 * Affected Rows
293 *
Timothy Warren7221f942012-02-14 15:02:33 -0500294 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500295 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500296 public function affected_rows()
Timothy Warren76e04352012-02-14 11:55:17 -0500297 {
Timothy Warren7221f942012-02-14 15:02:33 -0500298 return @ibase_affected_rows($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500299 }
300
301 // --------------------------------------------------------------------
302
303 /**
304 * Insert ID
305 *
Timothy Warren6e821ce2012-02-15 18:40:39 -0500306 * @param string $generator_name
307 * @param integer $inc_by
Timothy Warren7221f942012-02-14 15:02:33 -0500308 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500309 */
Timothy Warren817af192012-02-16 08:28:00 -0500310 public function insert_id($generator_name, $inc_by=0)
Timothy Warren76e04352012-02-14 11:55:17 -0500311 {
Timothy Warren07b660b2012-02-20 13:23:06 -0500312 //If a generator hasn't been used before it will return 0
Timothy Warrenfed2d1d2012-02-20 15:42:45 -0500313 return ibase_gen_id('"'.$generator_name.'"', $inc_by);
Timothy Warren76e04352012-02-14 11:55:17 -0500314 }
315
316 // --------------------------------------------------------------------
317
318 /**
319 * "Count All" query
320 *
321 * Generates a platform-specific query string that counts all records in
322 * the specified database
323 *
Timothy Warren7221f942012-02-14 15:02:33 -0500324 * @param string
325 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500326 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500327 public function count_all($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500328 {
329 if ($table == '')
330 {
331 return 0;
332 }
333
Timothy Warren817af192012-02-16 08:28:00 -0500334 $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 -0500335
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500336 $query->result_array();
337
Timothy Warren76e04352012-02-14 11:55:17 -0500338 if ($query->num_rows() == 0)
339 {
340 return 0;
341 }
342
343 $row = $query->row();
344 $this->_reset_select();
345 return (int) $row->numrows;
346 }
347
348 // --------------------------------------------------------------------
349
350 /**
351 * List table query
352 *
353 * Generates a platform-specific query string so that the table names can be fetched
354 *
Timothy Warren7221f942012-02-14 15:02:33 -0500355 * @param boolean
356 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500357 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500358 public function _list_tables($prefix_limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500359 {
360 $sql = <<<SQL
361 SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
362 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
363 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
364SQL;
365
366 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
367 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500368 $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 -0500369 }
370 return $sql;
371 }
372
373 // --------------------------------------------------------------------
374
375 /**
376 * Show column query
377 *
378 * Generates a platform-specific query string so that the column names can be fetched
379 *
Timothy Warren7221f942012-02-14 15:02:33 -0500380 * @param string the table name
381 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500382 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500383 public function _list_columns($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500384 {
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500385 return <<<SQL
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500386 SELECT "RDB\$FIELD_NAME" FROM "RDB\$RELATION_FIELDS"
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500387 WHERE "RDB\$RELATION_NAME"='{$table}';
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500388SQL;
Timothy Warren76e04352012-02-14 11:55:17 -0500389 }
390
391 // --------------------------------------------------------------------
392
393 /**
394 * Field data query
395 *
396 * Generates a platform-specific query so that the column data can be retrieved
397 *
Timothy Warren7221f942012-02-14 15:02:33 -0500398 * @param string the table name
399 * @return object
Timothy Warren76e04352012-02-14 11:55:17 -0500400 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500401 public function _field_data($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500402 {
Timothy Warren8be31a92012-02-15 11:48:57 -0500403 // Need to find a more efficient way to do this
404 // but Interbase/Firebird seems to lack the
405 // limit clause
406 return "SELECT * FROM {$table}";
Timothy Warren76e04352012-02-14 11:55:17 -0500407 }
408
409 // --------------------------------------------------------------------
410
411 /**
412 * The error message string
413 *
Timothy Warren7221f942012-02-14 15:02:33 -0500414 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500415 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500416 public function _error_message()
Timothy Warren76e04352012-02-14 11:55:17 -0500417 {
418 return ibase_errmsg();
419 }
420
421 // --------------------------------------------------------------------
422
423 /**
424 * The error message number
425 *
Timothy Warren7221f942012-02-14 15:02:33 -0500426 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500427 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500428 public function _error_number()
Timothy Warren76e04352012-02-14 11:55:17 -0500429 {
430 return ibase_errcode();
431 }
432
433 // --------------------------------------------------------------------
434
435 /**
436 * Escape the SQL Identifiers
437 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500438 * This public function escapes column and table names
Timothy Warren76e04352012-02-14 11:55:17 -0500439 *
Timothy Warren7221f942012-02-14 15:02:33 -0500440 * @param string
441 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500442 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500443 public function _escape_identifiers($item)
Timothy Warren76e04352012-02-14 11:55:17 -0500444 {
445 foreach ($this->_reserved_identifiers as $id)
446 {
447 if (strpos($item, '.'.$id) !== FALSE)
448 {
449 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
450
451 // remove duplicates if the user already included the escape
452 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
453 }
454 }
455
456 if (strpos($item, '.') !== FALSE)
457 {
458 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
459 }
460 else
461 {
462 $str = $this->_escape_char.$item.$this->_escape_char;
463 }
464
465 // remove duplicates if the user already included the escape
Timothy Warrend19e47a2012-02-14 23:40:40 -0500466 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Timothy Warren76e04352012-02-14 11:55:17 -0500467 }
468
469 // --------------------------------------------------------------------
470
471 /**
472 * From Tables
473 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500474 * This public function implicitly groups FROM tables so there is no confusion
Timothy Warren76e04352012-02-14 11:55:17 -0500475 * about operator precedence in harmony with SQL standards
476 *
Timothy Warren7221f942012-02-14 15:02:33 -0500477 * @param type
478 * @return type
Timothy Warren76e04352012-02-14 11:55:17 -0500479 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500480 public function _from_tables($tables)
Timothy Warren76e04352012-02-14 11:55:17 -0500481 {
482 if ( ! is_array($tables))
483 {
484 $tables = array($tables);
485 }
486
Timothy Warren817af192012-02-16 08:28:00 -0500487 //Interbase/Firebird doesn't like grouped tables
Timothy Warrend19e47a2012-02-14 23:40:40 -0500488 return implode(', ', $tables);
Timothy Warren76e04352012-02-14 11:55:17 -0500489 }
490
491 // --------------------------------------------------------------------
492
493 /**
494 * Insert statement
495 *
496 * Generates a platform-specific insert string from the supplied data
497 *
Timothy Warren7221f942012-02-14 15:02:33 -0500498 * @param string the table name
499 * @param array the insert keys
500 * @param array the insert values
501 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500502 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500503 public function _insert($table, $keys, $values)
Timothy Warren76e04352012-02-14 11:55:17 -0500504 {
Timothy Warren817af192012-02-16 08:28:00 -0500505 return "INSERT INTO {$table} (".implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
Timothy Warren76e04352012-02-14 11:55:17 -0500506 }
507
508 // --------------------------------------------------------------------
509
510 /**
511 * Update statement
512 *
513 * Generates a platform-specific update string from the supplied data
514 *
Timothy Warren7221f942012-02-14 15:02:33 -0500515 * @param string the table name
516 * @param array the update data
517 * @param array the where clause
518 * @param array the orderby clause
519 * @param array the limit clause
520 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500521 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500522 public function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500523 {
524 foreach ($values as $key => $val)
525 {
526 $valstr[] = $key." = ".$val;
527 }
528
Timothy Warren8be31a92012-02-15 11:48:57 -0500529 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500530
531 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
532
Timothy Warren817af192012-02-16 08:28:00 -0500533 $sql = "UPDATE {$table} SET ".implode(', ', $valstr);
Timothy Warren76e04352012-02-14 11:55:17 -0500534
Timothy Warren817af192012-02-16 08:28:00 -0500535 $sql .= ($where != '' AND count($where) >=1) ? ' WHERE '.implode(' ', $where) : '';
Timothy Warren76e04352012-02-14 11:55:17 -0500536
Timothy Warren8be31a92012-02-15 11:48:57 -0500537 $sql .= $orderby;
Timothy Warren76e04352012-02-14 11:55:17 -0500538
539 return $sql;
540 }
541
542
543 // --------------------------------------------------------------------
544
545 /**
546 * Truncate statement
547 *
548 * Generates a platform-specific truncate string from the supplied data
549 * If the database does not support the truncate() command
Timothy Warren4be822b2012-02-14 12:07:34 -0500550 * This public function maps to "DELETE FROM table"
Timothy Warren76e04352012-02-14 11:55:17 -0500551 *
Timothy Warren7221f942012-02-14 15:02:33 -0500552 * @param string the table name
553 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500554 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500555 public function _truncate($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500556 {
557 return $this->_delete($table);
558 }
559
560 // --------------------------------------------------------------------
561
562 /**
563 * Delete statement
564 *
565 * Generates a platform-specific delete string from the supplied data
566 *
Timothy Warren7221f942012-02-14 15:02:33 -0500567 * @param string the table name
568 * @param array the where clause
569 * @param string the limit clause
570 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500571 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500572 public function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500573 {
574 $conditions = '';
575
576 if (count($where) > 0 OR count($like) > 0)
577 {
578 $conditions = "\nWHERE ";
579 $conditions .= implode("\n", $this->ar_where);
580
581 if (count($where) > 0 && count($like) > 0)
582 {
Timothy Warren817af192012-02-16 08:28:00 -0500583 $conditions .= ' AND ';
Timothy Warren76e04352012-02-14 11:55:17 -0500584 }
585 $conditions .= implode("\n", $like);
586 }
587
Timothy Warren3d985a12012-02-15 11:38:00 -0500588 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500589
Timothy Warren8be31a92012-02-15 11:48:57 -0500590 return "DELETE FROM {$table}{$conditions}";
Timothy Warren76e04352012-02-14 11:55:17 -0500591 }
592
593 // --------------------------------------------------------------------
594
595 /**
596 * Limit string
597 *
598 * Generates a platform-specific LIMIT clause
599 *
Timothy Warren7221f942012-02-14 15:02:33 -0500600 * @param string the sql query string
601 * @param integer the number of rows to limit the query to
602 * @param integer the offset value
603 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500604 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500605 public function _limit($sql, $limit, $offset)
Timothy Warren76e04352012-02-14 11:55:17 -0500606 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500607 //There doesn't seem to be a limit clause?
608 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500609 }
610
611 // --------------------------------------------------------------------
612
613 /**
614 * Close DB Connection
615 *
Timothy Warren7221f942012-02-14 15:02:33 -0500616 * @param resource
617 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500618 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500619 public function _close($conn_id)
Timothy Warren76e04352012-02-14 11:55:17 -0500620 {
Timothy Warren7221f942012-02-14 15:02:33 -0500621 @ibase_close($conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500622 }
Timothy Warren76e04352012-02-14 11:55:17 -0500623}
624
Timothy Warren76e04352012-02-14 11:55:17 -0500625/* End of file interbase_driver.php */
626/* Location: ./system/database/drivers/interbase/interbase_driver.php */