1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-12 09:04:24 +02:00

typos & whitespace

This commit is contained in:
David Grudl
2013-07-02 18:42:55 +02:00
parent 9e23730cb0
commit e87c112d71
55 changed files with 612 additions and 1299 deletions

View File

@@ -53,7 +53,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
private $buffered;
/**
* @throws DibiNotSupportedException
*/
@@ -65,13 +64,12 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Connects to a database.
* @return void
* @throws DibiException
*/
public function connect(array &$config)
public function connect(array & $config)
{
if (isset($config['resource'])) {
$this->connection = $config['resource'];
@@ -79,17 +77,21 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
} else {
// default values
DibiConnection::alias($config, 'flags', 'options');
if (!isset($config['charset'])) $config['charset'] = 'utf8';
if (!isset($config['timezone'])) $config['timezone'] = date('P');
if (!isset($config['username'])) $config['username'] = ini_get('mysql.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('mysql.default_password');
$config += array(
'charset' => 'utf8',
'timezone' => date('P'),
'username' => ini_get('mysql.default_user'),
'password' => ini_get('mysql.default_password'),
);
if (!isset($config['host'])) {
$host = ini_get('mysql.default_host');
if ($host) {
$config['host'] = $host;
$config['port'] = ini_get('mysql.default_port');
} else {
if (!isset($config['socket'])) $config['socket'] = ini_get('mysql.default_socket');
if (!isset($config['socket'])) {
$config['socket'] = ini_get('mysql.default_socket');
}
$config['host'] = NULL;
}
}
@@ -140,7 +142,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Disconnects from a database.
* @return void
@@ -151,7 +152,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Executes the SQL query.
* @param string SQL statement.
@@ -175,7 +175,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Retrieves information about the most recently executed query.
* @return array
@@ -184,7 +183,9 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
{
$res = array();
preg_match_all('#(.+?): +(\d+) *#', mysql_info($this->connection), $matches, PREG_SET_ORDER);
if (preg_last_error()) throw new DibiPcreException;
if (preg_last_error()) {
throw new DibiPcreException;
}
foreach ($matches as $m) {
$res[$m[1]] = (int) $m[2];
@@ -193,7 +194,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
* @return int|FALSE number of rows or FALSE on error
@@ -204,7 +204,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @return int|FALSE int on success or FALSE on failure
@@ -215,7 +214,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Begins a transaction (if supported).
* @param string optional savepoint name
@@ -228,7 +226,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Commits statements in a transaction.
* @param string optional savepoint name
@@ -241,7 +238,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Rollback changes in a transaction.
* @param string optional savepoint name
@@ -254,7 +250,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Returns the connection resource.
* @return mixed
@@ -265,7 +260,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Returns the connection reflector.
* @return IDibiReflector
@@ -276,7 +270,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Result set driver factory.
* @param resource
@@ -290,11 +283,9 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/********************* SQL ****************d*g**/
/**
* Encodes data for use in a SQL statement.
* @param mixed value
@@ -305,38 +296,37 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
public function escape($value, $type)
{
switch ($type) {
case dibi::TEXT:
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::TEXT:
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::BINARY:
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::BINARY:
if (!is_resource($this->connection)) {
throw new DibiException('Lost connection to server.');
}
return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::IDENTIFIER:
// @see http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
return '`' . str_replace('`', '``', $value) . '`';
case dibi::IDENTIFIER:
// @see http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
return '`' . str_replace('`', '``', $value) . '`';
case dibi::BOOL:
return $value ? 1 : 0;
case dibi::BOOL:
return $value ? 1 : 0;
case dibi::DATE:
return $value instanceof DateTime ? $value->format("'Y-m-d'") : date("'Y-m-d'", $value);
case dibi::DATE:
return $value instanceof DateTime ? $value->format("'Y-m-d'") : date("'Y-m-d'", $value);
case dibi::DATETIME:
return $value instanceof DateTime ? $value->format("'Y-m-d H:i:s'") : date("'Y-m-d H:i:s'", $value);
case dibi::DATETIME:
return $value instanceof DateTime ? $value->format("'Y-m-d H:i:s'") : date("'Y-m-d H:i:s'", $value);
default:
throw new InvalidArgumentException('Unsupported type.');
default:
throw new InvalidArgumentException('Unsupported type.');
}
}
/**
* Encodes string for use in a LIKE statement.
* @param string
@@ -350,7 +340,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Decodes data from result set.
* @param string value
@@ -367,29 +356,23 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Injects LIMIT/OFFSET to the SQL query.
* @param string &$sql The SQL query that will be modified.
* @param int $limit
* @param int $offset
* @return void
*/
public function applyLimit(&$sql, $limit, $offset)
public function applyLimit(& $sql, $limit, $offset)
{
if ($limit < 0 && $offset < 1) return;
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
if ($limit >= 0 || $offset > 0) {
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
}
}
/********************* result set ****************d*g**/
/**
* Automatically frees the resources allocated for this result set.
* @return void
@@ -400,7 +383,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Returns the number of rows in a result set.
* @return int
@@ -414,7 +396,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Fetches the row at current position and moves the internal cursor to the next position.
* @param bool TRUE for associative array, FALSE for numeric
@@ -426,7 +407,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Moves cursor position without fetching row.
* @param int the 0-based cursor pos to seek to
@@ -443,7 +423,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Frees the resources allocated for this result set.
* @return void
@@ -455,7 +434,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Returns metadata for all columns in a result set.
* @return array
@@ -478,7 +456,6 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
}
/**
* Returns the result set resource.
* @return mixed