Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: SQL Lite driver with Builder -> InsertBatch has intermittend lastError reporting issues #3350

Closed
devorama opened this issue Jul 18, 2020 · 3 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@devorama
Copy link
Contributor

devorama commented Jul 18, 2020

Describe the bug
Good day, I dont really know where to post this as it feels asif it maybe more a PHP bug itself
than a Code Igniter, but here goes

I have a intermittend issue where with SQLite3 driver adding line with inserBatch function (all inside a transaction)
of builder the lasterror report does not always return the error. I have added debug lines to the code to try and see where
it goes wrong and this is the odd part. It actually still have the correct error reporting just as simpleQuery executes the insertSQL, but immediatly after it , it just falls back to 0 and message 'not a error'.

My log file looks as follow

ERROR - 2020-07-18 09:14:01 --> SQLite3 execute error code : 19,UNIQUE constraint failed: employees.emp_no
DEBUG - 2020-07-18 09:14:01 --> BaseConnection simpleQuery fail error code : 19,UNIQUE constraint failed: employees.emp_no
DEBUG - 2020-07-18 09:14:01 --> BaseConnection query fail error code : 0,not an error
DEBUG - 2020-07-18 09:14:01 --> BaseBuilder result : CodeIgniter\Database\SQLite3\Result Object
(
    [connID] => SQLite3 Object
        (
        )

    [resultID] => 
    [resultArray] => Array
        (
        )

    [resultObject] => Array
        (
        )

    [customResultObject] => Array
        (
        )

    [currentRow] => 0
    [numRows] => 
    [rowData] => 
)

DEBUG - 2020-07-18 09:14:01 --> BaseBuilder insertbatch after query error code : 0,not an error
DEBUG - 2020-07-18 09:14:01 --> Calling function after insertBatch call error code : 0,not an error

Now the Code changes (debug lines) I made was in
SQLite3\Connection.php
prent

In BaseConnection.php inside the public function query function
prent
and
prent

BaseBuilder.php in the public function insertBatch
prent

Note that I call inserbatch nommerally as follows
$builder->insertBatch($insertVals);

There is a workaround thou and that is why I think it is a PHP thing.
If I do a dummy query (something that will return nonthing for the table ) before I do the insertBatch
Then it WORKS !, it is so weird.

$builder->where('1 = 0')->get();
$builder->insertBatch($insertVals);

Also note I experience this intermittend issue only with my interface that accept JSON data as input, when I wrote a test
controller interface that does everything in code (even the array was hardcoded), then it worked every time without the workaround.

CodeIgniter 4 version
4.0.4

Affected module(s)
BaseBuilder.php
BaseConnection.php
SQLite3\Connection.php

Expected behavior, and steps to reproduce if appropriate
If a Error is experienced and one calls the error function that calls the lastError function one would expect the error
that was returned first just after execute to still show instead of 0.

Context
Win 7
Xamp (Apache/php)
PHP 7.4

@devorama devorama added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 18, 2020
@michalsn
Copy link
Member

Could you please provide some sample code that will allow us to reproduce this bug? As I understand it's not that obvious. If you need more files to present this you can use gist.

@devorama
Copy link
Contributor Author

Will try so far I could only do it as I am actually writting a external system that sends in json data and then CI process that , when I tried to emulate the data by pasting the json in code and just running the code, but when I feed it in via http stream then it does this, thus little tricky. Will see what I can figure out to emulate it. Thanks

@paulbalandan
Copy link
Member

No updates whether this issue is resolved or not. Closing for lack of activity, but feel free to reopen if more information can be provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants