Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Sqlsrv fixes - cursor type fix, utf8 support, transaction support, varbinary update support #5851

Merged
merged 1 commit into from
Aug 7, 2014

Conversation

marcelto
Copy link
Contributor

Please merge this stuff, mssql support is buggy and very limited without it.

@samsonasik
Copy link
Contributor

travis build failure, see https://travis-ci.org/zendframework/zf2/jobs/19294649

if (!$this->resource) {
$this->connect();
}
if (sqlsrv_begin_transaction($this->resource)===false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces are always required

@marcelto
Copy link
Contributor Author

Thanks guys. I'll make those changes. As for the reference, it has been awhile but I believe it has to do with how the varbinary update need to happen.

@ralphschindler ralphschindler added this to the 2.3.0 milestone Feb 27, 2014
@ralphschindler ralphschindler self-assigned this Feb 27, 2014
@@ -117,7 +117,11 @@ public function delete($table = null)
*/
public function prepareStatementForSqlObject(PreparableSqlInterface $sqlObject, StatementInterface $statement = null)
{
$statement = ($statement) ?: $this->adapter->getDriver()->createStatement();
$statementReceived = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These kind of SqlSrv specific things need to happen in the SqlServer Platform Decorators, they are located in Zend\Db\Sql\Platform.

@ralphschindler
Copy link
Member

By and large, this PR won't work as is. A couple of large scale issues:

  • you've removed the ? finding logic in prepare(). While I regret that that logic is required in the first place, it is necessary as the design of the sqlsrv extension don't not facilitate a workflow where the number of parameters is unknown at prepare time but known at execution time. The tradeoff we decided to go with when we original architected it was to count the ?'s to produce a proper execute-time array of parameter references
  • prepare time options should likely just come in through a single method $statement->setPrepareOptions() or something similar
  • Zend\Db\Sql\Select shouldn't have SQL Server specific logic in it

That said, the charset and transaction support looks good. If we can find a resolution to the above issues, perhaps we can get it into the next mini point release.

@ralphschindler ralphschindler modified the milestones: 2.3.1, 2.3.0 Mar 10, 2014
@marcelto
Copy link
Contributor Author

A method to set the prepare options and perhaps another to check/get them would be great. No argument on the select decorator being the place to set the cursor type but I'm not sure what the preferred path forward would be. It seems like either a one off method call (which doesn't seem clean) or a change to the StatementInterface or StatementContainerInterface would be needed. Also, it is worth noting that the utf8 character support cannot happen without fixing the cursor type issue. A foreach loop against a result set will actually cause a driver error that will crash the web server if the character set is utf8 and the default cursor type is used.

@marcelto
Copy link
Contributor Author

What about $statement->setPrepareOptions() and $statement->setPrepareParams()? If the params aren't set default to the existing ? finding logic. Although I kinda like a couple of optional arguments in $statement->prepare, so maybe something like prepare function($sql = null, $params = null, $options = null)? It would also be nice to be able to test if options were set so a statement could be prepared explicitly with a usable cursor type like "buffered" but have the decorator override the default cursor "forward" with a select to avoid errors.

@Ocramius
Copy link
Member

Ocramius commented Apr 3, 2014

@marcelto this PR needs a rebase

@ralphschindler ralphschindler modified the milestones: 2.3.2, 2.3.1 Apr 14, 2014
@ralphschindler
Copy link
Member

A few things. This PR is going in the right direction, but not yet there ;)

First, I'm not fond of introducing the $params to the StatementInterface::prepare(). Reason being is that in general, parameters don't need to be known at prepare time for all adapters. SQL Server seems to be the outlier. The PDO version of the SQL Server driver doesn't have this requirement (yeah, I know it could potentially be emulating prepare under the hood, but that's neither here nor there).

That leaves us with $options. I think it's totally acceptable that the Zend/Db/Adapter/Driver/Sqlsrv/Statement.php's prepare() method take in prepare-time driver options, but I don't think this need to be applied globally to all Statements. Essentially what I am saying is that we don't need to make any changes to the StatementInterface. We can simply add $options = array() as a 2nd parameter to Sqlsrv\Statement::prepare(), and leave the rest alone.

Also, what about complimenting this with what I suggested above setPrepareOptions()?

if (!$this->resource) {
$this->connect();
}
if (sqlsrv_begin_transaction($this->resource)===false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces around operators (=== here).

@weierophinney
Copy link
Member

Final comment: rebase off of current master to ensure we can merge this cleanly, and I think it should be ready.

@marcelto
Copy link
Contributor Author

Ok, hope this is what you are looking for. On an unrelated note, apigility is awesome.

@weierophinney weierophinney merged commit 2a9c97d into zendframework:master Aug 7, 2014
weierophinney added a commit that referenced this pull request Aug 7, 2014
Sqlsrv fixes - cursor type fix, utf8 support, transaction support, varbinary update support
weierophinney added a commit that referenced this pull request Aug 7, 2014
weierophinney added a commit that referenced this pull request Aug 7, 2014
weierophinney added a commit that referenced this pull request Aug 7, 2014

//set statement cursor type
if ($statementContainer instanceof Statement) {
$statementContainer->setPrepareOptions(array('Scrollable'=>\SQLSRV_CURSOR_STATIC));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\SQLSRV_CURSOR_STATIC - is a constant? May be it should be without \ ?
can you create test for this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants