blob: 4044c4529773b51272eea4c26c3167c7314db979 [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
313 if($id = ibase_gen_id('"'.$generator_name.'"', $inc_by) !== 0)
314 {
315 return $id;
316 }
317 return ibase_gen_id('"'.$generator_name.'"', 1);
Timothy Warren76e04352012-02-14 11:55:17 -0500318 }
319
320 // --------------------------------------------------------------------
321
322 /**
323 * "Count All" query
324 *
325 * Generates a platform-specific query string that counts all records in
326 * the specified database
327 *
Timothy Warren7221f942012-02-14 15:02:33 -0500328 * @param string
329 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500330 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500331 public function count_all($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500332 {
333 if ($table == '')
334 {
335 return 0;
336 }
337
Timothy Warren817af192012-02-16 08:28:00 -0500338 $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 -0500339
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500340 $query->result_array();
341
Timothy Warren76e04352012-02-14 11:55:17 -0500342 if ($query->num_rows() == 0)
343 {
344 return 0;
345 }
346
347 $row = $query->row();
348 $this->_reset_select();
349 return (int) $row->numrows;
350 }
351
352 // --------------------------------------------------------------------
353
354 /**
355 * List table query
356 *
357 * Generates a platform-specific query string so that the table names can be fetched
358 *
Timothy Warren7221f942012-02-14 15:02:33 -0500359 * @param boolean
360 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500361 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500362 public function _list_tables($prefix_limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500363 {
364 $sql = <<<SQL
365 SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
366 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
367 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
368SQL;
369
370 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
371 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500372 $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 -0500373 }
374 return $sql;
375 }
376
377 // --------------------------------------------------------------------
378
379 /**
380 * Show column query
381 *
382 * Generates a platform-specific query string so that the column names can be fetched
383 *
Timothy Warren7221f942012-02-14 15:02:33 -0500384 * @param string the table name
385 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500386 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500387 public function _list_columns($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500388 {
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500389 return <<<SQL
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500390 SELECT "RDB\$FIELD_NAME" FROM "RDB\$RELATION_FIELDS"
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500391 WHERE "RDB\$RELATION_NAME"='{$table}';
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500392SQL;
Timothy Warren76e04352012-02-14 11:55:17 -0500393 }
394
395 // --------------------------------------------------------------------
396
397 /**
398 * Field data query
399 *
400 * Generates a platform-specific query so that the column data can be retrieved
401 *
Timothy Warren7221f942012-02-14 15:02:33 -0500402 * @param string the table name
403 * @return object
Timothy Warren76e04352012-02-14 11:55:17 -0500404 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500405 public function _field_data($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500406 {
Timothy Warren8be31a92012-02-15 11:48:57 -0500407 // Need to find a more efficient way to do this
408 // but Interbase/Firebird seems to lack the
409 // limit clause
410 return "SELECT * FROM {$table}";
Timothy Warren76e04352012-02-14 11:55:17 -0500411 }
412
413 // --------------------------------------------------------------------
414
415 /**
416 * The error message string
417 *
Timothy Warren7221f942012-02-14 15:02:33 -0500418 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500419 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500420 public function _error_message()
Timothy Warren76e04352012-02-14 11:55:17 -0500421 {
422 return ibase_errmsg();
423 }
424
425 // --------------------------------------------------------------------
426
427 /**
428 * The error message number
429 *
Timothy Warren7221f942012-02-14 15:02:33 -0500430 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500431 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500432 public function _error_number()
Timothy Warren76e04352012-02-14 11:55:17 -0500433 {
434 return ibase_errcode();
435 }
436
437 // --------------------------------------------------------------------
438
439 /**
440 * Escape the SQL Identifiers
441 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500442 * This public function escapes column and table names
Timothy Warren76e04352012-02-14 11:55:17 -0500443 *
Timothy Warren7221f942012-02-14 15:02:33 -0500444 * @param string
445 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500446 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500447 public function _escape_identifiers($item)
Timothy Warren76e04352012-02-14 11:55:17 -0500448 {
449 foreach ($this->_reserved_identifiers as $id)
450 {
451 if (strpos($item, '.'.$id) !== FALSE)
452 {
453 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
454
455 // remove duplicates if the user already included the escape
456 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
457 }
458 }
459
460 if (strpos($item, '.') !== FALSE)
461 {
462 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
463 }
464 else
465 {
466 $str = $this->_escape_char.$item.$this->_escape_char;
467 }
468
469 // remove duplicates if the user already included the escape
Timothy Warrend19e47a2012-02-14 23:40:40 -0500470 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Timothy Warren76e04352012-02-14 11:55:17 -0500471 }
472
473 // --------------------------------------------------------------------
474
475 /**
476 * From Tables
477 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500478 * This public function implicitly groups FROM tables so there is no confusion
Timothy Warren76e04352012-02-14 11:55:17 -0500479 * about operator precedence in harmony with SQL standards
480 *
Timothy Warren7221f942012-02-14 15:02:33 -0500481 * @param type
482 * @return type
Timothy Warren76e04352012-02-14 11:55:17 -0500483 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500484 public function _from_tables($tables)
Timothy Warren76e04352012-02-14 11:55:17 -0500485 {
486 if ( ! is_array($tables))
487 {
488 $tables = array($tables);
489 }
490
Timothy Warren817af192012-02-16 08:28:00 -0500491 //Interbase/Firebird doesn't like grouped tables
Timothy Warrend19e47a2012-02-14 23:40:40 -0500492 return implode(', ', $tables);
Timothy Warren76e04352012-02-14 11:55:17 -0500493 }
494
495 // --------------------------------------------------------------------
496
497 /**
498 * Insert statement
499 *
500 * Generates a platform-specific insert string from the supplied data
501 *
Timothy Warren7221f942012-02-14 15:02:33 -0500502 * @param string the table name
503 * @param array the insert keys
504 * @param array the insert values
505 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500506 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500507 public function _insert($table, $keys, $values)
Timothy Warren76e04352012-02-14 11:55:17 -0500508 {
Timothy Warren817af192012-02-16 08:28:00 -0500509 return "INSERT INTO {$table} (".implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
Timothy Warren76e04352012-02-14 11:55:17 -0500510 }
511
512 // --------------------------------------------------------------------
513
514 /**
515 * Update statement
516 *
517 * Generates a platform-specific update string from the supplied data
518 *
Timothy Warren7221f942012-02-14 15:02:33 -0500519 * @param string the table name
520 * @param array the update data
521 * @param array the where clause
522 * @param array the orderby clause
523 * @param array the limit clause
524 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500525 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500526 public function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500527 {
528 foreach ($values as $key => $val)
529 {
530 $valstr[] = $key." = ".$val;
531 }
532
Timothy Warren8be31a92012-02-15 11:48:57 -0500533 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500534
535 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
536
Timothy Warren817af192012-02-16 08:28:00 -0500537 $sql = "UPDATE {$table} SET ".implode(', ', $valstr);
Timothy Warren76e04352012-02-14 11:55:17 -0500538
Timothy Warren817af192012-02-16 08:28:00 -0500539 $sql .= ($where != '' AND count($where) >=1) ? ' WHERE '.implode(' ', $where) : '';
Timothy Warren76e04352012-02-14 11:55:17 -0500540
Timothy Warren8be31a92012-02-15 11:48:57 -0500541 $sql .= $orderby;
Timothy Warren76e04352012-02-14 11:55:17 -0500542
543 return $sql;
544 }
545
546
547 // --------------------------------------------------------------------
548
549 /**
550 * Truncate statement
551 *
552 * Generates a platform-specific truncate string from the supplied data
553 * If the database does not support the truncate() command
Timothy Warren4be822b2012-02-14 12:07:34 -0500554 * This public function maps to "DELETE FROM table"
Timothy Warren76e04352012-02-14 11:55:17 -0500555 *
Timothy Warren7221f942012-02-14 15:02:33 -0500556 * @param string the table name
557 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500558 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500559 public function _truncate($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500560 {
561 return $this->_delete($table);
562 }
563
564 // --------------------------------------------------------------------
565
566 /**
567 * Delete statement
568 *
569 * Generates a platform-specific delete string from the supplied data
570 *
Timothy Warren7221f942012-02-14 15:02:33 -0500571 * @param string the table name
572 * @param array the where clause
573 * @param string the limit clause
574 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500575 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500576 public function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500577 {
578 $conditions = '';
579
580 if (count($where) > 0 OR count($like) > 0)
581 {
582 $conditions = "\nWHERE ";
583 $conditions .= implode("\n", $this->ar_where);
584
585 if (count($where) > 0 && count($like) > 0)
586 {
Timothy Warren817af192012-02-16 08:28:00 -0500587 $conditions .= ' AND ';
Timothy Warren76e04352012-02-14 11:55:17 -0500588 }
589 $conditions .= implode("\n", $like);
590 }
591
Timothy Warren3d985a12012-02-15 11:38:00 -0500592 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500593
Timothy Warren8be31a92012-02-15 11:48:57 -0500594 return "DELETE FROM {$table}{$conditions}";
Timothy Warren76e04352012-02-14 11:55:17 -0500595 }
596
597 // --------------------------------------------------------------------
598
599 /**
600 * Limit string
601 *
602 * Generates a platform-specific LIMIT clause
603 *
Timothy Warren7221f942012-02-14 15:02:33 -0500604 * @param string the sql query string
605 * @param integer the number of rows to limit the query to
606 * @param integer the offset value
607 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500608 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500609 public function _limit($sql, $limit, $offset)
Timothy Warren76e04352012-02-14 11:55:17 -0500610 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500611 //There doesn't seem to be a limit clause?
612 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500613 }
614
615 // --------------------------------------------------------------------
616
617 /**
618 * Close DB Connection
619 *
Timothy Warren7221f942012-02-14 15:02:33 -0500620 * @param resource
621 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500622 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500623 public function _close($conn_id)
Timothy Warren76e04352012-02-14 11:55:17 -0500624 {
Timothy Warren7221f942012-02-14 15:02:33 -0500625 @ibase_close($conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500626 }
Timothy Warren76e04352012-02-14 11:55:17 -0500627}
628
Timothy Warren76e04352012-02-14 11:55:17 -0500629/* End of file interbase_driver.php */
630/* Location: ./system/database/drivers/interbase/interbase_driver.php */