->value($model->tablePrefix . $model->table) . " ORDER BY ordinal_position");
foreach($cols as $column) {
$colKey = array_keys($column);
if (isset($column[$colKey[0]]) && !isset($column[0])) {
$column[0] = $column[$colKey[0]];
}
if (isset($column[0])) {
$fields[] = array('name' => $column[0]['name'],
'type' => $this->column($column[0]['type']),
'null' => $column[0]['null'],
'default' => $column[0]['default']
);
}
}
$this->__cacheDescription($model->tablePrefix . $model->table, $fields);
return $fields;
}
/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
* @param string $data String to be prepared for use in an SQL statement
* @return string Quoted and escaped
*/
function name($data) {
if ($data == '*') {
return '*';
}
$pos = strpos($data, '"');
if ($pos === false) {
$data = '"' . str_replace('.', '"."', $data) . '"';
}
return $data;
}
/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
* @param string $data String to be prepared for use in an SQL statement
* @param string $column The column into which this data will be inserted
* @return string Quoted and escaped
* @todo Add logic that formats/escapes data based on column type
*/
function value($data, $column = null) {
$parent = parent::value($data, $column);
if ($parent != null) {
return $parent;
}
if ($data === null) {
return 'NULL';
}
switch($column) {
case 'inet':
if (!strlen($data)){
return 'DEFAULT';
} else {
$data = pg_escape_string($data);
}
break;
case 'integer':
if ($data === '') {
return 'DEFAULT';
} else {
$data = pg_escape_string($data);
}
break;
case 'binary':
$data = pg_escape_bytea($data);
break;
case 'boolean':
$data = $this->boolean((bool)$data);
if ($data === true) {
$data = '1';
} elseif ($data === false) {
$data = '0';
}
break;
default:
$data = pg_escape_string($data);
break;
}
return "'" . $data . "'";
}
/**
* Begin a transaction
*
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions).
*/
function begin(&$model) {
if (parent::begin($model)) {
if ($this->execute('BEGIN')) {
$this->__transactionStarted = true;
return true;
}
}
return false;
}
/**
* Commit a transaction
*
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions,
* or a transaction has not started).
*/
function commit(&$model) {
if (parent::commit($model)) {
$this->__transactionStarted = false;
return $this->execute('COMMIT');
}
return false;
}
/**
* Rollback a transaction
*
* @param unknown_type $model
* @return boolean True on success, false on fail
* (i.e. if the database/model does not support transactions,
* or a transaction has not started).
*/
function rollback(&$model) {
if (parent::rollback($model)) {
return $this->execute('ROLLBACK');
}
return false;
}
/**
* Returns a formatted error message from previous database operation.
*
* @return string Error message
*/
function lastError() {
$last_error = pg_last_error($this->connection);
if ($last_error) {
r