Permalink
Browse files

Merge PHLAK:hotfix/gravatar-trim-strtolower into master

  • Loading branch information...
2 parents 0a74768 + 8af59fc commit e702a42b8e0d745d79531f1340807bd9d9ea65e5 @EvanDotPro EvanDotPro committed Aug 16, 2013
@@ -1,4 +1,5 @@
<?php
+
/**
* Zend Framework (http://framework.zend.com/)
*
@@ -64,6 +65,12 @@ class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
protected $isPrepared = false;
/**
+ *
+ * @var array
+ */
+ protected $options = array();
+
+ /**
* Set driver
*
* @param Sqlsrv $driver
@@ -181,7 +188,7 @@ public function getSql()
}
/**
- * @param string $sql
+ * @param string $sql
* @throws Exception\RuntimeException
* @return Statement
*/
@@ -193,13 +200,11 @@ public function prepare($sql = null)
$sql = ($sql) ?: $this->sql;
$pRef = &$this->parameterReferences;
- for ($position = 0, $count = substr_count($sql, '?'); $position < $count; $position++) {
- $pRef[$position] = array('', SQLSRV_PARAM_IN, null, null);
- }
- $this->resource = sqlsrv_prepare($this->sqlsrv, $sql, $pRef);
+ $this->resource = sqlsrv_prepare($this->sqlsrv, $sql, $pRef, $this->options);
$this->isPrepared = true;
+
return $this;
}
@@ -220,9 +225,6 @@ public function isPrepared()
*/
public function execute($parameters = null)
{
- if (!$this->isPrepared) {
- $this->prepare();
- }
/** START Standard ParameterContainer Merging Block */
if (!$this->parameterContainer instanceof ParameterContainer) {
@@ -242,6 +244,9 @@ public function execute($parameters = null)
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
+ if (!$this->isPrepared) {
+ $this->prepare();
+ }
if ($this->profiler) {
$this->profiler->profilerStart($this);
@@ -271,19 +276,70 @@ public function execute($parameters = null)
*/
protected function bindParametersFromContainer()
{
- $values = $this->parameterContainer->getPositionalArray();
+ $parameters = $this->parameterContainer->getNamedArray();
+
$position = 0;
- foreach ($values as $value) {
- $this->parameterReferences[$position++][0] = $value;
+ foreach ($parameters as $key => &$value) {
+ if ($this->parameterContainer->offsetHasErrata($key)) {
+ $errata = $this->parameterContainer->offsetGetErrata($key);
+ switch ($errata) {
+ case ParameterContainer::TYPE_BINARY:
+ $params = array();
+ $params[] = $value;
+ $params[] = \SQLSRV_PARAM_IN;
+ $params[] = \SQLSRV_PHPTYPE_STREAM(\SQLSRV_ENC_BINARY);
+ $params[] = \SQLSRV_SQLTYPE_VARBINARY('max');
+ $this->parameterReferences[$position++] = $params;
+ break;
+ default:
+ $params = array($value, \SQLSRV_PARAM_IN, null, null);
+ $this->parameterReferences[$position++] = $params;
+ }
+ } elseif (is_array($value)) {
+ $this->parameterReferences[$position++] = $value;
+ } else {
+ $params = array($value, \SQLSRV_PARAM_IN, null, null);
+ $this->parameterReferences[$position++] = $params;
+ }
}
+ }
- // @todo bind errata
- //foreach ($this->parameterContainer as $name => &$value) {
- // $p[$position][0] = $value;
- // $position++;
- // if ($this->parameterContainer->offsetHasErrata($name)) {
- // $p[$position][3] = $this->parameterContainer->offsetGetErrata($name);
- // }
- //}
+ public function setQueryTimeout($queryTimeout)
+ {
+ if (is_int($queryTimeout)) {
+ $this->options['QueryTimeout'] = $queryTimeout;
+ } else {
+ $message = 'Invalid argument provided to ';
+ $message.= __METHOD__ . ' method in class ' . __CLASS__;
+ throw new Exception\InvalidArgumentException($message);
+ }
}
+
+ public function setSendStreamParamsAtExec($sendStreamParamsAtExec)
+ {
+ if (is_bool($sendStreamParamsAtExec)) {
+ $this->options['SendStreamParamsAtExec'] = $sendStreamParamsAtExec;
+ } else {
+ $message = 'Invalid argument provided to ';
+ $message.= __METHOD__ . ' method in class ' . __CLASS__;
+ throw new Exception\InvalidArgumentException($message);
+ }
+ }
+
+ public function setScrollable($scrollable)
+ {
+ switch ($scrollable) {
+ case \SQLSRV_CURSOR_FORWARD:
+ case \SQLSRV_CURSOR_STATIC:
+ case \SQLSRV_CURSOR_DYNAMIC:
+ case \SQLSRV_CURSOR_KEYSET:
+ $this->options['Scrollable'] = $scrollable;
+ break;
+ default:
+ $message = 'Invalid argument provided to ';
+ $message.= __METHOD__ . ' method in class ' . __CLASS__;
+ throw new Exception\InvalidArgumentException($message);
+ }
+ }
+
}
@@ -230,6 +230,7 @@ protected function executeSelect(Select $select)
// prepare and execute
$statement = $this->sql->prepareStatementForSqlObject($select);
+ $this->featureSet->apply('preSelectExecute', array($statement));
$result = $statement->execute();
// build result set
@@ -288,6 +289,7 @@ protected function executeInsert(Insert $insert)
$this->featureSet->apply('preInsert', array($insert));
$statement = $this->sql->prepareStatementForSqlObject($insert);
+ $this->featureSet->apply('preInsertExecute', array($statement));
$result = $statement->execute();
$this->lastInsertValue = $this->adapter->getDriver()->getConnection()->getLastGeneratedValue();
@@ -348,6 +350,7 @@ protected function executeUpdate(Update $update)
$this->featureSet->apply('preUpdate', array($update));
$statement = $this->sql->prepareStatementForSqlObject($update);
+ $this->featureSet->apply('preUpdateExecute', array($statement));
$result = $statement->execute();
// apply postUpdate features
@@ -404,6 +407,7 @@ protected function executeDelete(Delete $delete)
$this->featureSet->apply('preDelete', array($delete));
$statement = $this->sql->prepareStatementForSqlObject($delete);
+ $this->featureSet->apply('preDeleteExecute', array($statement));
$result = $statement->execute();
// apply postDelete features
@@ -0,0 +1,27 @@
+<?php
+
+namespace Zend\Db\Table\Feature;
+
+use Zend\Db\Adapter\Driver\StatementInterface;
+
+class StatementOptionsFeature extends AbstractFeature
+{
+
+ public function preSelectExecute(StatementInterface $statement)
+ {
+ $adapter = $this->tableGateway->getAdapter();
+ $platform = $adapter->getPlatform();
+ $platformName = $platform->getName();
+
+ switch ($platformName) {
+ case "SQLServer":
+ //Necessary for ResultSet count to work
+ $statement->setScrollable(\SQLSRV_CURSOR_STATIC);
+ break;
+ }
+ }
+
+// public function preInsertExecute(StatementInterface $statement){}
+// public function preUpdateExecute(StatementInterface $statement){}
+// public function preDeleteExecute(StatementInterface $statement){}
+}

0 comments on commit e702a42

Please sign in to comment.