0
votes

I have a db table:

ConfigID | Type  | Key            | Value
--------------------------------------------------------------
0        | "API" | "ClientID"     | "iofoewi"
1        | "API" | "ClientSecret" | "eijfoiewjfioejfoiewjfoie"

Take the following code:

    $data = array(
        array(
            'Key' => "ClientID",
            'Value' => $testAPICredential->ClientID
        ),
        array(
            'Key' => "ClientSecret",
            'Value' => $testAPICredential->ClientSecret
        )
    );

    try
    {
        $this->context->db->trans_start();
        $this->context->db->update_batch( $this->tableName, $data, "Key" ); 
        $this->context->db->trans_complete();        
        return ($this->context->db->trans_status() === FALSE)? FALSE:TRUE;
    }
    catch( Exception $e )
    {
        return FALSE;
    }

It outputs this SQL when I use the profiler:

UPDATE `config` SET `Value` = CASE 
WHEN `Key` = 'ClientID' THEN 'iofoewi2'
WHEN `Key` = 'ClientSecret' THEN 'eijfoiewjfioejfoiewjfoie2'
ELSE `Value` END WHERE `Key` IN ('ClientID','ClientSecret')  

And yet the database table is un=touched?

Any ideas?

1
Chances are the transaction failed and it was rolled back. What does $this->context->db->trans_status() return? Try turning on the db_debug option in config/database.php to see if any errors get returned. - Rocket Hazmat
The context is an instance of a class that extends CI_Model. Thanks, I'll give that a try - Jimmyt1988
You're right, Oracle seems to be more picky than MySQL. I've deleted my answer since it's not really helpful. - Max

1 Answers

0
votes

If you are using CI 3.1.2 maybe it's will help you.

In our project. We find out that function update_patch sometimes will be have problem. Index for update sometimes will be wrong. So i found out another function for replace is update_batch_real_index In file /yourproject/system/database/DB_query_builder.php

From time using this to present is 3 months we not found any bug again. Maybe you should try that.