blob: 8a156af5383f22245c01acef1be06d85cba0390f [file] [log] [blame]
Timothy Warren76e04352012-02-14 11:55:17 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
7 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * 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 * @access private called by the base class
69 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050070 */
Timothy Warren4be822b2012-02-14 12:07:34 -050071 public function db_connect()
Timothy Warren76e04352012-02-14 11:55:17 -050072 {
Timothy Warren7221f942012-02-14 15:02:33 -050073 if ( ! $conn_id = @ibase_connect($this->database, $this->username, $this->password, $this->char_set))
Timothy Warren76e04352012-02-14 11:55:17 -050074 {
Timothy Warrend19e47a2012-02-14 23:40:40 -050075 log_message('error', $this->_error_message());
Timothy Warren76e04352012-02-14 11:55:17 -050076
77 if ($this->db_debug)
78 {
Timothy Warrend19e47a2012-02-14 23:40:40 -050079 $this->display_error($this->_error_message(), '', TRUE);
Timothy Warren76e04352012-02-14 11:55:17 -050080 }
81
82 return FALSE;
83 }
84
85 return $conn_id;
86 }
87
88 // --------------------------------------------------------------------
89
90 /**
91 * Persistent database connection
92 *
Timothy Warren7221f942012-02-14 15:02:33 -050093 * @access private called by the base class
94 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050095 */
Timothy Warren4be822b2012-02-14 12:07:34 -050096 public function db_pconnect()
Timothy Warren76e04352012-02-14 11:55:17 -050097 {
Timothy Warren7221f942012-02-14 15:02:33 -050098 if ( ! $conn_id = @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set))
Timothy Warren76e04352012-02-14 11:55:17 -050099 {
Timothy Warrend19e47a2012-02-14 23:40:40 -0500100 log_message('error', $this->_error_message());
Timothy Warren76e04352012-02-14 11:55:17 -0500101
102 if ($this->db_debug)
103 {
Timothy Warrend19e47a2012-02-14 23:40:40 -0500104 $this->display_error($this->_error_message(), '', TRUE);
Timothy Warren76e04352012-02-14 11:55:17 -0500105 }
106
107 return FALSE;
108 }
109
110 return $conn_id;
111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Reconnect
117 *
118 * Keep / reestablish the db connection if no queries have been
119 * sent for a length of time exceeding the server's idle timeout
120 *
Timothy Warren7221f942012-02-14 15:02:33 -0500121 * @access public
122 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500123 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500124 public function reconnect()
Timothy Warren76e04352012-02-14 11:55:17 -0500125 {
126 // not implemented in Interbase/Firebird
127 }
128
129 // --------------------------------------------------------------------
130
131 /**
132 * Select the database
133 *
Timothy Warren7221f942012-02-14 15:02:33 -0500134 * @access private called by the base class
135 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500136 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500137 public function db_select()
Timothy Warren76e04352012-02-14 11:55:17 -0500138 {
139 // Connection selects the database
140 return TRUE;
141 }
142
143 // --------------------------------------------------------------------
144
145 /**
146 * Set client character set
147 *
Timothy Warren7221f942012-02-14 15:02:33 -0500148 * @access public
149 * @param string
150 * @param string
151 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500152 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500153 public function db_set_charset($charset, $collation)
Timothy Warren76e04352012-02-14 11:55:17 -0500154 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500155 // Must be determined at connection
Timothy Warren76e04352012-02-14 11:55:17 -0500156 return TRUE;
157 }
158
159 // --------------------------------------------------------------------
160
161 /**
162 * Version number query string
163 *
Timothy Warren7221f942012-02-14 15:02:33 -0500164 * @access public
165 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500166 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500167 public function _version()
Timothy Warren76e04352012-02-14 11:55:17 -0500168 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500169 if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
170 {
171 $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
172 return $version;
173 }
174
175 return FALSE;
Timothy Warren76e04352012-02-14 11:55:17 -0500176 }
177
178 // --------------------------------------------------------------------
179
180 /**
181 * Execute the query
182 *
Timothy Warren7221f942012-02-14 15:02:33 -0500183 * @access private called by the base class
184 * @param string an SQL query
185 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500186 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500187 public function _execute($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500188 {
189 $sql = $this->_prep_query($sql);
Timothy Warren7221f942012-02-14 15:02:33 -0500190 return @ibase_query($this->conn_id, $sql);
Timothy Warren76e04352012-02-14 11:55:17 -0500191 }
192
193 // --------------------------------------------------------------------
194
195 /**
196 * Prep the query
197 *
198 * If needed, each database adapter can prep the query string
199 *
Timothy Warren7221f942012-02-14 15:02:33 -0500200 * @access private called by execute()
201 * @param string an SQL query
202 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500203 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500204 public function _prep_query($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500205 {
206 return $sql;
207 }
208
209 // --------------------------------------------------------------------
210
211 /**
212 * Begin Transaction
213 *
Timothy Warren7221f942012-02-14 15:02:33 -0500214 * @access public
215 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500216 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500217 public function trans_begin($test_mode = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500218 {
219 if ( ! $this->trans_enabled)
220 {
221 return TRUE;
222 }
223
224 // When transactions are nested we only begin/commit/rollback the outermost ones
225 if ($this->_trans_depth > 0)
226 {
227 return TRUE;
228 }
229
230 // Reset the transaction failure flag.
231 // If the $test_mode flag is set to TRUE transactions will be rolled back
232 // even if the queries produce a successful result.
233 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
234
Timothy Warren7221f942012-02-14 15:02:33 -0500235 $this->trans = @ibase_trans($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500236
237 return TRUE;
238 }
239
240 // --------------------------------------------------------------------
241
242 /**
243 * Commit Transaction
244 *
Timothy Warren7221f942012-02-14 15:02:33 -0500245 * @access public
246 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500247 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500248 public function trans_commit()
Timothy Warren76e04352012-02-14 11:55:17 -0500249 {
250 if ( ! $this->trans_enabled)
251 {
252 return TRUE;
253 }
254
255 // When transactions are nested we only begin/commit/rollback the outermost ones
256 if ($this->_trans_depth > 0)
257 {
258 return TRUE;
259 }
260
Timothy Warren7221f942012-02-14 15:02:33 -0500261 @ibase_commit($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500262
263 return TRUE;
264 }
265
266 // --------------------------------------------------------------------
267
268 /**
269 * Rollback Transaction
270 *
Timothy Warren7221f942012-02-14 15:02:33 -0500271 * @access public
272 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500273 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500274 public function trans_rollback()
Timothy Warren76e04352012-02-14 11:55:17 -0500275 {
276 if ( ! $this->trans_enabled)
277 {
278 return TRUE;
279 }
280
281 // When transactions are nested we only begin/commit/rollback the outermost ones
282 if ($this->_trans_depth > 0)
283 {
284 return TRUE;
285 }
286
Timothy Warren7221f942012-02-14 15:02:33 -0500287 @ibase_rollback($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500288
289 return TRUE;
290 }
291
292 // --------------------------------------------------------------------
293
294 /**
295 * Escape String
296 *
Timothy Warren7221f942012-02-14 15:02:33 -0500297 * @access public
298 * @param string
299 * @param bool whether or not the string will be used in a LIKE condition
300 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500301 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500302 public function escape_str($str, $like = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500303 {
304 if (is_array($str))
305 {
306 foreach ($str as $key => $val)
307 {
308 $str[$key] = $this->escape_str($val, $like);
309 }
310
311 return $str;
312 }
313
314 // escape LIKE condition wildcards
315 if ($like === TRUE)
316 {
317 $str = str_replace( array('%', '_', $this->_like_escape_chr),
318 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
319 $str);
320 }
321
322 return $str;
323 }
324
325 // --------------------------------------------------------------------
326
327 /**
328 * Affected Rows
329 *
Timothy Warren7221f942012-02-14 15:02:33 -0500330 * @access public
331 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500332 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500333 public function affected_rows()
Timothy Warren76e04352012-02-14 11:55:17 -0500334 {
Timothy Warren7221f942012-02-14 15:02:33 -0500335 return @ibase_affected_rows($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500336 }
337
338 // --------------------------------------------------------------------
339
340 /**
341 * Insert ID
342 *
Timothy Warren7221f942012-02-14 15:02:33 -0500343 * @access public
344 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500345 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500346 public function insert_id()
Timothy Warren76e04352012-02-14 11:55:17 -0500347 {
Timothy Warren7221f942012-02-14 15:02:33 -0500348 //@todo Implement manually
Timothy Warren76e04352012-02-14 11:55:17 -0500349 return 0;
350 }
351
352 // --------------------------------------------------------------------
353
354 /**
355 * "Count All" query
356 *
357 * Generates a platform-specific query string that counts all records in
358 * the specified database
359 *
Timothy Warren7221f942012-02-14 15:02:33 -0500360 * @access public
361 * @param string
362 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500363 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500364 public function count_all($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500365 {
366 if ($table == '')
367 {
368 return 0;
369 }
370
371 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
372
373 if ($query->num_rows() == 0)
374 {
375 return 0;
376 }
377
378 $row = $query->row();
379 $this->_reset_select();
380 return (int) $row->numrows;
381 }
382
383 // --------------------------------------------------------------------
384
385 /**
386 * List table query
387 *
388 * Generates a platform-specific query string so that the table names can be fetched
389 *
Timothy Warren7221f942012-02-14 15:02:33 -0500390 * @access private
391 * @param boolean
392 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500393 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500394 public function _list_tables($prefix_limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500395 {
396 $sql = <<<SQL
397 SELECT "RDB\$RELATION_NAME" FROM "RDB\$RELATIONS"
398 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
399 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
400SQL;
401
402 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
403 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500404 $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 -0500405 }
406 return $sql;
407 }
408
409 // --------------------------------------------------------------------
410
411 /**
412 * Show column query
413 *
414 * Generates a platform-specific query string so that the column names can be fetched
415 *
Timothy Warren7221f942012-02-14 15:02:33 -0500416 * @access public
417 * @param string the table name
418 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500419 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500420 public function _list_columns($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500421 {
Timothy Warreneb6dcf02012-02-15 16:48:51 -0500422 $sql = <<<SQL
423 SELECT "RDB\$FIELD_NAME" FROM "RDB\$RELATION_FIELDS"
424 WHERE "RDB\$RELATION_NAME" NOT LIKE 'RDB$%'
425 AND "RDB\$RELATION_NAME" NOT LIKE 'MON$%'
426SQL;
427 if($table !== '')
428 {
429 $sql .= ' AND "RDB$RELATION_NAME"='.$table;
430 }
431
432 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500433 }
434
435 // --------------------------------------------------------------------
436
437 /**
438 * Field data query
439 *
440 * Generates a platform-specific query so that the column data can be retrieved
441 *
Timothy Warren7221f942012-02-14 15:02:33 -0500442 * @access public
443 * @param string the table name
444 * @return object
Timothy Warren76e04352012-02-14 11:55:17 -0500445 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500446 public function _field_data($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500447 {
Timothy Warren8be31a92012-02-15 11:48:57 -0500448 // Need to find a more efficient way to do this
449 // but Interbase/Firebird seems to lack the
450 // limit clause
451 return "SELECT * FROM {$table}";
Timothy Warren76e04352012-02-14 11:55:17 -0500452 }
453
454 // --------------------------------------------------------------------
455
456 /**
457 * The error message string
458 *
Timothy Warren7221f942012-02-14 15:02:33 -0500459 * @access private
460 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500461 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500462 public function _error_message()
Timothy Warren76e04352012-02-14 11:55:17 -0500463 {
464 return ibase_errmsg();
465 }
466
467 // --------------------------------------------------------------------
468
469 /**
470 * The error message number
471 *
Timothy Warren7221f942012-02-14 15:02:33 -0500472 * @access private
473 * @return integer
Timothy Warren76e04352012-02-14 11:55:17 -0500474 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500475 public function _error_number()
Timothy Warren76e04352012-02-14 11:55:17 -0500476 {
477 return ibase_errcode();
478 }
479
480 // --------------------------------------------------------------------
481
482 /**
483 * Escape the SQL Identifiers
484 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500485 * This public function escapes column and table names
Timothy Warren76e04352012-02-14 11:55:17 -0500486 *
Timothy Warren7221f942012-02-14 15:02:33 -0500487 * @access private
488 * @param string
489 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500490 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500491 public function _escape_identifiers($item)
Timothy Warren76e04352012-02-14 11:55:17 -0500492 {
493 foreach ($this->_reserved_identifiers as $id)
494 {
495 if (strpos($item, '.'.$id) !== FALSE)
496 {
497 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
498
499 // remove duplicates if the user already included the escape
500 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
501 }
502 }
503
504 if (strpos($item, '.') !== FALSE)
505 {
506 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
507 }
508 else
509 {
510 $str = $this->_escape_char.$item.$this->_escape_char;
511 }
512
513 // remove duplicates if the user already included the escape
Timothy Warrend19e47a2012-02-14 23:40:40 -0500514 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Timothy Warren76e04352012-02-14 11:55:17 -0500515 }
516
517 // --------------------------------------------------------------------
518
519 /**
520 * From Tables
521 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500522 * This public function implicitly groups FROM tables so there is no confusion
Timothy Warren76e04352012-02-14 11:55:17 -0500523 * about operator precedence in harmony with SQL standards
524 *
Timothy Warren7221f942012-02-14 15:02:33 -0500525 * @access public
526 * @param type
527 * @return type
Timothy Warren76e04352012-02-14 11:55:17 -0500528 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500529 public function _from_tables($tables)
Timothy Warren76e04352012-02-14 11:55:17 -0500530 {
531 if ( ! is_array($tables))
532 {
533 $tables = array($tables);
534 }
535
Timothy Warrend19e47a2012-02-14 23:40:40 -0500536 return implode(', ', $tables);
Timothy Warren76e04352012-02-14 11:55:17 -0500537 }
538
539 // --------------------------------------------------------------------
540
541 /**
542 * Insert statement
543 *
544 * Generates a platform-specific insert string from the supplied data
545 *
Timothy Warren7221f942012-02-14 15:02:33 -0500546 * @access public
547 * @param string the table name
548 * @param array the insert keys
549 * @param array the insert values
550 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500551 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500552 public function _insert($table, $keys, $values)
Timothy Warren76e04352012-02-14 11:55:17 -0500553 {
Timothy Warrend19e47a2012-02-14 23:40:40 -0500554 return "INSERT INTO {$table} (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
Timothy Warren76e04352012-02-14 11:55:17 -0500555 }
556
557 // --------------------------------------------------------------------
558
559 /**
560 * Update statement
561 *
562 * Generates a platform-specific update string from the supplied data
563 *
Timothy Warren7221f942012-02-14 15:02:33 -0500564 * @access public
565 * @param string the table name
566 * @param array the update data
567 * @param array the where clause
568 * @param array the orderby clause
569 * @param array the limit clause
570 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500571 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500572 public function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500573 {
574 foreach ($values as $key => $val)
575 {
576 $valstr[] = $key." = ".$val;
577 }
578
Timothy Warren8be31a92012-02-15 11:48:57 -0500579 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500580
581 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
582
583 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
584
585 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
586
Timothy Warren8be31a92012-02-15 11:48:57 -0500587 $sql .= $orderby;
Timothy Warren76e04352012-02-14 11:55:17 -0500588
589 return $sql;
590 }
591
592
593 // --------------------------------------------------------------------
594
595 /**
596 * Truncate statement
597 *
598 * Generates a platform-specific truncate string from the supplied data
599 * If the database does not support the truncate() command
Timothy Warren4be822b2012-02-14 12:07:34 -0500600 * This public function maps to "DELETE FROM table"
Timothy Warren76e04352012-02-14 11:55:17 -0500601 *
Timothy Warren7221f942012-02-14 15:02:33 -0500602 * @access public
603 * @param string the table name
604 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500605 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500606 public function _truncate($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500607 {
608 return $this->_delete($table);
609 }
610
611 // --------------------------------------------------------------------
612
613 /**
614 * Delete statement
615 *
616 * Generates a platform-specific delete string from the supplied data
617 *
Timothy Warren7221f942012-02-14 15:02:33 -0500618 * @access public
619 * @param string the table name
620 * @param array the where clause
621 * @param string the limit clause
622 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500623 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500624 public function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500625 {
626 $conditions = '';
627
628 if (count($where) > 0 OR count($like) > 0)
629 {
630 $conditions = "\nWHERE ";
631 $conditions .= implode("\n", $this->ar_where);
632
633 if (count($where) > 0 && count($like) > 0)
634 {
635 $conditions .= " AND ";
636 }
637 $conditions .= implode("\n", $like);
638 }
639
Timothy Warren3d985a12012-02-15 11:38:00 -0500640 //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Timothy Warren76e04352012-02-14 11:55:17 -0500641
Timothy Warren8be31a92012-02-15 11:48:57 -0500642 return "DELETE FROM {$table}{$conditions}";
Timothy Warren76e04352012-02-14 11:55:17 -0500643 }
644
645 // --------------------------------------------------------------------
646
647 /**
648 * Limit string
649 *
650 * Generates a platform-specific LIMIT clause
651 *
Timothy Warren7221f942012-02-14 15:02:33 -0500652 * @access public
653 * @param string the sql query string
654 * @param integer the number of rows to limit the query to
655 * @param integer the offset value
656 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500657 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500658 public function _limit($sql, $limit, $offset)
Timothy Warren76e04352012-02-14 11:55:17 -0500659 {
Timothy Warren3d985a12012-02-15 11:38:00 -0500660 //There doesn't seem to be a limit clause?
661 return $sql;
Timothy Warren76e04352012-02-14 11:55:17 -0500662 }
663
664 // --------------------------------------------------------------------
665
666 /**
667 * Close DB Connection
668 *
Timothy Warren7221f942012-02-14 15:02:33 -0500669 * @access public
670 * @param resource
671 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500672 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500673 public function _close($conn_id)
Timothy Warren76e04352012-02-14 11:55:17 -0500674 {
Timothy Warren7221f942012-02-14 15:02:33 -0500675 @ibase_close($conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500676 }
Timothy Warren76e04352012-02-14 11:55:17 -0500677}
678
Timothy Warren76e04352012-02-14 11:55:17 -0500679/* End of file interbase_driver.php */
680/* Location: ./system/database/drivers/interbase/interbase_driver.php */