Welcome Guest, Not a member yet? Register   Sign In
Transaction status FALSE but DB error NULL
#1

Hi!,

I'd like to catch the sqlsrv(driver) db-error from a codeigniter transac with insert_batch:

model:

Code:
public function sync($data)
   {
       $this->myDB->trans_start();
           $this->myDB->insert_batch('myTable', $data);
           $db_error = $this->myDB->error();
       $this->myDB->trans_complete();

       if ($this->myDB->trans_status() === FALSE)
       {        
           if (!empty($db_error['message']))
           {
               return $db_error['message'];
           }
       }
       else
           return true;
   }
}

The trans_status() works fine because a SQL "string truncated" error. The problem is, accord with the CI3 system sqlsrv driver :

Code:
public function error()
   {
       $error = array('code' => '00000', 'message' => '');
       $sqlsrv_errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);

       if ( ! is_array($sqlsrv_errors))
       {
           return $error;
       }
...


the sqlsrv_errors(SQLSRV_ERR_ERRORS) returns NULL (Error number: 00000)

But if I set the CI config/database.php to 'db_debug' => TRUE, CI show that error:


[Image: ykLqU.jpg]

Why??, exists another way to capture the DB-error?

Thanks in advance,

Regards
Reply
#2

(This post was last modified: 05-30-2018, 02:39 PM by dave friend.)

I may not be correct, but I suspect it might be because insert_batch will continue to iterate through the data set even if one item in the set results in a failed insert. Subsequent inserts may succeed meaning that $this->myDB->error(); will report no problem after the batch is finished. If you can set up a test where you know the last insert will fail you should be able to test my premise.

I don't see any way to capture the error when it happens short of extending CI_DB_query_builder and overwriting inset_batch().
Reply
#3

(05-30-2018, 02:39 PM)dave friend Wrote: I may not be correct, but I suspect it might be because insert_batch will continue to iterate through the data set even if one item in the set results in a failed insert. Subsequent inserts may succeed meaning that $this->myDB->error(); will report no problem after the batch is finished. If you can set up a test where you know the last insert will fail you should be able to test my premise.

I don't see any way to capture the error when it happens short of extending CI_DB_query_builder and overwriting inset_batch().

Hi, thanks. Is it possible to report this to the CI developers team?
Reply
#4

There have been a nuymber of issues reported about batches.
I don't know if this is the same as any of them or not.
You can raise an issue on our repo if this indeed appears to be a bug.
Reply
#5

Thanks a lot
Reply




Theme © iAndrew 2016 - Forum software by © MyBB