Problem with insert in SQlite database

Hi there,

I’m trying to manage a SQlite database using toolkit sql API (v. 2.3.1), but I have some strange insert problems.

This is my code:

$db->table('table__name')->insert(array(
	'guid' => 'data1',
	'nome' => 'data2'
));	

And this is the result:

The problem is not multiple rows, but guid -> “data2” instead of “data1”

:sweat: :sweat:

Thanks

I think that the problem is related on something about “bindings”.

If I change:

//$output[] = $valueBinding;
$output[] = '"' . $value . '"';

in /toolkit/lib/sql.php (row 403), everything works perfectly.

Could you please post the output of:

var_dump($db->table('table__name')->debug()->insert(array(
	'guid' => 'data1',
	'nome' => 'data2'
)));

Here it is:

string(1) "0"

Have you inserted the ->debug() statement into the query chain? Looks like the result of the run query instead of the debug data.

Yes, I did.

I’m using toolkit not in a Kirby project.
Could it be the problem?

That’s strange. I will look into this.

It shouldn’t be, but thanks for the hint, I will test this.

Hum, I think it’s a local problem.
I’m working local with XAMPP and PHP 5.6.19.

Online it works, same PHP version.

:confused:

I have just tested it locally and couldn’t reproduce the issue either. Seems to be an issue with your local PHP installation. Maybe it linked in a different version of the sqlite library or something.

I could however reproduce the issue that the debug option didn’t do anything for the insert query. This is now fixed for Kirby 2.3.2.

1 Like

Ok, thanks!

I think I’ll bypass bindings in local project and reactive them online.
It’s a mistery… :anguished:

Ciao!

Hi, here it is the output using 2.3.2:

array(3) { ["query"]=> string(94) "INSERT INTO "table__name" ("guid", "nome") VALUES (:value_57a4a5ad23b68, :value_57a4a5ad23b68)" ["bindings"]=> array(1) { [":value_57a4a5ad23b68"]=> string(5) "data2" } ["options"]=> array(0) { } }

Oh, that’s interesting. Looks like Kirby actually generates only one binding for you and uses that for both fields, which is why you get the same value in both columns.

The only reason I can think of is that uniqid() generates the same value twice on your server. Could you please test what the following outputs:

<?php

var_dump(uniqid());
var_dump(uniqid());
var_dump(uniqid());

Sorry, I’m late.
Ok, finally the problem is that the outputs have the same unique id (!!), probably due to Xampp.

Googling I found this:

3 Likes

Interesting…
Are you using XAMPP on Windows?

Yep, XAMPP v3.2.2 on Windows

OK, then we finally found the issue. However it seems like this is a bug/non-intended feature of PHP on Windows, so there’s nothing we can do about it.