dbal icon indicating copy to clipboard operation
dbal copied to clipboard

Updated PDO_SQLSRV connection to use driverOptions in prepare-function

Open DAdq26 opened this issue 1 year ago • 4 comments

Hi team,

Bug Report

Previously closed issue https://github.com/doctrine/dbal/issues/2185 on the same subject does not exist anymore in version 3.x Actually the simple script above

$database = "mybase";
$server = "mssql";
$conn = new PDO( "sqlsrv:server=$server ; MultipleActiveResultSets=false; Database = $database", "", "");

$query = "select * from mytable";
$stmt = $conn->prepare($query);
$stmt->execute();

print "Row count : ";
print $stmt->rowCount();

returns everytime -1 because we cannot use PDO::ATTR_CURSOR attribute when we used native prepare

After debugging inside DBAL with PDO_SqlSrv wrapper we discover that prepare cannot be override like in the first issue with driverOptions It's essential to use native Pdo::prepare($stmt, $options) to precise scrollable cursor to make it works..

$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));

Perhaps we have not seen any option or configuration, but runtime code does not seems to modify native prepare method in doctrine/dbal/src/Driver/PDO/Connection.php line 55 on version 3.6.6

image

If you have any advice or fix to get back $driverOptions config as in https://github.com/doctrine/dbal/issues/2185, it would be perfect

Best

DAdq26 avatar Oct 29 '24 12:10 DAdq26

Sorry, but I don't understand this bug report. Please explain to me:

  • What are you trying to do?
  • How are you attempting to do that using DBAL APIs only?
  • What did you expect to happen?
  • What happens instead?

derrabus avatar Nov 27 '24 08:11 derrabus

Hi,

I just try to count my result here from statement method rowCount() But as in this previous issue https://github.com/doctrine/dbal/issues/2185 i can't use main driver option that seems removed before but is essential for us here to use driver options to make rowCount work well.

On my screenshot on my first post, you see your code in prepare method which cannot use prepare options anymore at runtime (previsously setted in main doctrine options with $driverOptions variable)

image

image

This was possible in an old doctrine version here https://github.com/doctrine/dbal/pull/631/files

Actually the count result is always -1 If i use array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL) in prepare option with buffered cursor the count result is right one

Do you need more debug or script ?

Best

DAdq26 avatar Dec 13 '24 07:12 DAdq26

And you need those options to be always passed to the PDO prepare() method? Or only occasionally?

derrabus avatar Dec 13 '24 07:12 derrabus

everytime ;) for all SELECT queries generated from prepare

we have hacked doctrine files to make it works temporary

image

but if we can use common driverOptions it would be better

DAdq26 avatar Dec 13 '24 07:12 DAdq26