code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function _alterTableParameters($table, $parameters) {
if (isset($parameters['change'])) {
return $this->buildTableParameters($parameters['change']);
}
return array();
} | Generate MySQL table parameter alteration statementes for a table.
@param string $table Table to alter parameters for.
@param array $parameters Parameters to add & drop.
@return array Array of table property alteration statementes.
@todo Implement this method. | _alterTableParameters | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function _alterIndexes($table, $indexes) {
$alter = array();
if (isset($indexes['drop'])) {
foreach($indexes['drop'] as $name => $value) {
$out = 'DROP ';
if ($name == 'PRIMARY') {
$out .= 'PRIMARY KEY';
} else {
$out .= 'KEY ' . $name;
}
$alter[] = $out;
}
}
if (isset($indexes['add'])) {
foreach ($indexes['add'] as $name => $value) {
$out = 'ADD ';
if ($name == 'PRIMARY') {
$out .= 'PRIMARY ';
$name = null;
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
}
if (is_array($value['column'])) {
$out .= 'KEY '. $name .' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')';
}
$alter[] = $out;
}
}
return $alter;
} | Generate MySQL index alteration statements for a table.
@param string $table Table to alter indexes for
@param array $new Indexes to add and drop
@return array Index alteration statements | _alterIndexes | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function insertMulti($table, $fields, $values) {
$table = $this->fullTableName($table);
if (is_array($fields)) {
$fields = implode(', ', array_map(array(&$this, 'name'), $fields));
}
$values = implode(', ', $values);
$this->query("INSERT INTO {$table} ({$fields}) VALUES {$values}");
} | Inserts multiple values into a table
@param string $table
@param string $fields
@param array $values | insertMulti | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function listDetailedSources($name = null) {
$condition = '';
if (is_string($name)) {
$condition = ' LIKE ' . $this->value($name);
}
$result = $this->query('SHOW TABLE STATUS FROM ' . $this->name($this->config['database']) . $condition . ';');
if (!$result) {
return array();
} else {
$tables = array();
foreach ($result as $row) {
$tables[$row['TABLES']['Name']] = $row['TABLES'];
if (!empty($row['TABLES']['Collation'])) {
$charset = $this->getCharsetName($row['TABLES']['Collation']);
if ($charset) {
$tables[$row['TABLES']['Name']]['charset'] = $charset;
}
}
}
if (is_string($name)) {
return $tables[$name];
}
return $tables;
}
} | Returns an detailed array of sources (tables) in the database.
@param string $name Table name to get parameters
@return array Array of tablenames in the database | listDetailedSources | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
}
return $col;
}
$col = str_replace(')', '', $real);
$limit = $this->length($real);
if (strpos($col, '(') !== false) {
list($col, $vals) = explode('(', $col);
}
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {
return 'float';
}
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}
return 'text';
} | Converts database-layer column types to basic types
@param string $real Real database-layer column type (i.e. "varchar(255)")
@return string Abstract column type (i.e. "string") | column | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function connect() {
$config = $this->config;
$this->connected = false;
if (!$config['persistent']) {
$this->connection = mysql_connect($config['host'] . ':' . $config['port'], $config['login'], $config['password'], true);
$config['connect'] = 'mysql_connect';
} else {
$this->connection = mysql_pconnect($config['host'] . ':' . $config['port'], $config['login'], $config['password']);
}
if (!$this->connection) {
return false;
}
if (mysql_select_db($config['database'], $this->connection)) {
$this->connected = true;
}
if (!empty($config['encoding'])) {
$this->setEncoding($config['encoding']);
}
$this->_useAlias = (bool)version_compare(mysql_get_server_info($this->connection), "4.1", ">=");
return $this->connected;
} | Connects to the database using options in the given configuration array.
@return boolean True if the database could be connected, else false | connect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function enabled() {
return extension_loaded('mysql');
} | Check whether the MySQL extension is installed/loaded
@return boolean | enabled | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function disconnect() {
if (isset($this->results) && is_resource($this->results)) {
mysql_free_result($this->results);
}
$this->connected = !@mysql_close($this->connection);
return !$this->connected;
} | Disconnects from database.
@return boolean True if the database could be disconnected, else false | disconnect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function _execute($sql) {
return mysql_query($sql, $this->connection);
} | Executes given SQL statement.
@param string $sql SQL statement
@return resource Result resource identifier
@access protected | _execute | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function listSources() {
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';');
if (!$result) {
return array();
} else {
$tables = array();
while ($line = mysql_fetch_row($result)) {
$tables[] = $line[0];
}
parent::listSources($tables);
return $tables;
}
} | Returns an array of sources (tables) in the database.
@return array Array of tablenames in the database | listSources | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function value($data, $column = null, $safe = false) {
$parent = parent::value($data, $column, $safe);
if ($parent != null) {
return $parent;
}
if ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
}
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
if (empty($column)) {
$column = $this->introspectType($data);
}
switch ($column) {
case 'boolean':
return $this->boolean((bool)$data);
break;
case 'integer':
case 'float':
if ($data === '') {
return 'NULL';
}
if (is_float($data)) {
return str_replace(',', '.', strval($data));
}
if ((is_int($data) || $data === '0') || (
is_numeric($data) && strpos($data, ',') === false &&
$data[0] != '0' && strpos($data, 'e') === false)
) {
return $data;
}
default:
return "'" . mysql_real_escape_string($data, $this->connection) . "'";
break;
}
} | 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
@param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
@return string Quoted and escaped data | value | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function lastError() {
if (mysql_errno($this->connection)) {
return mysql_errno($this->connection).': '.mysql_error($this->connection);
}
return null;
} | Returns a formatted error message from previous database operation.
@return string Error message with error number | lastError | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function lastAffected() {
if ($this->_result) {
return mysql_affected_rows($this->connection);
}
return null;
} | Returns number of affected rows in previous database operation. If no previous operation exists,
this returns false.
@return integer Number of affected rows | lastAffected | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function lastNumRows() {
if ($this->hasResult()) {
return mysql_num_rows($this->_result);
}
return null;
} | Returns number of rows in previous resultset. If no previous resultset exists,
this returns false.
@return integer Number of rows in resultset | lastNumRows | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function lastInsertId($source = null) {
$id = $this->fetchRow('SELECT LAST_INSERT_ID() AS insertID', false);
if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0]['insertID'])) {
return $id[0]['insertID'];
}
return null;
} | Returns the ID generated from the previous INSERT operation.
@param unknown_type $source
@return in | lastInsertId | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function fetchResult() {
if ($row = mysql_fetch_row($this->results)) {
$resultRow = array();
$i = 0;
foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index];
$resultRow[$table][$column] = $row[$index];
$i++;
}
return $resultRow;
} else {
return false;
}
} | Fetches the next row from the current result set
@return unknown | fetchResult | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function getEncoding() {
return mysql_client_encoding($this->connection);
} | Gets the database encoding
@return string The database encoding | getEncoding | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function getCharsetName($name) {
if ((bool)version_compare(mysql_get_server_info($this->connection), "5", ">=")) {
$cols = $this->query('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME= ' . $this->value($name) . ';');
if (isset($cols[0]['COLLATIONS']['CHARACTER_SET_NAME'])) {
return $cols[0]['COLLATIONS']['CHARACTER_SET_NAME'];
}
}
return false;
} | Query charset by collation
@param string $name Collation name
@return string Character set name | getCharsetName | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysql.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php | MIT |
function connect() {
$config = $this->config;
$this->connected = false;
$this->connection = mysqli_connect($config['host'], $config['login'], $config['password'], $config['database'], $config['port'], $config['socket']);
if ($this->connection !== false) {
$this->connected = true;
} else {
return false;
}
$this->_useAlias = (bool)version_compare(mysqli_get_server_info($this->connection), "4.1", ">=");
if (!empty($config['encoding'])) {
$this->setEncoding($config['encoding']);
}
return $this->connected;
} | Connects to the database using options in the given configuration array.
@return boolean True if the database could be connected, else false | connect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function enabled() {
return extension_loaded('mysqli');
} | Check that MySQLi is installed/enabled
@return boolean | enabled | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function disconnect() {
if (isset($this->results) && is_resource($this->results)) {
mysqli_free_result($this->results);
}
$this->connected = !@mysqli_close($this->connection);
return !$this->connected;
} | Disconnects from database.
@return boolean True if the database could be disconnected, else false | disconnect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function _execute($sql) {
if (preg_match('/^\s*call/i', $sql)) {
return $this->_executeProcedure($sql);
}
return mysqli_query($this->connection, $sql);
} | Executes given SQL statement.
@param string $sql SQL statement
@return resource Result resource identifier
@access protected | _execute | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function _executeProcedure($sql) {
$answer = mysqli_multi_query($this->connection, $sql);
$firstResult = mysqli_store_result($this->connection);
if (mysqli_more_results($this->connection)) {
while ($lastResult = mysqli_next_result($this->connection));
}
return $firstResult;
} | Executes given SQL statement (procedure call).
@param string $sql SQL statement (procedure call)
@return resource Result resource identifier for first recordset
@access protected | _executeProcedure | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function listSources() {
$cache = parent::listSources();
if ($cache !== null) {
return $cache;
}
$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';');
if (!$result) {
return array();
}
$tables = array();
while ($line = mysqli_fetch_row($result)) {
$tables[] = $line[0];
}
parent::listSources($tables);
return $tables;
} | Returns an array of sources (tables) in the database.
@return array Array of tablenames in the database | listSources | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function value($data, $column = null, $safe = false) {
$parent = parent::value($data, $column, $safe);
if ($parent != null) {
return $parent;
}
if ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
}
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
if (empty($column)) {
$column = $this->introspectType($data);
}
switch ($column) {
case 'boolean':
return $this->boolean((bool)$data);
break;
case 'integer' :
case 'float' :
case null :
if ($data === '') {
return 'NULL';
}
if (is_float($data)) {
return str_replace(',', '.', strval($data));
}
if ((is_int($data) || is_float($data) || $data === '0') || (
is_numeric($data) && strpos($data, ',') === false &&
$data[0] != '0' && strpos($data, 'e') === false)) {
return $data;
}
default:
$data = "'" . mysqli_real_escape_string($this->connection, $data) . "'";
break;
}
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
@param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
@return string Quoted and escaped data | value | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function lastError() {
if (mysqli_errno($this->connection)) {
return mysqli_errno($this->connection).': '.mysqli_error($this->connection);
}
return null;
} | Returns a formatted error message from previous database operation.
@return string Error message with error number | lastError | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function lastAffected() {
if ($this->_result) {
return mysqli_affected_rows($this->connection);
}
return null;
} | Returns number of affected rows in previous database operation. If no previous operation exists,
this returns false.
@return integer Number of affected rows | lastAffected | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function lastNumRows() {
if ($this->hasResult()) {
return mysqli_num_rows($this->_result);
}
return null;
} | Returns number of rows in previous resultset. If no previous resultset exists,
this returns false.
@return integer Number of rows in resultset | lastNumRows | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function lastInsertId($source = null) {
$id = $this->fetchRow('SELECT LAST_INSERT_ID() AS insertID', false);
if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0]['insertID'])) {
return $id[0]['insertID'];
}
return null;
} | Returns the ID generated from the previous INSERT operation.
@param unknown_type $source
@return in | lastInsertId | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function fetchResult() {
if ($row = mysqli_fetch_row($this->results)) {
$resultRow = array();
foreach ($row as $index => $field) {
$table = $column = null;
if (count($this->map[$index]) === 2) {
list($table, $column) = $this->map[$index];
}
$resultRow[$table][$column] = $row[$index];
}
return $resultRow;
}
return false;
} | Fetches the next row from the current result set
@return unknown | fetchResult | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function getEncoding() {
return mysqli_client_encoding($this->connection);
} | Gets the database encoding
@return string The database encoding | getEncoding | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function getCharsetName($name) {
if ((bool)version_compare(mysqli_get_server_info($this->connection), "5", ">=")) {
$cols = $this->query('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME= ' . $this->value($name) . ';');
if (isset($cols[0]['COLLATIONS']['CHARACTER_SET_NAME'])) {
return $cols[0]['COLLATIONS']['CHARACTER_SET_NAME'];
}
}
return false;
} | Query charset by collation
@param string $name Collation name
@return string Character set name | getCharsetName | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function hasResult() {
return is_object($this->_result);
} | Checks if the result is valid
@return boolean True if the result is valid, else false | hasResult | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_mysqli.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_mysqli.php | MIT |
function connect() {
$config = $this->config;
$this->connected = false;
$config['charset'] = !empty($config['charset']) ? $config['charset'] : null;
if (!$config['persistent']) {
$this->connection = ocilogon($config['login'], $config['password'], $config['database'], $config['charset']);
} else {
$this->connection = ociplogon($config['login'], $config['password'], $config['database'], $config['charset']);
}
if ($this->connection) {
$this->connected = true;
if (!empty($config['nls_sort'])) {
$this->execute('ALTER SESSION SET NLS_SORT='.$config['nls_sort']);
}
if (!empty($config['nls_comp'])) {
$this->execute('ALTER SESSION SET NLS_COMP='.$config['nls_comp']);
}
$this->execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
} else {
$this->connected = false;
$this->_setError();
return false;
}
return $this->connected;
} | Connects to the database using options in the given configuration array.
@return boolean True if the database could be connected, else false
@access public | connect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function _setError($source = null, $clear = false) {
if ($source) {
$e = ocierror($source);
} else {
$e = ocierror();
}
$this->_error = $e['message'];
if ($clear) {
$this->_error = null;
}
} | Keeps track of the most recent Oracle error | _setError | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function setEncoding($lang) {
if (!$this->execute('ALTER SESSION SET NLS_LANGUAGE='.$lang)) {
return false;
}
return true;
} | Sets the encoding language of the session
@param string $lang language constant
@return bool | setEncoding | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function getEncoding() {
$sql = 'SELECT VALUE FROM NLS_SESSION_PARAMETERS WHERE PARAMETER=\'NLS_LANGUAGE\'';
if (!$this->execute($sql)) {
return false;
}
if (!$row = $this->fetchRow()) {
return false;
}
return $row[0]['VALUE'];
} | Gets the current encoding language
@return string language constant | getEncoding | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function disconnect() {
if ($this->connection) {
$this->connected = !ocilogoff($this->connection);
return !$this->connected;
}
} | Disconnects from database.
@return boolean True if the database could be disconnected, else false
@access public | disconnect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function _scrapeSQL($sql) {
$sql = str_replace("\"", '', $sql);
$preFrom = preg_split('/\bFROM\b/', $sql);
$preFrom = $preFrom[0];
$find = array('SELECT');
$replace = array('');
$fieldList = trim(str_replace($find, $replace, $preFrom));
$fields = preg_split('/,\s+/', $fieldList);//explode(', ', $fieldList);
$lastTableName = '';
foreach($fields as $key => $value) {
if ($value != 'COUNT(*) AS count') {
if (preg_match('/\s+(\w+(\.\w+)*)$/', $value, $matches)) {
$fields[$key] = $matches[1];
if (preg_match('/^(\w+\.)/', $value, $matches)) {
$fields[$key] = $matches[1] . $fields[$key];
$lastTableName = $matches[1];
}
}
/*
if (preg_match('/(([[:alnum:]_]+)\.[[:alnum:]_]+)(\s+AS\s+(\w+))?$/i', $value, $matches)) {
$fields[$key] = isset($matches[4]) ? $matches[2] . '.' . $matches[4] : $matches[1];
}
*/
}
}
$this->_map = array();
foreach($fields as $f) {
$e = explode('.', $f);
if (count($e) > 1) {
$table = $e[0];
$field = strtolower($e[1]);
} else {
$table = 0;
$field = $e[0];
}
$this->_map[] = array($table, $field);
}
} | Scrape the incoming SQL to create the association map. This is an extremely
experimental method that creates the association maps since Oracle will not tell us.
@param string $sql
@return false if sql is nor a SELECT
@access protected | _scrapeSQL | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function lastNumRows() {
return $this->_numRows;
} | Returns number of rows in previous resultset. If no previous resultset exists,
this returns false.
@return integer Number of rows in resultset
@access public | lastNumRows | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function _execute($sql) {
$this->_statementId = @ociparse($this->connection, $sql);
if (!$this->_statementId) {
$this->_setError($this->connection);
return false;
}
if ($this->__transactionStarted) {
$mode = OCI_DEFAULT;
} else {
$mode = OCI_COMMIT_ON_SUCCESS;
}
if (!@ociexecute($this->_statementId, $mode)) {
$this->_setError($this->_statementId);
return false;
}
$this->_setError(null, true);
switch(ocistatementtype($this->_statementId)) {
case 'DESCRIBE':
case 'SELECT':
$this->_scrapeSQL($sql);
break;
default:
return $this->_statementId;
break;
}
if ($this->_limit >= 1) {
ocisetprefetch($this->_statementId, $this->_limit);
} else {
ocisetprefetch($this->_statementId, 3000);
}
$this->_numRows = ocifetchstatement($this->_statementId, $this->_results, $this->_offset, $this->_limit, OCI_NUM | OCI_FETCHSTATEMENT_BY_ROW);
$this->_currentRow = 0;
$this->limit();
return $this->_statementId;
} | Executes given SQL statement. This is an overloaded method.
@param string $sql SQL statement
@return resource Result resource identifier or null
@access protected | _execute | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function fetchRow() {
if ($this->_currentRow >= $this->_numRows) {
ocifreestatement($this->_statementId);
$this->_map = null;
$this->_results = null;
$this->_currentRow = null;
$this->_numRows = null;
return false;
}
$resultRow = array();
foreach($this->_results[$this->_currentRow] as $index => $field) {
list($table, $column) = $this->_map[$index];
if (strpos($column, ' count')) {
$resultRow[0]['count'] = $field;
} else {
$resultRow[$table][$column] = $this->_results[$this->_currentRow][$index];
}
}
$this->_currentRow++;
return $resultRow;
} | Fetch result row
@return array
@access public | fetchRow | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function fetchResult() {
return $this->fetchRow();
} | Fetches the next row from the current result set
@return unknown | fetchResult | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function sequenceExists($sequence) {
$sql = "SELECT SEQUENCE_NAME FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '$sequence'";
if (!$this->execute($sql)) {
return false;
}
return $this->fetchRow();
} | Checks to see if a named sequence exists
@param string $sequence
@return bool
@access public | sequenceExists | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function createSequence($sequence) {
$sql = "CREATE SEQUENCE $sequence";
return $this->execute($sql);
} | Creates a database sequence
@param string $sequence
@return bool
@access public | createSequence | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function createTrigger($table) {
$sql = "CREATE OR REPLACE TRIGGER pk_$table" . "_trigger BEFORE INSERT ON $table FOR EACH ROW BEGIN SELECT pk_$table.NEXTVAL INTO :NEW.ID FROM DUAL; END;";
return $this->execute($sql);
} | Create trigger
@param string $table
@return mixed
@access public | createTrigger | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function listSources() {
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
$sql = 'SELECT view_name AS name FROM user_views UNION SELECT table_name AS name FROM user_tables';
if (!$this->execute($sql)) {
return false;
}
$sources = array();
while($r = $this->fetchRow()) {
$sources[] = strtolower($r[0]['name']);
}
parent::listSources($sources);
return $sources;
} | Returns an array of tables in the database. If there are no tables, an error is
raised and the application exits.
@return array tablenames in the database
@access public | listSources | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function describe(&$model) {
$table = $this->fullTableName($model, false);
if (!empty($model->sequence)) {
$this->_sequenceMap[$table] = $model->sequence;
} elseif (!empty($model->table)) {
$this->_sequenceMap[$table] = $model->table . '_seq';
}
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM user_tab_columns WHERE table_name = \'';
$sql .= strtoupper($this->fullTableName($model)) . '\'';
if (!$this->execute($sql)) {
return false;
}
$fields = array();
for ($i = 0; $row = $this->fetchRow(); $i++) {
$fields[strtolower($row[0]['COLUMN_NAME'])] = array(
'type'=> $this->column($row[0]['DATA_TYPE']),
'length'=> $row[0]['DATA_LENGTH']
);
}
$this->__cacheDescription($this->fullTableName($model, false), $fields);
return $fields;
} | Returns an array of the fields in given table name.
@param object instance of a model to inspect
@return array Fields in table. Keys are name and type
@access public | describe | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function truncate($table, $reset = 0) {
if (empty($this->_sequences)) {
$sql = "SELECT sequence_name FROM all_sequences";
$this->execute($sql);
while ($row = $this->fetchRow()) {
$this->_sequences[] = strtolower($row[0]['sequence_name']);
}
}
$this->execute('DELETE FROM ' . $this->fullTableName($table));
if (!isset($this->_sequenceMap[$table]) || !in_array($this->_sequenceMap[$table], $this->_sequences)) {
return true;
}
if ($reset === 0) {
$this->execute("SELECT {$this->_sequenceMap[$table]}.nextval FROM dual");
$row = $this->fetchRow();
$currval = $row[$this->_sequenceMap[$table]]['nextval'];
$this->execute("SELECT min_value FROM all_sequences WHERE sequence_name = '{$this->_sequenceMap[$table]}'");
$row = $this->fetchRow();
$min_value = $row[0]['min_value'];
if ($min_value == 1) $min_value = 0;
$offset = -($currval - $min_value);
$this->execute("ALTER SEQUENCE {$this->_sequenceMap[$table]} INCREMENT BY $offset MINVALUE $min_value");
$this->execute("SELECT {$this->_sequenceMap[$table]}.nextval FROM dual");
$this->execute("ALTER SEQUENCE {$this->_sequenceMap[$table]} INCREMENT BY 1");
} else {
//$this->execute("DROP SEQUENCE {$this->_sequenceMap[$table]}");
}
return true;
} | Deletes all the records in a table and drops all associated auto-increment sequences.
Using DELETE instead of TRUNCATE because it causes locking problems.
@param mixed $table A string or model class representing the table to be truncated
@param integer $reset If -1, sequences are dropped, if 0 (default), sequences are reset,
and if 1, sequences are not modified
@return boolean SQL TRUNCATE TABLE statement, false if not applicable.
@access public | truncate | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function constraint($action, $table) {
if (empty($table)) {
trigger_error(__('Must specify table to operate on constraints', true));
}
$table = strtoupper($table);
if (empty($this->_keyConstraints)) {
$sql = "SELECT
table_name,
c.constraint_name
FROM all_cons_columns cc
LEFT JOIN all_indexes i ON (cc.constraint_name = i.index_name)
LEFT JOIN all_constraints c ON(c.constraint_name = cc.constraint_name)";
$this->execute($sql);
while ($row = $this->fetchRow()) {
$this->_keyConstraints[] = array($row[0]['table_name'], $row['c']['constraint_name']);
}
}
$relatedKeys = array();
foreach ($this->_keyConstraints as $c) {
if ($c[0] == $table) {
$relatedKeys[] = $c[1];
}
}
if (empty($this->_constraints)) {
$sql = "SELECT
table_name,
constraint_name,
r_constraint_name
FROM
all_constraints";
$this->execute($sql);
while ($row = $this->fetchRow()) {
$this->_constraints[] = $row[0];
}
}
$constraints = array();
foreach ($this->_constraints as $c) {
if (in_array($c['r_constraint_name'], $relatedKeys)) {
$constraints[] = array($c['table_name'], $c['constraint_name']);
}
}
foreach ($constraints as $c) {
list($table, $constraint) = $c;
switch ($action) {
case 'enable':
$this->execute("ALTER TABLE $table ENABLE CONSTRAINT $constraint");
break;
case 'disable':
$this->execute("ALTER TABLE $table DISABLE CONSTRAINT $constraint");
break;
case 'list':
return $constraints;
break;
default:
trigger_error(__('DboOracle::constraint() accepts only enable, disable, or list', true));
}
}
return true;
} | Enables, disables, and lists table constraints
Note: This method could have been written using a subselect for each table,
however the effort Oracle expends to run the constraint introspection is very high.
Therefore, this method caches the result once and loops through the arrays to find
what it needs. It reduced my query time by 50%. YMMV.
@param string $action
@param string $table
@return mixed boolean true or array of constraints | constraint | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function index($model) {
$index = array();
$table = $this->fullTableName($model, false);
if ($table) {
$indexes = $this->query('SELECT
cc.table_name,
cc.column_name,
cc.constraint_name,
c.constraint_type,
i.index_name,
i.uniqueness
FROM all_cons_columns cc
LEFT JOIN all_indexes i ON(cc.constraint_name = i.index_name)
LEFT JOIN all_constraints c ON(c.constraint_name = cc.constraint_name)
WHERE cc.table_name = \'' . strtoupper($table) .'\'');
foreach ($indexes as $i => $idx) {
if ($idx['c']['constraint_type'] == 'P') {
$key = 'PRIMARY';
} else {
continue;
}
if (!isset($index[$key])) {
$index[$key]['column'] = strtolower($idx['cc']['column_name']);
$index[$key]['unique'] = intval($idx['i']['uniqueness'] == 'UNIQUE');
} else {
if (!is_array($index[$key]['column'])) {
$col[] = $index[$key]['column'];
}
$col[] = strtolower($idx['cc']['column_name']);
$index[$key]['column'] = $col;
}
}
}
return $index;
} | Returns an array of the indexes in given table name.
@param string $model Name of model to inspect
@return array Fields in table. Keys are column and unique | index | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function alterSchema($compare, $table = null) {
if (!is_array($compare)) {
return false;
}
$out = '';
$colList = array();
foreach($compare as $curTable => $types) {
if (!$table || $table == $curTable) {
$out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
foreach($types as $type => $column) {
switch($type) {
case 'add':
foreach($column as $field => $col) {
$col['name'] = $field;
$alter = 'ADD '.$this->buildColumn($col);
if (isset($col['after'])) {
$alter .= ' AFTER '. $this->name($col['after']);
}
$colList[] = $alter;
}
break;
case 'drop':
foreach($column as $field => $col) {
$col['name'] = $field;
$colList[] = 'DROP '.$this->name($field);
}
break;
case 'change':
foreach($column as $field => $col) {
if (!isset($col['name'])) {
$col['name'] = $field;
}
$colList[] = 'CHANGE '. $this->name($field).' '.$this->buildColumn($col);
}
break;
}
}
$out .= "\t" . implode(",\n\t", $colList) . ";\n\n";
}
}
return $out;
} | Generate a Oracle Alter Table syntax for the given Schema comparison
@param unknown_type $schema
@return unknown | alterSchema | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function name($name) {
if (strpos($name, '.') !== false && strpos($name, '"') === false) {
list($model, $field) = explode('.', $name);
if ($field[0] == "_") {
$name = "$model.\"$field\"";
}
} else {
if ($name[0] == "_") {
$name = "\"$name\"";
}
}
return $name;
} | This method should quote Oracle identifiers. Well it doesn't.
It would break all scaffolding and all of Cake's default assumptions.
@param unknown_type $var
@return unknown
@access public | name | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function begin() {
$this->__transactionStarted = true;
return true;
} | 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). | begin | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function rollback() {
return ocirollback($this->connection);
} | 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). | rollback | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
}
return $col;
} else {
$real = strtolower($real);
}
$col = str_replace(')', '', $real);
$limit = null;
if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}
if (in_array($col, array('date', 'timestamp'))) {
return $col;
}
if (strpos($col, 'number') !== false) {
return 'integer';
}
if (strpos($col, 'integer') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false) {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false) {
return 'binary';
}
if (in_array($col, array('float', 'double', 'decimal'))) {
return 'float';
}
if ($col == 'boolean') {
return $col;
}
return 'text';
} | Converts database-layer column types to basic types
@param string $real Real database-layer column type (i.e. "varchar(255)")
@return string Abstract column type (i.e. "string")
@access public | column | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function value($data, $column = null, $safe = false) {
$parent = parent::value($data, $column, $safe);
if ($parent != null) {
return $parent;
}
if ($data === null) {
return 'NULL';
}
if ($data === '') {
return "''";
}
switch($column) {
case 'date':
$data = date('Y-m-d H:i:s', strtotime($data));
$data = "TO_DATE('$data', 'YYYY-MM-DD HH24:MI:SS')";
break;
case 'integer' :
case 'float' :
case null :
if (is_numeric($data)) {
break;
}
default:
$data = str_replace("'", "''", $data);
$data = "'$data'";
break;
}
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
@return string Quoted and escaped
@access public | value | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function lastInsertId($source) {
$sequence = $this->_sequenceMap[$source];
$sql = "SELECT $sequence.currval FROM dual";
if (!$this->execute($sql)) {
return false;
}
while($row = $this->fetchRow()) {
return $row[$sequence]['currval'];
}
return false;
} | Returns the ID generated from the previous INSERT operation.
@param string
@return integer
@access public | lastInsertId | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function lastError() {
return $this->_error;
} | Returns a formatted error message from previous database operation.
@return string Error message with error number
@access public | lastError | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function lastAffected() {
return $this->_statementId ? ocirowcount($this->_statementId): false;
} | Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
@return int Number of affected rows
@access public | lastAffected | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function renderStatement($type, $data) {
extract($data);
$aliases = null;
switch (strtolower($type)) {
case 'select':
return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}";
break;
case 'create':
return "INSERT INTO {$table} ({$fields}) VALUES ({$values})";
break;
case 'update':
if (!empty($alias)) {
$aliases = "{$this->alias}{$alias} ";
}
return "UPDATE {$table} {$aliases}SET {$fields} {$conditions}";
break;
case 'delete':
if (!empty($alias)) {
$aliases = "{$this->alias}{$alias} ";
}
return "DELETE FROM {$table} {$aliases}{$conditions}";
break;
case 'schema':
foreach (array('columns', 'indexes') as $var) {
if (is_array(${$var})) {
${$var} = "\t" . implode(",\n\t", array_filter(${$var}));
}
}
if (trim($indexes) != '') {
$columns .= ',';
}
return "CREATE TABLE {$table} (\n{$columns}{$indexes})";
break;
case 'alter':
break;
}
} | Renders a final SQL statement by putting together the component parts in the correct order
@param string $type
@param array $data
@return string | renderStatement | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) {
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
if (!isset($resultSet) || !is_array($resultSet)) {
if (Configure::read() > 0) {
echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ';
if (isset($this->error) && $this->error != null) {
echo $this->error;
}
echo '</div>';
}
return null;
}
$count = count($resultSet);
if ($type === 'hasMany' && (!isset($assocData['limit']) || empty($assocData['limit']))) {
$ins = $fetch = array();
for ($i = 0; $i < $count; $i++) {
if ($in = $this->insertQueryData('{$__cakeID__$}', $resultSet[$i], $association, $assocData, $model, $linkModel, $stack)) {
$ins[] = $in;
}
}
if (!empty($ins)) {
$fetch = array();
$ins = array_chunk($ins, 1000);
foreach ($ins as $i) {
$q = str_replace('{$__cakeID__$}', implode(', ', $i), $query);
$q = str_replace('= (', 'IN (', $q);
$res = $this->fetchAll($q, $model->cacheQueries, $model->alias);
$fetch = array_merge($fetch, $res);
}
}
if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) {
foreach ($linkModel->__associations as $type1) {
foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assoc1};
$tmpStack = $stack;
$tmpStack[] = $assoc1;
if ($linkModel->useDbConfig === $deepModel->useDbConfig) {
$db =& $this;
} else {
$db =& ConnectionManager::getDataSource($deepModel->useDbConfig);
}
$db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
}
}
}
}
return $this->__mergeHasMany($resultSet, $fetch, $association, $model, $linkModel, $recursive);
} elseif ($type === 'hasAndBelongsToMany') {
$ins = $fetch = array();
for ($i = 0; $i < $count; $i++) {
if ($in = $this->insertQueryData('{$__cakeID__$}', $resultSet[$i], $association, $assocData, $model, $linkModel, $stack)) {
$ins[] = $in;
}
}
$foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey'];
$joinKeys = array($foreignKey, $model->hasAndBelongsToMany[$association]['associationForeignKey']);
list($with, $habtmFields) = $model->joinModel($model->hasAndBelongsToMany[$association]['with'], $joinKeys);
$habtmFieldsCount = count($habtmFields);
if (!empty($ins)) {
$fetch = array();
$ins = array_chunk($ins, 1000);
foreach ($ins as $i) {
$q = str_replace('{$__cakeID__$}', '(' .implode(', ', $i) .')', $query);
$q = str_replace('= (', 'IN (', $q);
$q = str_replace(' WHERE 1 = 1', '', $q);
$q = $this->insertQueryData($q, null, $association, $assocData, $model, $linkModel, $stack);
if ($q != false) {
$res = $this->fetchAll($q, $model->cacheQueries, $model->alias);
$fetch = array_merge($fetch, $res);
}
}
}
}
for ($i = 0; $i < $count; $i++) {
$row =& $resultSet[$i];
if ($type !== 'hasAndBelongsToMany') {
$q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack);
if ($q != false) {
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->alias);
} else {
$fetch = null;
}
}
if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) {
foreach ($linkModel->__associations as $type1) {
foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assoc1};
if (($type1 === 'belongsTo') || ($deepModel->alias === $model->alias && $type === 'belongsTo') || ($deepModel->alias != $model->alias)) {
$tmpStack = $stack;
$tmpStack[] = $assoc1;
if ($linkModel->useDbConfig == $deepModel->useDbConfig) {
$db =& $this;
} else {
$db =& ConnectionManager::getDataSource($deepModel->useDbConfig);
}
$db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
}
}
}
}
if ($type == 'hasAndBelongsToMany') {
$merge = array();
foreach($fetch as $j => $data) {
if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) {
if ($habtmFieldsCount > 2) {
$merge[] = $data;
} else {
$merge[] = Set::diff($data, array($with => $data[$with]));
}
}
}
if (empty($merge) && !isset($row[$association])) {
$row[$association] = $merge;
} else {
$this->__mergeAssociation($resultSet[$i], $merge, $association, $type);
}
} else {
$this->__mergeAssociation($resultSet[$i], $fetch, $association, $type);
}
$resultSet[$i][$association] = $linkModel->afterfind($resultSet[$i][$association]);
} else {
$tempArray[0][$association] = false;
$this->__mergeAssociation($resultSet[$i], $tempArray, $association, $type);
}
}
}
} | Enter description here...
@param Model $model
@param unknown_type $linkModel
@param string $type Association type
@param unknown_type $association
@param unknown_type $assocData
@param unknown_type $queryData
@param unknown_type $external
@param unknown_type $resultSet
@param integer $recursive Number of levels of association
@param array $stack | queryAssociation | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function dropSchema($schema, $table = null) {
if (!is_a($schema, 'CakeSchema')) {
trigger_error(__('Invalid schema object', true), E_USER_WARNING);
return null;
}
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
$out .= 'DROP TABLE ' . $this->fullTableName($curTable) . "\n";
}
}
return $out;
} | Generate a "drop table" statement for the given Schema object
@param object $schema An instance of a subclass of CakeSchema
@param string $table Optional. If specified only the table name given will be generated.
Otherwise, all tables defined in the schema are generated.
@return string | dropSchema | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_oracle.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_oracle.php | MIT |
function connect() {
$config = $this->config;
$conn = "host='{$config['host']}' port='{$config['port']}' dbname='{$config['database']}' ";
$conn .= "user='{$config['login']}' password='{$config['password']}'";
if (!$config['persistent']) {
$this->connection = pg_connect($conn, PGSQL_CONNECT_FORCE_NEW);
} else {
$this->connection = pg_pconnect($conn);
}
$this->connected = false;
if ($this->connection) {
$this->connected = true;
$this->_execute("SET search_path TO " . $config['schema']);
}
if (!empty($config['encoding'])) {
$this->setEncoding($config['encoding']);
}
return $this->connected;
} | Connects to the database using options in the given configuration array.
@return True if successfully connected. | connect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function enabled() {
return extension_loaded('pgsql');
} | Check if PostgreSQL is enabled/loaded
@return boolean | enabled | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function disconnect() {
if ($this->hasResult()) {
pg_free_result($this->_result);
}
if (is_resource($this->connection)) {
$this->connected = !pg_close($this->connection);
} else {
$this->connected = false;
}
return !$this->connected;
} | Disconnects from database.
@return boolean True if the database could be disconnected, else false | disconnect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function _execute($sql) {
return pg_query($this->connection, $sql);
} | Executes given SQL statement.
@param string $sql SQL statement
@return resource Result resource identifier | _execute | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function listSources() {
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
$schema = $this->config['schema'];
$sql = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = '{$schema}';";
$result = $this->fetchAll($sql, false);
if (!$result) {
return array();
} else {
$tables = array();
foreach ($result as $item) {
$tables[] = $item[0]['name'];
}
parent::listSources($tables);
return $tables;
}
} | Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
@return array Array of tablenames in the database | listSources | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function &describe(&$model) {
$fields = parent::describe($model);
$table = $this->fullTableName($model, false);
$this->_sequenceMap[$table] = array();
if ($fields === null) {
$cols = $this->fetchAll(
"SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null,
column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,
character_octet_length AS oct_length FROM information_schema.columns
WHERE table_name = " . $this->value($table) . " AND table_schema = " .
$this->value($this->config['schema'])." ORDER BY position",
false
);
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])) {
$c = $column[0];
if (!empty($c['char_length'])) {
$length = intval($c['char_length']);
} elseif (!empty($c['oct_length'])) {
if ($c['type'] == 'character varying') {
$length = null;
$c['type'] = 'text';
} else {
$length = intval($c['oct_length']);
}
} else {
$length = $this->length($c['type']);
}
$fields[$c['name']] = array(
'type' => $this->column($c['type']),
'null' => ($c['null'] == 'NO' ? false : true),
'default' => preg_replace(
"/^'(.*)'$/",
"$1",
preg_replace('/::.*/', '', $c['default'])
),
'length' => $length
);
if ($c['name'] == $model->primaryKey) {
$fields[$c['name']]['key'] = 'primary';
if ($fields[$c['name']]['type'] !== 'string') {
$fields[$c['name']]['length'] = 11;
}
}
if (
$fields[$c['name']]['default'] == 'NULL' ||
preg_match('/nextval\([\'"]?([\w.]+)/', $c['default'], $seq)
) {
$fields[$c['name']]['default'] = null;
if (!empty($seq) && isset($seq[1])) {
$this->_sequenceMap[$table][$c['name']] = $seq[1];
}
}
if ($fields[$c['name']]['type'] == 'boolean' && !empty($fields[$c['name']]['default'])) {
$fields[$c['name']]['default'] = constant($fields[$c['name']]['default']);
}
}
}
$this->__cacheDescription($table, $fields);
}
if (isset($model->sequence)) {
$this->_sequenceMap[$table][$model->primaryKey] = $model->sequence;
}
return $fields;
} | Returns an array of the fields in given table name.
@param string $tableName Name of database table to inspect
@return array Fields in table. Keys are name and type | describe | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function value($data, $column = null, $read = true) {
$parent = parent::value($data, $column);
if ($parent != null) {
return $parent;
}
if ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
}
if (empty($column)) {
$column = $this->introspectType($data);
}
switch($column) {
case 'binary':
$data = pg_escape_bytea($data);
break;
case 'boolean':
if ($data === true || $data === 't' || $data === 'true') {
return 'TRUE';
} elseif ($data === false || $data === 'f' || $data === 'false') {
return 'FALSE';
}
return (!empty($data) ? 'TRUE' : 'FALSE');
break;
case 'float':
if (is_float($data)) {
$data = sprintf('%F', $data);
}
case 'inet':
case 'integer':
case 'date':
case 'datetime':
case 'timestamp':
case 'time':
if ($data === '') {
return $read ? 'NULL' : 'DEFAULT';
}
default:
$data = pg_escape_string($data);
break;
}
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
@param boolean $read Value to be used in READ or WRITE context
@return string Quoted and escaped
@todo Add logic that formats/escapes data based on column type | value | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function lastError() {
$error = pg_last_error($this->connection);
return ($error) ? $error : null;
} | Returns a formatted error message from previous database operation.
@return string Error message | lastError | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function lastAffected() {
return ($this->_result) ? pg_affected_rows($this->_result) : false;
} | Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
@return integer Number of affected rows | lastAffected | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function lastNumRows() {
return ($this->_result) ? pg_num_rows($this->_result) : false;
} | Returns number of rows in previous resultset. If no previous resultset exists,
this returns false.
@return integer Number of rows in resultset | lastNumRows | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function lastInsertId($source, $field = 'id') {
$seq = $this->getSequence($source, $field);
$data = $this->fetchRow("SELECT currval('{$seq}') as max");
return $data[0]['max'];
} | Returns the ID generated from the previous INSERT operation.
@param string $source Name of the database table
@param string $field Name of the ID database field. Defaults to "id"
@return integer | lastInsertId | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function getSequence($table, $field = 'id') {
if (is_object($table)) {
$table = $this->fullTableName($table, false);
}
if (isset($this->_sequenceMap[$table]) && isset($this->_sequenceMap[$table][$field])) {
return $this->_sequenceMap[$table][$field];
} else {
return "{$table}_{$field}_seq";
}
} | Gets the associated sequence for the given table/field
@param mixed $table Either a full table name (with prefix) as a string, or a model object
@param string $field Name of the ID database field. Defaults to "id"
@return string The associated sequence name from the sequence map, defaults to "{$table}_{$field}_seq" | getSequence | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function truncate($table, $reset = 0) {
if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
$table = $this->fullTableName($table, false);
if (isset($this->_sequenceMap[$table]) && $reset !== 1) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
if ($reset === 0) {
$this->execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
} elseif ($reset === -1) {
$this->execute("DROP SEQUENCE IF EXISTS \"{$sequence}\"");
}
}
}
return true;
}
return false;
} | Deletes all the records in a table and drops all associated auto-increment sequences
@param mixed $table A string or model class representing the table to be truncated
@param integer $reset If -1, sequences are dropped, if 0 (default), sequences are reset,
and if 1, sequences are not modified
@return boolean SQL TRUNCATE TABLE statement, false if not applicable.
@access public | truncate | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function name($data) {
if (is_string($data)) {
$data = str_replace('"__"', '__', $data);
}
return parent::name($data);
} | Prepares field names to be quoted by parent
@param string $data
@return string SQL field | name | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function fields(&$model, $alias = null, $fields = array(), $quote = true) {
if (empty($alias)) {
$alias = $model->alias;
}
$fields = parent::fields($model, $alias, $fields, false);
if (!$quote) {
return $fields;
}
$count = count($fields);
if ($count >= 1 && strpos($fields[0], 'COUNT(*)') === false) {
$result = array();
for ($i = 0; $i < $count; $i++) {
if (!preg_match('/^.+\\(.*\\)/', $fields[$i]) && !preg_match('/\s+AS\s+/', $fields[$i])) {
if (substr($fields[$i], -1) == '*') {
if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') {
$build = explode('.', $fields[$i]);
$AssociatedModel = $model->{$build[0]};
} else {
$AssociatedModel = $model;
}
$_fields = $this->fields($AssociatedModel, $AssociatedModel->alias, array_keys($AssociatedModel->schema()));
$result = array_merge($result, $_fields);
continue;
}
$prepend = '';
if (strpos($fields[$i], 'DISTINCT') !== false) {
$prepend = 'DISTINCT ';
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
}
if (strrpos($fields[$i], '.') === false) {
$fields[$i] = $prepend . $this->name($alias) . '.' . $this->name($fields[$i]) . ' AS ' . $this->name($alias . '__' . $fields[$i]);
} else {
$build = explode('.', $fields[$i]);
$fields[$i] = $prepend . $this->name($build[0]) . '.' . $this->name($build[1]) . ' AS ' . $this->name($build[0] . '__' . $build[1]);
}
} else {
$fields[$i] = preg_replace_callback('/\(([\s\.\w]+)\)/', array(&$this, '__quoteFunctionField'), $fields[$i]);
}
$result[] = $fields[$i];
}
return $result;
}
return $fields;
} | Generates the fields list of an SQL query.
@param Model $model
@param string $alias Alias tablename
@param mixed $fields
@return array | fields | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function __quoteFunctionField($match) {
$prepend = '';
if (strpos($match[1], 'DISTINCT') !== false) {
$prepend = 'DISTINCT ';
$match[1] = trim(str_replace('DISTINCT', '', $match[1]));
}
$constant = preg_match('/^\d+|NULL|FALSE|TRUE$/i', $match[1]);
if (!$constant && strpos($match[1], '.') === false) {
$match[1] = $this->name($match[1]);
} elseif (!$constant){
$parts = explode('.', $match[1]);
if (!Set::numeric($parts)) {
$match[1] = $this->name($match[1]);
}
}
return '(' . $prepend .$match[1] . ')';
} | Auxiliary function to quote matched `(Model.fields)` from a preg_replace_callback call
Quotes the fields in a function call.
@param string matched string
@return string quoted strig
@access private | __quoteFunctionField | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function index($model) {
$index = array();
$table = $this->fullTableName($model, false);
if ($table) {
$indexes = $this->query("SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, i.indisvalid, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) as statement, c2.reltablespace
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
WHERE c.oid = (
SELECT c.oid
FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ '^(" . $table . ")$'
AND pg_catalog.pg_table_is_visible(c.oid)
AND n.nspname ~ '^(" . $this->config['schema'] . ")$'
)
AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname", false);
foreach ($indexes as $i => $info) {
$key = array_pop($info);
if ($key['indisprimary']) {
$key['relname'] = 'PRIMARY';
}
$col = array();
preg_match('/\(([^\)]+)\)/', $key['statement'], $indexColumns);
$parsedColumn = $indexColumns[1];
if (strpos($indexColumns[1], ',') !== false) {
$parsedColumn = explode(', ', $indexColumns[1]);
}
$index[$key['relname']]['unique'] = $key['indisunique'];
$index[$key['relname']]['column'] = $parsedColumn;
}
}
return $index;
} | Returns an array of the indexes in given datasource name.
@param string $model Name of model to inspect
@return array Fields in table. Keys are column and unique | index | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function alterSchema($compare, $table = null) {
if (!is_array($compare)) {
return false;
}
$out = '';
$colList = array();
foreach ($compare as $curTable => $types) {
$indexes = $colList = array();
if (!$table || $table == $curTable) {
$out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
foreach ($types as $type => $column) {
if (isset($column['indexes'])) {
$indexes[$type] = $column['indexes'];
unset($column['indexes']);
}
switch ($type) {
case 'add':
foreach ($column as $field => $col) {
$col['name'] = $field;
$colList[] = 'ADD COLUMN '.$this->buildColumn($col);
}
break;
case 'drop':
foreach ($column as $field => $col) {
$col['name'] = $field;
$colList[] = 'DROP COLUMN '.$this->name($field);
}
break;
case 'change':
foreach ($column as $field => $col) {
if (!isset($col['name'])) {
$col['name'] = $field;
}
$fieldName = $this->name($field);
$default = isset($col['default']) ? $col['default'] : null;
$nullable = isset($col['null']) ? $col['null'] : null;
unset($col['default'], $col['null']);
$colList[] = 'ALTER COLUMN '. $fieldName .' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col));
if (isset($nullable)) {
$nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL';
$colList[] = 'ALTER COLUMN '. $fieldName .' ' . $nullable;
}
if (isset($default)) {
$colList[] = 'ALTER COLUMN '. $fieldName .' SET DEFAULT ' . $this->value($default, $col['type']);
} else {
$colList[] = 'ALTER COLUMN '. $fieldName .' DROP DEFAULT';
}
}
break;
}
}
if (isset($indexes['drop']['PRIMARY'])) {
$colList[] = 'DROP CONSTRAINT ' . $curTable . '_pkey';
}
if (isset($indexes['add']['PRIMARY'])) {
$cols = $indexes['add']['PRIMARY']['column'];
if (is_array($cols)) {
$cols = implode(', ', $cols);
}
$colList[] = 'ADD PRIMARY KEY (' . $cols . ')';
}
if (!empty($colList)) {
$out .= "\t" . implode(",\n\t", $colList) . ";\n\n";
} else {
$out = '';
}
$out .= implode(";\n\t", $this->_alterIndexes($curTable, $indexes));
}
}
return $out;
} | Alter the Schema of a table.
@param array $compare Results of CakeSchema::compare()
@param string $table name of the table
@access public
@return array | alterSchema | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function _alterIndexes($table, $indexes) {
$alter = array();
if (isset($indexes['drop'])) {
foreach($indexes['drop'] as $name => $value) {
$out = 'DROP ';
if ($name == 'PRIMARY') {
continue;
} else {
$out .= 'INDEX ' . $name;
}
$alter[] = $out;
}
}
if (isset($indexes['add'])) {
foreach ($indexes['add'] as $name => $value) {
$out = 'CREATE ';
if ($name == 'PRIMARY') {
continue;
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
$out .= 'INDEX ';
}
if (is_array($value['column'])) {
$out .= $name . ' ON ' . $table . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= $name . ' ON ' . $table . ' (' . $this->name($value['column']) . ')';
}
$alter[] = $out;
}
}
return $alter;
} | Generate PostgreSQL index alteration statements for a table.
@param string $table Table to alter indexes for
@param array $new Indexes to add and drop
@return array Index alteration statements | _alterIndexes | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '(' . $real['limit'] . ')';
}
return $col;
}
$col = str_replace(')', '', $real);
$limit = null;
if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}
$floats = array(
'float', 'float4', 'float8', 'double', 'double precision', 'decimal', 'real', 'numeric'
);
switch (true) {
case (in_array($col, array('date', 'time', 'inet', 'boolean'))):
return $col;
case (strpos($col, 'timestamp') !== false):
return 'datetime';
case (strpos($col, 'time') === 0):
return 'time';
case (strpos($col, 'int') !== false && $col != 'interval'):
return 'integer';
case (strpos($col, 'char') !== false || $col == 'uuid'):
return 'string';
case (strpos($col, 'text') !== false):
return 'text';
case (strpos($col, 'bytea') !== false):
return 'binary';
case (in_array($col, $floats)):
return 'float';
default:
return 'text';
break;
}
} | Converts database-layer column types to basic types
@param string $real Real database-layer column type (i.e. "varchar(255)")
@return string Abstract column type (i.e. "string") | column | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function length($real) {
$col = str_replace(array(')', 'unsigned'), '', $real);
$limit = null;
if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}
if ($col == 'uuid') {
return 36;
}
if ($limit != null) {
return intval($limit);
}
return null;
} | Gets the length of a database-native column description, or null if no length
@param string $real Real database-layer column type (i.e. "varchar(255)")
@return int An integer representing the length of the column | length | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function fetchResult() {
if ($row = pg_fetch_row($this->results)) {
$resultRow = array();
foreach ($row as $index => $field) {
list($table, $column) = $this->map[$index];
$type = pg_field_type($this->results, $index);
switch ($type) {
case 'bool':
$resultRow[$table][$column] = $this->boolean($row[$index], false);
break;
case 'binary':
case 'bytea':
$resultRow[$table][$column] = pg_unescape_bytea($row[$index]);
break;
default:
$resultRow[$table][$column] = $row[$index];
break;
}
}
return $resultRow;
} else {
return false;
}
} | Fetches the next row from the current result set
@return unknown | fetchResult | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function boolean($data, $quote = true) {
switch (true) {
case ($data === true || $data === false):
return $data;
case ($data === 't' || $data === 'f'):
return ($data === 't');
case ($data === 'true' || $data === 'false'):
return ($data === 'true');
case ($data === 'TRUE' || $data === 'FALSE'):
return ($data === 'TRUE');
default:
return (bool)$data;
break;
}
} | Translates between PHP boolean values and PostgreSQL boolean values
@param mixed $data Value to be translated
@param boolean $quote True to quote value, false otherwise
@return mixed Converted boolean value | boolean | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function setEncoding($enc) {
return pg_set_client_encoding($this->connection, $enc) == 0;
} | Sets the database encoding
@param mixed $enc Database encoding
@return boolean True on success, false on failure | setEncoding | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function getEncoding() {
return pg_client_encoding($this->connection);
} | Gets the database encoding
@return string The database encoding | getEncoding | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function buildColumn($column) {
$col = $this->columns[$column['type']];
if (!isset($col['length']) && !isset($col['limit'])) {
unset($column['length']);
}
$out = preg_replace('/integer\([0-9]+\)/', 'integer', parent::buildColumn($column));
$out = str_replace('integer serial', 'serial', $out);
if (strpos($out, 'timestamp DEFAULT')) {
if (isset($column['null']) && $column['null']) {
$out = str_replace('DEFAULT NULL', '', $out);
} else {
$out = str_replace('DEFAULT NOT NULL', '', $out);
}
}
if (strpos($out, 'DEFAULT DEFAULT')) {
if (isset($column['null']) && $column['null']) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT NULL', $out);
} elseif (in_array($column['type'], array('integer', 'float'))) {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT 0', $out);
} elseif ($column['type'] == 'boolean') {
$out = str_replace('DEFAULT DEFAULT', 'DEFAULT FALSE', $out);
}
}
return $out;
} | Generate a Postgres-native column schema string
@param array $column An array structured like the following:
array('name'=>'value', 'type'=>'value'[, options]),
where options can be 'default', 'length', or 'key'.
@return string | buildColumn | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function buildIndex($indexes, $table = null) {
$join = array();
if (!is_array($indexes)) {
return array();
}
foreach ($indexes as $name => $value) {
if ($name == 'PRIMARY') {
$out = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
} else {
$out = 'CREATE ';
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
if (is_array($value['column'])) {
$value['column'] = implode(', ', array_map(array(&$this, 'name'), $value['column']));
} else {
$value['column'] = $this->name($value['column']);
}
$out .= "INDEX {$name} ON {$table}({$value['column']});";
}
$join[] = $out;
}
return $join;
} | Format indexes for create table
@param array $indexes
@param string $table
@return string | buildIndex | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function renderStatement($type, $data) {
switch (strtolower($type)) {
case 'schema':
extract($data);
foreach ($indexes as $i => $index) {
if (preg_match('/PRIMARY KEY/', $index)) {
unset($indexes[$i]);
$columns[] = $index;
break;
}
}
$join = array('columns' => ",\n\t", 'indexes' => "\n");
foreach (array('columns', 'indexes') as $var) {
if (is_array(${$var})) {
${$var} = implode($join[$var], array_filter(${$var}));
}
}
return "CREATE TABLE {$table} (\n\t{$columns}\n);\n{$indexes}";
break;
default:
return parent::renderStatement($type, $data);
break;
}
} | Overrides DboSource::renderStatement to handle schema generation with Postgres-style indexes
@param string $type
@param array $data
@return string | renderStatement | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_postgres.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_postgres.php | MIT |
function connect() {
$config = $this->config;
if (!$config['persistent']) {
$this->connection = sqlite_open($config['database']);
} else {
$this->connection = sqlite_popen($config['database']);
}
$this->connected = is_resource($this->connection);
if ($this->connected) {
$this->_execute('PRAGMA count_changes = 1;');
}
return $this->connected;
} | Connects to the database using config['database'] as a filename.
@param array $config Configuration array for connecting
@return mixed | connect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function enabled() {
return extension_loaded('sqlite');
} | Check that SQLite is enabled/installed
@return boolean | enabled | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function disconnect() {
@sqlite_close($this->connection);
$this->connected = false;
return $this->connected;
} | Disconnects from database.
@return boolean True if the database could be disconnected, else false | disconnect | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function _execute($sql) {
$result = sqlite_query($this->connection, $sql);
if (preg_match('/^(INSERT|UPDATE|DELETE)/', $sql)) {
$this->resultSet($result);
list($this->_queryStats) = $this->fetchResult();
}
return $result;
} | Executes given SQL statement.
@param string $sql SQL statement
@return resource Result resource identifier | _execute | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function execute($sql) {
$result = parent::execute($sql);
$this->_queryStats = array();
return $result;
} | Overrides DboSource::execute() to correctly handle query statistics
@param string $sql
@return unknown | execute | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function listSources() {
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
$result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false);
if (empty($result)) {
return array();
} else {
$tables = array();
foreach ($result as $table) {
$tables[] = $table[0]['name'];
}
parent::listSources($tables);
return $tables;
}
return array();
} | Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
@return array Array of tablenames in the database | listSources | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function describe(&$model) {
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$fields = array();
$result = $this->fetchAll('PRAGMA table_info(' . $this->fullTableName($model) . ')');
foreach ($result as $column) {
$fields[$column[0]['name']] = array(
'type' => $this->column($column[0]['type']),
'null' => !$column[0]['notnull'],
'default' => $column[0]['dflt_value'],
'length' => $this->length($column[0]['type'])
);
if ($column[0]['pk'] == 1) {
$colLength = $this->length($column[0]['type']);
$fields[$column[0]['name']] = array(
'type' => $fields[$column[0]['name']]['type'],
'null' => false,
'default' => $column[0]['dflt_value'],
'key' => $this->index['PRI'],
'length'=> ($colLength != null) ? $colLength : 11
);
}
}
$this->__cacheDescription($model->tablePrefix . $model->table, $fields);
return $fields;
} | Returns an array of the fields in given table name.
@param string $tableName Name of database table to inspect
@return array Fields in table. Keys are name and type | describe | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function value($data, $column = null, $safe = false) {
$parent = parent::value($data, $column, $safe);
if ($parent != null) {
return $parent;
}
if ($data === null) {
return 'NULL';
}
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
switch ($column) {
case 'boolean':
$data = $this->boolean((bool)$data);
break;
case 'integer':
case 'float':
if ($data === '') {
return 'NULL';
}
default:
$data = sqlite_escape_string($data);
break;
}
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
@return string Quoted and escaped | value | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
function update(&$model, $fields = array(), $values = null, $conditions = null) {
if (empty($values) && !empty($fields)) {
foreach ($fields as $field => $value) {
if (strpos($field, $model->alias . '.') !== false) {
unset($fields[$field]);
$field = str_replace($model->alias . '.', "", $field);
$field = str_replace($model->alias . '.', "", $field);
$fields[$field] = $value;
}
}
}
$result = parent::update($model, $fields, $values, $conditions);
return $result;
} | Generates and executes an SQL UPDATE statement for given model, fields, and values.
@param Model $model
@param array $fields
@param array $values
@param mixed $conditions
@return array | update | php | Datawalke/Coordino | cake/libs/model/datasources/dbo/dbo_sqlite.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/model/datasources/dbo/dbo_sqlite.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.