Page 1 of 1

SQLite via PDO - Find affected rows

Posted: Sun Oct 21, 2007 7:52 pm
by Stryks
Has anyone else come across SQLite not showing affected rows when using the prepare() / execute() method?

Code: Select all

$test = $link->prepare('DELETE FROM tbl_admin_postcodes');  // $link is a valid connection
$test->execute();

 echo "Affected rows: " . $test->rowCount(); // returns 0 though rows are removed
It returns a valid PDOStatement, and I can pull data on selects and so forth, however INSERTs and DELETEs all return 0 if I call rowCount().

Anyone worked with PDO SQLite before? Ever found this?

Cheers

Posted: Sun Oct 21, 2007 8:09 pm
by Kieran Huggins
It's not you; PDO can be buggy in this respect, though it seems to affect only certain version of DB engines.

Adding a COUNT column can work around SELECT queries, but I have no idea how to work around DELETE or UPDATE :-(

Posted: Sun Oct 21, 2007 8:32 pm
by Stryks
8O

Well ...

I'm kinda lost for words. If I want to use SQLite3 then I have to use PDO ... and PDO implementation is broken. That'd be a FANTASTIC thing to have in the PHP documentation so a person could read it BEFORE they went off and wrote a stack of code for it.

It probably doesn't matter that much, but I always like to build that into my abstraction so that I can easily check that actions have had the desired effect.

I just went back and had a tinker, and yeah ... I cant get affected rows from anything. exec() and query() expose no extra info.

Dammit.

Thanks for the reply though 8)

Posted: Sun Oct 21, 2007 8:36 pm
by Kieran Huggins
That DOES suck :-(

You should contribute a note to the man page - at least it will help the next person. Make sure you include your version and platform.