Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #537 from gharlan/sql-connection-interface

ConnectionInterface vs. SqlConnectionInterface
  • Loading branch information...
commit ce3f433135c94f7734c54c045587b85a9fef55e7 2 parents 34cf151 + 40b381e
@marcj marcj authored
View
4 src/Propel/Generator/Behavior/QueryCache/QueryCacheBehavior.php
@@ -169,7 +169,7 @@ public function cacheFetch(\$key)
protected function addDoSelect(&$script)
{
$script .= "
-public function doSelect(\$con = null)
+public function doSelect(ConnectionInterface \$con = null)
{
// check that the columns of the main class are already added (if this is the primary ModelCriteria)
if (!\$this->hasSelectClause() && !\$this->getPrimaryCriteria()) {
@@ -209,7 +209,7 @@ public function doSelect(\$con = null)
protected function addDoCount(&$script)
{
$script .= "
-public function doCount(\$con = null)
+public function doCount(ConnectionInterface \$con = null)
{
\$dbMap = Propel::getServiceContainer()->getDatabaseMap(\$this->getDbName());
\$db = Propel::getServiceContainer()->getAdapter(\$this->getDbName());
View
10 src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -1129,7 +1129,7 @@ protected function addHasArrayElement(&$script, Column $column)
* ".$column->getDescription();
if ($column->isLazyLoad()) {
$script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
+ * @param ConnectionInterface \$con An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
}
$script .= "
* @return boolean
@@ -1181,7 +1181,7 @@ public function addDefaultAccessorComment(&$script, Column $column)
* ".$column->getDescription();
if ($column->isLazyLoad()) {
$script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
+ * @param ConnectionInterface \$con An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
}
$script .= "
* @return ".$column->getPhpType()."
@@ -1679,7 +1679,7 @@ protected function addAddArrayElement(&$script, Column $col)
* ".$col->getDescription();
if ($col->isLazyLoad()) {
$script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
+ * @param ConnectionInterface \$con An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
}
$script .= "
* @return ".$this->getObjectClassName(true)." The current object (for fluent API support)
@@ -1723,7 +1723,7 @@ protected function addRemoveArrayElement(&$script, Column $col)
* ".$col->getDescription();
if ($col->isLazyLoad()) {
$script .= "
- * @param ConnectionInterface An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
+ * @param ConnectionInterface \$con An optional ConnectionInterface connection to use for fetching this lazy-loaded column.";
}
$script .= "
* @return ".$this->getObjectClassName(true)." The current object (for fluent API support)
@@ -3418,7 +3418,7 @@ protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)
* @param string \$joinBehavior optional join type to use (defaults to $joinBehavior)
* @return ObjectCollection|{$className}[] List of $className objects
*/
- public function get".$relCol."Join".$relCol2."(Criteria \$criteria = null, \$con = null, \$joinBehavior = $joinBehavior)
+ public function get".$relCol."Join".$relCol2."(Criteria \$criteria = null, ConnectionInterface \$con = null, \$joinBehavior = $joinBehavior)
{";
$script .= "
\$query = $fkQueryClassName::create(null, \$criteria);
View
8 src/Propel/Generator/Builder/Om/QueryBuilder.php
@@ -470,7 +470,7 @@ protected function addFindPk(&$script)
*
* @return $class|array|mixed the result, formatted by the current formatter
*/
- public function findPk(\$key, \$con = null)
+ public function findPk(\$key, ConnectionInterface \$con = null)
{";
if (!$table->hasPrimaryKey()) {
$this->declareClass('Propel\\Runtime\\Exception\\LogicException');
@@ -564,7 +564,7 @@ protected function addFindPkSimple(&$script)
*
* @return $ARClassName A model object, or null if the key is not found
*/
- protected function findPkSimple(\$key, \$con)
+ protected function findPkSimple(\$key, ConnectionInterface \$con)
{
\$sql = '$query';
try {
@@ -632,7 +632,7 @@ protected function addFindPkComplex(&$script)
*
* @return " . $class . "|array|mixed the result, formatted by the current formatter
*/
- protected function findPkComplex(\$key, \$con)
+ protected function findPkComplex(\$key, ConnectionInterface \$con)
{
// As the query uses a PK condition, no limit(1) is necessary.
\$criteria = \$this->isKeepQuery() ? clone \$this : \$this;
@@ -677,7 +677,7 @@ protected function addFindPks(&$script)
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
- public function findPks(\$keys, \$con = null)
+ public function findPks(\$keys, ConnectionInterface \$con = null)
{";
if (!$table->hasPrimaryKey()) {
$this->declareClass('Propel\\Runtime\\Exception\\LogicException');
View
3  src/Propel/Generator/Reverse/AbstractSchemaParser.php
@@ -13,7 +13,6 @@
use Propel\Generator\Config\GeneratorConfigInterface;
use Propel\Generator\Model\VendorInfo;
use Propel\Runtime\Connection\ConnectionInterface;
-use Propel\Runtime\Connection\SqlConnectionInterface;
/**
* Base class for reverse engineering a database schema.
@@ -25,7 +24,7 @@
/**
* The database connection.
*
- * @var SqlConnectionInterface
+ * @var ConnectionInterface
*/
protected $dbh;
View
8 src/Propel/Runtime/ActiveQuery/Criteria.php
@@ -2138,7 +2138,7 @@ public function getPrimaryKey(Criteria $criteria = null)
*
* @throws PropelException
*/
- public function doUpdate($updateValues, $con)
+ public function doUpdate($updateValues, ConnectionInterface $con)
{
$db = Propel::getServiceContainer()->getAdapter($this->getDbName());
$dbMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName());
@@ -2283,7 +2283,7 @@ public function buildParams($columns, Criteria $values = null)
return $params;
}
- public function doCount($con = null)
+ public function doCount(ConnectionInterface $con = null)
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName());
$db = Propel::getServiceContainer()->getAdapter($this->getDbName());
@@ -2414,13 +2414,13 @@ public function doDelete(ConnectionInterface $con = null)
/**
* Builds, binds and executes a SELECT query based on the current object.
*
- * @param $con A connection object
+ * @param ConnectionInterface $con A connection object
*
* @return DataFetcherInterface A dataFetcher using the connection, ready to be fetched
*
* @throws \Propel\Runtime\Exception\PropelException
*/
- public function doSelect($con = null)
+ public function doSelect(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
View
32 src/Propel/Runtime/ActiveQuery/ModelCriteria.php
@@ -964,7 +964,7 @@ protected function preSelect(ConnectionInterface $con)
*
* @return ObjectCollection|array|mixed the list of results, formatted by the current formatter
*/
- public function find($con = null)
+ public function find(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
@@ -988,7 +988,7 @@ public function find($con = null)
*
* @return mixed the result, formatted by the current formatter
*/
- public function findOne($con = null)
+ public function findOne(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
@@ -1016,7 +1016,7 @@ public function findOne($con = null)
*
* @throws PropelException
*/
- public function findOneOrCreate($con = null)
+ public function findOneOrCreate(ConnectionInterface $con = null)
{
if ($this->joins) {
throw new PropelException(__METHOD__ .' cannot be used on a query with a join, because Propel cannot transform a SQL JOIN into a subquery. You should split the query in two queries to avoid joins.');
@@ -1048,7 +1048,7 @@ public function findOneOrCreate($con = null)
*
* @return mixed the result, formatted by the current formatter
*/
- public function findPk($key, $con = null)
+ public function findPk($key, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
@@ -1090,7 +1090,7 @@ public function findPk($key, $con = null)
*
* @throws PropelException
*/
- public function findPks($keys, $con = null)
+ public function findPks($keys, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
@@ -1124,7 +1124,7 @@ public function findPks($keys, $con = null)
*
* @return mixed the list of results, formatted by the current formatter
*/
- public function findBy($column, $value, $con = null)
+ public function findBy($column, $value, ConnectionInterface $con = null)
{
$method = 'filterBy' . $column;
$this->$method($value);
@@ -1149,7 +1149,7 @@ public function findBy($column, $value, $con = null)
*
* @return mixed the list of results, formatted by the current formatter
*/
- public function findByArray($conditions, $con = null)
+ public function findByArray($conditions, ConnectionInterface $con = null)
{
$this->filterByArray($conditions);
@@ -1168,7 +1168,7 @@ public function findByArray($conditions, $con = null)
*
* @return mixed the result, formatted by the current formatter
*/
- public function findOneBy($column, $value, $con = null)
+ public function findOneBy($column, $value, ConnectionInterface $con = null)
{
$method = 'filterBy' . $column;
$this->$method($value);
@@ -1193,7 +1193,7 @@ public function findOneBy($column, $value, $con = null)
*
* @return mixed the list of results, formatted by the current formatter
*/
- public function findOneByArray($conditions, $con = null)
+ public function findOneByArray($conditions, ConnectionInterface $con = null)
{
$this->filterByArray($conditions);
@@ -1207,7 +1207,7 @@ public function findOneByArray($conditions, $con = null)
*
* @return integer the number of results
*/
- public function count($con = null)
+ public function count(ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
@@ -1234,7 +1234,7 @@ public function count($con = null)
return $count;
}
- public function doCount($con = null)
+ public function doCount(ConnectionInterface $con = null)
{
$this->configureSelectColumns();
@@ -1257,7 +1257,7 @@ public function doCount($con = null)
*
* @return PropelModelPager a pager object, supporting iteration
*/
- public function paginate($page = 1, $maxPerPage = 10, $con = null)
+ public function paginate($page = 1, $maxPerPage = 10, ConnectionInterface $con = null)
{
$criteria = $this->isKeepQuery() ? clone $this : $this;
$pager = new PropelModelPager($criteria, $maxPerPage);
@@ -1457,7 +1457,7 @@ protected function postUpdate($affectedRows, ConnectionInterface $con)
* @throws \Propel\Runtime\Exception\PropelException
* @throws \Exception|\Propel\Runtime\Exception\PropelException
*/
- public function update($values, $con = null, $forceIndividualSaves = false)
+ public function update($values, ConnectionInterface $con = null, $forceIndividualSaves = false)
{
if (!is_array($values) && !($values instanceof Criteria)) {
throw new PropelException(__METHOD__ .' expects an array or Criteria as first argument');
@@ -1503,7 +1503,7 @@ public function update($values, $con = null, $forceIndividualSaves = false)
*
* @return integer Number of updated rows
*/
- public function doUpdate($values, $con, $forceIndividualSaves = false)
+ public function doUpdate($values, ConnectionInterface $con, $forceIndividualSaves = false)
{
if ($forceIndividualSaves) {
@@ -1798,13 +1798,13 @@ protected function getColumnFromName($phpName, $failSilently = true)
/**
* Builds, binds and executes a SELECT query based on the current object.
*
- * @param $con A connection object
+ * @param ConnectionInterface $con A connection object
*
* @return DataFetcherInterface A dataFetcher using the connection, ready to be fetched
*
* @throws \Propel\Runtime\Exception\PropelException
*/
- public function doSelect($con = null)
+ public function doSelect(ConnectionInterface $con = null)
{
// check that the columns of the main class are already added (if this is the primary ModelCriteria)
View
62 src/Propel/Runtime/Connection/ConnectionInterface.php
@@ -125,7 +125,7 @@ public function getSingleDataFetcher($data);
*/
public function getDataFetcher($data);
- /**
+ /**
* Executes the given callable within a transaction.
* This helper method takes care to commit or rollback the transaction.
*
@@ -138,4 +138,64 @@ public function getDataFetcher($data);
* @throws Exception Re-throws a possible <code>Exception</code> triggered by the callable.
*/
public function transaction(callable $callable);
+
+ /**
+ * Execute an SQL statement and return the number of affected rows.
+ *
+ * @param string $statement The SQL statement to prepare and execute.
+ * Data inside the query should be properly escaped.
+ *
+ * @return int The number of rows that were modified or deleted by the SQL
+ * statement you issued. If no rows were affected, returns 0.
+ */
+ public function exec($statement);
+
+ /**
+ * Prepares a statement for execution and returns a statement object.
+ *
+ * Prepares an SQL statement to be executed by the Statement::execute() method.
+ * The SQL statement can contain zero or more named (:name) or question mark (?)
+ * parameter markers for which real values will be substituted when the statement
+ * is executed. You cannot use both named and question mark parameter markers
+ * within the same SQL statement; pick one or the other parameter style. Use
+ * these parameters to bind any user-input, do not include the user-input
+ * directly in the query.
+ *
+ * @param string $statement This must be a valid SQL statement for the target
+ * database server.
+ * @param array $driver_options
+ *
+ * @return \Propel\Runtime\Connection\StatementInterface|bool A Statement object if the database server
+ * successfully prepares, FALSE otherwise.
+ * @throws \Propel\Runtime\Connection\Exception\ConnectionException depending on error handling.
+ */
+ public function prepare($statement, $driver_options = array());
+
+ /**
+ * Executes an SQL statement, returning a result set as a Statement object.
+ *
+ * @param string $statement The SQL statement to prepare and execute.
+ * Data inside the query should be properly escaped.
+ *
+ * @return \Propel\Runtime\DataFetcher\DataFetcherInterface
+ * @throws \Propel\Runtime\Connection\Exception\ConnectionException depending on error handling.
+ */
+ public function query($statement);
+
+ /**
+ * Quotes a string for use in a query.
+ *
+ * Places quotes around the input string (if required) and escapes special
+ * characters within the input string, using a quoting style appropriate to
+ * the underlying driver.
+ *
+ * @param string $string The string to be quoted.
+ * @param int $parameter_type Provides a data type hint for drivers that
+ * have alternate quoting styles.
+ *
+ * @return string A quoted string that is theoretically safe to pass into an
+ * SQL statement. Returns FALSE if the driver does not support
+ * quoting in this way.
+ */
+ public function quote($string, $parameter_type = 2);
}
View
5 src/Propel/Runtime/Connection/ConnectionWrapper.php
@@ -426,9 +426,12 @@ public function exec($sql)
*
* @see http://php.net/manual/en/pdo.query.php for a description of the possible parameters.
*
+ * @param string $statement The SQL statement to prepare and execute.
+ * Data inside the query should be properly escaped.
+ *
* @return StatementInterface
*/
- public function query()
+ public function query($statement)
{
$args = func_get_args();
$sql = array_shift($args);
View
2  src/Propel/Runtime/Connection/PdoConnection.php
@@ -16,7 +16,7 @@
/**
* PDO extension that implements ConnectionInterface and builds statements implementing StatementInterface.
*/
-class PdoConnection extends \PDO implements SqlConnectionInterface
+class PdoConnection extends \PDO implements ConnectionInterface
{
/**
* @var string The datasource name associated to this connection
View
82 src/Propel/Runtime/Connection/SqlConnectionInterface.php
@@ -1,82 +0,0 @@
-<?php
-
-/**
- * This file is part of the Propel package.
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * @license MIT License
- */
-
-namespace Propel\Runtime\Connection;
-
-/**
- * Interface for Propel Connection object.
- * Based on the PDO interface.
- * @see http://php.net/manual/en/book.pdo.php
- *
- * @author Francois Zaninotto
- */
-interface SqlConnectionInterface extends ConnectionInterface
-{
-
- /**
- * Execute an SQL statement and return the number of affected rows.
- *
- * @param string $statement The SQL statement to prepare and execute.
- * Data inside the query should be properly escaped.
- *
- * @return int The number of rows that were modified or deleted by the SQL
- * statement you issued. If no rows were affected, returns 0.
- */
- public function exec($statement);
-
- /**
- * Prepares a statement for execution and returns a statement object.
- *
- * Prepares an SQL statement to be executed by the Statement::execute() method.
- * The SQL statement can contain zero or more named (:name) or question mark (?)
- * parameter markers for which real values will be substituted when the statement
- * is executed. You cannot use both named and question mark parameter markers
- * within the same SQL statement; pick one or the other parameter style. Use
- * these parameters to bind any user-input, do not include the user-input
- * directly in the query.
- *
- * @param string $statement This must be a valid SQL statement for the target
- * database server.
- * @param array $driver_options
- *
- * @return \Propel\Runtime\Connection\StatementInterface|bool A Statement object if the database server
- * successfully prepares, FALSE otherwise.
- * @throws \Propel\Runtime\Connection\Exception\ConnectionException depending on error handling.
- */
- public function prepare($statement, $driver_options = array());
-
- /**
- * Executes an SQL statement, returning a result set as a Statement object.
- *
- * @param string $statement The SQL statement to prepare and execute.
- * Data inside the query should be properly escaped.
- *
- * @return \Propel\Runtime\DataFetcher\DataFetcherInterface
- * @throws \Propel\Runtime\Connection\Exception\ConnectionException depending on error handling.
- */
- public function query($statement);
-
- /**
- * Quotes a string for use in a query.
- *
- * Places quotes around the input string (if required) and escapes special
- * characters within the input string, using a quoting style appropriate to
- * the underlying driver.
- *
- * @param string $string The string to be quoted.
- * @param int $parameter_type Provides a data type hint for drivers that
- * have alternate quoting styles.
- *
- * @return string A quoted string that is theoretically safe to pass into an
- * SQL statement. Returns FALSE if the driver does not support
- * quoting in this way.
- */
- public function quote($string, $parameter_type = 2);
-}
Please sign in to comment.
Something went wrong with that request. Please try again.