*
* @param array $config Configuration options and optional objects:
* <pre>
- * 'cache' - TODO
+ * 'cache' - (Horde_Cache) Cache object.
* 'charset' - (string) TODO
- * 'logger' - TODO
+ * 'logger' - (Horde_Log_Logger) Logging object.
* 'write_db' - (Horde_Db_Adapter_Base) Use this DB for write operations.
* </pre>
*/
*
* @param string $method
* @param array $args
+ *
+ * @return TODO
*/
public function componentFactory($component, $args)
{
*
* @param string $method
* @param array $args
+ *
+ * @return mixed TODO
+ * @throws BadMethodCallException
*/
public function __call($method, $args)
{
* Returns the human-readable name of the adapter. Use mixed case - one
* can always use downcase if needed.
*
- * @return string
+ * @return string
*/
public function adapterName()
{
* Does this adapter support migrations? Backend specific, as the
* abstract adapter always returns +false+.
*
- * @return boolean
+ * @return boolean
*/
public function supportsMigrations()
{
* Does this adapter support using DISTINCT within COUNT? This is +true+
* for all adapters except sqlite.
*
- * @return boolean
+ * @return boolean
*/
public function supportsCountDistinct()
{
* sequence before the insert statement? If true, next_sequence_value
* is called before each insert to set the record's primary key.
* This is false for all adapters but Firebird.
+ *
+ * @return boolean
*/
public function prefetchPrimaryKey($tableName = null)
{
/**
* Reset the timer
*
- * @return int
+ * @return integer
*/
public function resetRuntime()
{
$runtime = $this->_runtime;
$this->_runtime = 0;
+
return $this->_runtime;
}
##########################################################################*/
/**
- * Connect to the db
+ * Connect to the db.
*/
abstract public function connect();
/**
- * Is the connection active
+ * Is the connection active?
*
- * @return boolean
+ * @return boolean
*/
public function isActive()
{
}
/**
- * Reconnect to the db
+ * Reconnect to the db.
*/
public function reconnect()
{
}
/**
- * Disconnect from db
+ * Disconnect from db.
*/
public function disconnect()
{
/**
* Provides access to the underlying database connection. Useful for when
- * you need to call a proprietary method such as postgresql's lo_* methods
+ * you need to call a proprietary method such as postgresql's
+ * lo_* methods.
*
- * @return resource
+ * @return resource
*/
public function rawConnection()
{
* Returns an array of records with the column names as keys, and
* column values as values.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
- * @return Traversable
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return Traversable
+ * @throws Horde_Db_Exception
*/
public function select($sql, $arg1 = null, $arg2 = null)
{
* Returns an array of record hashes with the column names as keys and
* column values as values.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return array
+ * @throws Horde_Db_Exception
*/
public function selectAll($sql, $arg1 = null, $arg2 = null)
{
* Returns a record hash with the column names as keys and column values
* as values.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
- * @return array
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return array
+ * @throws Horde_Db_Exception
*/
public function selectOne($sql, $arg1 = null, $arg2 = null)
{
$result = $this->selectAll($sql, $arg1, $arg2);
- return $result ? next($result) : array();
+ return $result
+ ? next($result)
+ : array();
}
/**
* Returns a single value from a record
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
- * @return string
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return string
+ * @throws Horde_Db_Exception
*/
public function selectValue($sql, $arg1 = null, $arg2 = null)
{
$result = $this->selectOne($sql, $arg1, $arg2);
- return $result ? next($result) : null;
+
+ return $result
+ ? next($result)
+ : null;
}
/**
* Returns an array of the values of the first column in a select:
* selectValues("SELECT id FROM companies LIMIT 3") => [1,2,3]
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return array
+ * @throws Horde_Db_Exception
*/
public function selectValues($sql, $arg1 = null, $arg2 = null)
{
*
* selectAssoc("SELECT id, name FROM companies LIMIT 3") => [1 => 'Ford', 2 => 'GM', 3 => 'Chrysler']
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return array
+ * @throws Horde_Db_Exception
*/
public function selectAssoc($sql, $arg1 = null, $arg2 = null)
{
/**
* Executes the SQL statement in the context of this connection.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return Traversable
+ * @throws Horde_Db_Exception
*/
public function execute($sql, $arg1 = null, $arg2 = null)
{
}
$this->_logInfo($sql, $name, $t->pop());
-
$this->_rowCount = $stmt ? $stmt->rowCount() : 0;
+
return $stmt;
}
/**
* Returns the last auto-generated ID from the affected table.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
- * @param string $pk
- * @param int $idValue
- * @param string $sequenceName
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a
+ * query name.
+ * @param string $arg2 If $arg1 contains bound parameters, the
+ * query name.
+ * @param string $pk TODO
+ * @param integer $idValue TODO
+ * @param string $sequenceName TODO
+ *
+ * @return TODO
+ * @throws Horde_Db_Exception
*/
- public function insert($sql, $arg1 = null, $arg2 = null, $pk = null, $idValue = null, $sequenceName = null)
+ public function insert($sql, $arg1 = null, $arg2 = null, $pk = null,
+ $idValue = null, $sequenceName = null)
{
if ($this->_write) {
return $this->_write->insert($sql, $arg1, $arg2, $pk, $idValue, $sequenceName);
}
$this->execute($sql, $arg1, $arg2);
- return isset($idValue) ? $idValue : $this->_connection->lastInsertId();
+
+ return isset($idValue)
+ ? $idValue
+ : $this->_connection->lastInsertId();
}
/**
* Executes the update statement and returns the number of rows affected.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return integer Number of rows affected.
+ * @throws Horde_Db_Exception
*/
public function update($sql, $arg1 = null, $arg2 = null)
{
/**
* Executes the delete statement and returns the number of rows affected.
*
- * @param string $sql
- * @param mixed $arg1 Either an array of bound parameters or a query name.
- * @param string $arg2 If $arg1 contains bound parameters, the query name.
+ * @param string $sql SQL statement.
+ * @param mixed $arg1 Either an array of bound parameters or a query
+ * name.
+ * @param string $arg2 If $arg1 contains bound parameters, the query
+ * name.
+ *
+ * @return integer Number of rows affected.
+ * @throws Horde_Db_Exception
*/
public function delete($sql, $arg1 = null, $arg2 = null)
{
}
/**
- * Check if a transaction has been started
+ * Check if a transaction has been started.
+ *
+ * @return boolean True if transaction has been started.
*/
public function transactionStarted()
{
{
if ($this->_write) {
$this->_write->beginDbTransaction();
- } else {
+ } elseif (!$this->_transactionStarted) {
$this->_transactionStarted = true;
$this->_connection->beginTransaction();
}
{
if ($this->_write) {
$this->_write->commitDbTransaction();
- } else {
+ } elseif ($this->_transactionStarted) {
$this->_connection->commit();
$this->_transactionStarted = false;
}
*/
public function rollbackDbTransaction()
{
- if (! $this->_transactionStarted) { return; }
-
if ($this->_write) {
$this->_write->rollbackDbTransaction();
- } else {
+ } elseif ($this->_transactionStarted) {
$this->_connection->rollBack();
$this->_transactionStarted = false;
}
/**
* Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
*
- * @param string $sql
- * @param array $options
- * @return string
+ * @param string $sql SQL statement.
+ * @param array $options TODO
+ *
+ * @return string
*/
public function addLimitOffset($sql, $options)
{
return $sql;
}
+ /**
+ * TODO
+ */
public function sanitizeLimit($limit)
{
- if (strpos($limit, ',') !== false) {
- return implode(',', array_map(create_function('$i', 'return (int)$i;'), explode(',', $limit)));
- } else return (int)$limit;
+ return (strpos($limit, ',') !== false)
+ ? implode(',', array_map('intval', explode(',', $limit)))
+ : intval($limit);
}
/**
* Appends a locking clause to an SQL statement.
* This method *modifies* the +sql+ parameter.
+ *
* # SELECT * FROM suppliers FOR UPDATE
* add_lock! 'SELECT * FROM suppliers', :lock => true
* add_lock! 'SELECT * FROM suppliers', :lock => ' FOR UPDATE'
+ *
+ * @param string &$sql SQL statment.
+ * @param array $options TODO.
*/
- public function addLock(&$sql, $options = array())
+ public function addLock(&$sql, array $options = array())
{
- if (isset($options['lock']) && is_string($options['lock'])) {
- $sql .= ' ' . $lock;
- } else {
- $sql .= ' FOR UPDATE';
- }
+ $sql .= (isset($options['lock']) && is_string($options['lock']))
+ ? ' ' . $lock
+ : ' FOR UPDATE';
}
/**
* Inserts the given fixture into the table. Overridden in adapters that
* require something beyond a simple insert (eg. Oracle).
+ *
+ * @param TODO $fixture TODO
+ * @param TODO $tableName TODO
+ *
+ * @return TODO
*/
public function insertFixture($fixture, $tableName)
{
}
}
+ /**
+ * TODO
+ *
+ * @param string $tableName TODO
+ *
+ * @return string TODO
+ */
public function emptyInsertStatement($tableName)
{
- return 'INSERT INTO '.$this->quoteTableName($tableName).' VALUES(DEFAULT)';
+ return 'INSERT INTO ' . $this->quoteTableName($tableName) . ' VALUES(DEFAULT)';
}
/**
* Replace ? in a SQL statement with quoted values from $args
*
- * @param string $sql
- * @param array $args
+ * @param string $sql SQL statement.
+ * @param array $args TODO
+ *
+ * @return string Modified SQL statement.
+ * @throws Horde_Db_Exception
*/
protected function _replaceParameters($sql, $args)
{
/**
* Logs the SQL query for debugging.
*
- * @param string $sql
- * @param string $name
- * @param float $runtime
+ * @param string $sql SQL statement.
+ * @param string $name TODO
+ * @param float $runtime Runtime interval.
*/
protected function _logInfo($sql, $name, $runtime = null)
{
/**
* Formats the log entry.
*
- * @param string $message
- * @param string $sql
+ * @param string $message Message.
+ * @param string $sql SQL statment.
+ *
+ * @return string Formatted log entry.
*/
protected function _formatLogEntry($message, $sql)
{
- $sql = preg_replace("/\s+/", ' ', $sql);
- $sql = "\n\t".wordwrap($sql, 70, "\n\t ", 1);
- return "SQL $message $sql";
+ return "SQL $message \n\t" . wordwrap(preg_replace("/\s+/", ' ', $sql), 70, "\n\t ", 1);
}
}