Possible bug in Nette\Database causing Selection::insert() to return FALSE

Notice: This thread is very old.
thunderbuff
Member | 164
+
0
-

Hello everyone,

I think I have found (similar) problem mentioned in this question: https://forum.nette.org/…se-nette-2-3

If I call

<?php
$row = $table->insert([/*...*/]);
?>

with my cache freshly deleted it returns FALSE.

I have discovered the problem on this line in Selection class:

https://github.com/…election.php#L726

Selection::getPrimarySequence() is called after INSERT statement and it executes many queries to build a cache. Unfortunately, executing those queries causes PDO::lastInsertId() to return “0” instead of real ID – which prevents from SELECTing inserted row and makes Selection::insert() to return FALSE.

The solution is simple, moving line 726 to the beginning of insert method solves the issue.

This error occurs only with cache freshly cleared.

Is this a bug?

Last edited by thunderbuff (2015-08-05 23:34)

meikr
Member | 2
+
0
-

I have a same problem now, even with the current version nette (2.3.8)

David Grudl
Nette Core | 8111
+
0
-

Could you send pull request?

meikr
Member | 2
+
0
-

Sorry, I don't have any idea to solution. In new Nette is another code for insert function.