RSol / RDB

Yii extention for MySQL database
5 stars 4 forks source link

insertUpdate doesn't work #2

Open tamvm opened 11 years ago

tamvm commented 11 years ago

Hi guy,

Thanks for your contribution, but I managed to use with inserUpdate (INSERT ON UPDATE DUPLICATE) as

Yii::app()->db->createCommand()->insertUpdate('table_name'
      array("fiverr_user_id" => "548",
    ),
    array("conversation" => "Asd",
      "user_id" => "5",
      "client_name" => "deeyazzious",
      "conversation" => "asd"
));

It raises this exception:

Array to string conversion

I also try to debug in your script and found out that you may pass wrong order params for _insertPrepare. Please help me test it again.

Thanks,

RSol commented 11 years ago
/**
* Creates and executes an INSERT ... ON DUPLICATE KEY UPDATE SQL statement.
* The method will properly escape the column names, and bind the values to be inserted.
* @param string $table the table that new rows will be inserted into.
* @param array $columns the column data (name=>value) to be inserted into the table
* or array(array(name=>value),array(name=>value)).
* @param array $update the column data (name=>value) to be update
* @param string $ignore '' or 'IGNORE'
* @return integer number of rows affected by the execution.
*/
public function insertUpdate($table, $columns, $update=array(), $ignore='')

You should add first param - table name. Also... can you write your table structure?

tamvm commented 11 years ago

Sorry, my bad, even I tried with table name as well, it still raise above exception, you can check places where use insertPrepare, the order params may be confused.

RSol commented 11 years ago

Added params check. Please update and test.

tamvm commented 11 years ago

Thanks for your update.!

RSol commented 11 years ago

Is your bug fixed?

tamvm commented 11 years ago

Actually, I haven't tried with your update, I use select model before to find out the model exists or not. Also, could you check method: _insertPrepare? This method is declared at line 87 with params: $columns, $iterat='', $params=array(), but you used at line 76 with params: $columns, $params, it may cause the problem, because params take place order of iterat. Right?

RSol commented 11 years ago

Yes you are right - thank you. Fixed.