-
Notifications
You must be signed in to change notification settings - Fork 360
Idiorm and Firebird #98
Copy link
Copy link
Closed
Milestone
Description
Hi,
I've adapted Idiorm for Firebird (www.firebirdsql.org).
/**
* Return the correct character used to quote identifiers (table
* names, column names etc) by looking at the driver being used by PDO.
*/
protected static function _detect_identifier_quote_character() {
switch(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'pgsql':
case 'sqlsrv':
case 'dblib':
case 'mssql':
case 'sybase':
//
//
case 'firebird':
return '"';
//
//
case 'mysql':
case 'sqlite':
case 'sqlite2':
default:
return '`';
}
}
/**
* Return the correct word LIMIT wordused
* by looking at the driver being used by PDO.
*/
protected static function _detect_identifier_limit_word() {
switch(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
//
//
case 'firebird':
return 'FIRST ';
//
//
default:
return 'LIMIT ';
}
}
/**
* Return the correct word OFFSET wordused
* by looking at the driver being used by PDO.
*/
protected static function _detect_identifier_offset_word() {
switch(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
//
//
case 'firebird':
return 'SKIP ';
//
//
default:
return 'OFFSET ';
}
}
/**
* Tell the ORM that you wish to execute a COUNT query.
* Will return an integer representing the number of
* rows returned.
*/
public function count() {
//$this->select_expr('COUNT(*)', 'count');
//
//
// 'count ' is reseved word in Firebird
$_order_by = $this->_order_by;
$this->_order_by = array(); // MP empty order by...
$this->select_expr('COUNT(*)', 'cnt');
$result = $this->find_one();
$this->_order_by = $_order_by;
return ($result !== false && isset($result->CNT)) ? (int) $result->CNT : 0;
//
//
}
/**
* Build a SELECT statement based on the clauses that have
* been passed to this instance by chaining method calls.
*/
protected function _build_select() {
// If the query is raw, just set the $this->_values to be
// the raw query parameters and return the raw query
if ($this->_is_raw_query) {
$this->_values = $this->_raw_parameters;
return $this->_raw_query;
}
// Build and return the full SELECT statement by concatenating
// the results of calling each separate builder method.
return $this->_join_if_not_empty(" ", array(
$this->_build_select_start(),
$this->_build_join(),
$this->_build_where(),
$this->_build_group_by(),
$this->_build_order_by(),
//
//
(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)=='firebird')?'':$this->_build_limit(),
(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)=='firebird')?'':$this->_build_offset(),
));
//
//
}
/**
* Build the start of the SELECT statement
*/
protected function _build_select_start() {
$result_columns = join(', ', $this->_result_columns);
if ($this->_distinct) {
$result_columns = 'DISTINCT ' . $result_columns;
}
//
//
if(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)=='firebird') {
$limit = $this->_build_limit();
$offset = $this->_build_offset();
}
else {
$limit = '';
$offset = '';
}
$fragment = "SELECT {$limit} {$offset} {$result_columns} FROM " . $this->_quote_identifier($this->_table_name);
if (!is_null($this->_table_alias)) {
$fragment .= " " . $this->_quote_identifier($this->_table_alias);
}
return $fragment;
//
//
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels