1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-08 07:06:52 +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

@@ -43,7 +43,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
private $driverName;
/**
* @throws DibiNotSupportedException
*/
@@ -55,13 +54,12 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Connects to a database.
* @return void
* @throws DibiException
*/
public function connect(array &$config)
public function connect(array & $config)
{
$foo = & $config['dsn'];
$foo = & $config['options'];
@@ -85,7 +83,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Disconnects from a database.
* @return void
@@ -96,7 +93,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Executes the SQL query.
* @param string SQL statement.
@@ -131,7 +127,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
* @return int|FALSE number of rows or FALSE on error
@@ -142,7 +137,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @return int|FALSE int on success or FALSE on failure
@@ -153,7 +147,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Begins a transaction (if supported).
* @param string optional savepoint name
@@ -169,7 +162,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Commits statements in a transaction.
* @param string optional savepoint name
@@ -185,7 +177,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Rollback changes in a transaction.
* @param string optional savepoint name
@@ -201,7 +192,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Returns the connection resource.
* @return PDO
@@ -212,7 +202,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Returns the connection reflector.
* @return IDibiReflector
@@ -220,20 +209,19 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
public function getReflector()
{
switch ($this->driverName) {
case 'mysql':
return new DibiMySqlReflector($this);
case 'mysql':
return new DibiMySqlReflector($this);
case 'sqlite':
case 'sqlite2':
return new DibiSqliteReflector($this);
case 'sqlite':
case 'sqlite2':
return new DibiSqliteReflector($this);
default:
throw new DibiNotSupportedException;
default:
throw new DibiNotSupportedException;
}
}
/**
* Result set driver factory.
* @param PDOStatement
@@ -247,11 +235,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/********************* SQL ****************d*g**/
/**
* Encodes data for use in a SQL statement.
* @param mixed value
@@ -262,52 +248,51 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
public function escape($value, $type)
{
switch ($type) {
case dibi::TEXT:
return $this->connection->quote($value, PDO::PARAM_STR);
case dibi::TEXT:
return $this->connection->quote($value, PDO::PARAM_STR);
case dibi::BINARY:
return $this->connection->quote($value, PDO::PARAM_LOB);
case dibi::BINARY:
return $this->connection->quote($value, PDO::PARAM_LOB);
case dibi::IDENTIFIER:
switch ($this->driverName) {
case 'mysql':
return '`' . str_replace('`', '``', $value) . '`';
case dibi::IDENTIFIER:
switch ($this->driverName) {
case 'mysql':
return '`' . str_replace('`', '``', $value) . '`';
case 'pgsql':
return '"' . str_replace('"', '""', $value) . '"';
case 'pgsql':
return '"' . str_replace('"', '""', $value) . '"';
case 'sqlite':
case 'sqlite2':
return '[' . strtr($value, '[]', ' ') . ']';
case 'sqlite':
case 'sqlite2':
return '[' . strtr($value, '[]', ' ') . ']';
case 'odbc':
case 'oci': // TODO: not tested
case 'mssql':
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
case 'odbc':
case 'oci': // TODO: not tested
case 'mssql':
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
case 'sqlsrv':
return '[' . str_replace(']', ']]', $value) . ']';
case 'sqlsrv':
return '[' . str_replace(']', ']]', $value) . ']';
default:
return $value;
}
case dibi::BOOL:
return $this->connection->quote($value, PDO::PARAM_BOOL);
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);
default:
return $value;
}
case dibi::BOOL:
return $this->connection->quote($value, PDO::PARAM_BOOL);
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);
default:
throw new InvalidArgumentException('Unsupported type.');
throw new InvalidArgumentException('Unsupported type.');
}
}
/**
* Encodes string for use in a LIKE statement.
* @param string
@@ -320,7 +305,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Decodes data from result set.
* @param string value
@@ -337,62 +321,64 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* 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;
if ($limit < 0 && $offset < 1) {
return;
}
switch ($this->driverName) {
case 'mysql':
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
break;
case 'pgsql':
if ($limit >= 0) $sql .= ' LIMIT ' . (int) $limit;
if ($offset > 0) $sql .= ' OFFSET ' . (int) $offset;
break;
case 'sqlite':
case 'sqlite2':
$sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
break;
case 'oci':
if ($offset > 0) {
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t ' . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE "__rnum" > '. (int) $offset;
} elseif ($limit >= 0) {
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
}
break;
case 'odbc':
case 'mssql':
case 'sqlsrv':
if ($offset < 1) {
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
case 'mysql':
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
break;
}
// intentionally break omitted
default:
throw new DibiNotSupportedException('PDO or driver does not support applying limit or offset.');
case 'pgsql':
if ($limit >= 0) {
$sql .= ' LIMIT ' . (int) $limit;
}
if ($offset > 0) {
$sql .= ' OFFSET ' . (int) $offset;
}
break;
case 'sqlite':
case 'sqlite2':
$sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
break;
case 'oci':
if ($offset > 0) {
$sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t '
. ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '')
. ') WHERE "__rnum" > '. (int) $offset;
} elseif ($limit >= 0) {
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
}
break;
case 'odbc':
case 'mssql':
case 'sqlsrv':
if ($offset < 1) {
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
break;
}
// intentionally break omitted
default:
throw new DibiNotSupportedException('PDO or driver does not support applying limit or offset.');
}
}
/********************* result set ****************d*g**/
/**
* Returns the number of rows in a result set.
* @return int
@@ -403,7 +389,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Fetches the row at current position and moves the internal cursor to the next position.
* @param bool TRUE for associative array, FALSE for numeric
@@ -415,7 +400,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Moves cursor position without fetching row.
* @param int the 0-based cursor pos to seek to
@@ -427,7 +411,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Frees the resources allocated for this result set.
* @return void
@@ -438,7 +421,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Returns metadata for all columns in a result set.
* @return array
@@ -472,7 +454,6 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
/**
* Returns the result set resource.
* @return PDOStatement