@@ -1973,12 +1973,13 @@ public function insertMultiple($table, array $data)
1973
1973
* array('value1', 'value2')
1974
1974
*
1975
1975
* @param string $table
1976
- * @param array $columns
1976
+ * @param string[] $columns
1977
1977
* @param array $data
1978
- * @return int
1979
- * @throws \Zend_Db_Exception
1978
+ * @param int $strategy
1979
+ * @return int
1980
+ * @throws \Zend_Db_Exception
1980
1981
*/
1981
- public function insertArray ($ table , array $ columns , array $ data )
1982
+ public function insertArray ($ table , array $ columns , array $ data, $ strategy = 0 )
1982
1983
{
1983
1984
$ values = [];
1984
1985
$ bind = [];
@@ -1990,10 +1991,16 @@ public function insertArray($table, array $columns, array $data)
1990
1991
$ values [] = $ this ->_prepareInsertData ($ row , $ bind );
1991
1992
}
1992
1993
1993
- $ insertQuery = $ this ->_getInsertSqlQuery ($ table , $ columns , $ values );
1994
+ switch ($ strategy ) {
1995
+ case self ::INSERT_ON_DUPLICATE :
1996
+ $ query = $ this ->_getReplaceSqlQuery ($ table , $ columns , $ values );
1997
+ break ;
1998
+ default :
1999
+ $ query = $ this ->_getInsertSqlQuery ($ table , $ columns , $ values );
2000
+ }
1994
2001
1995
2002
// execute the statement and return the number of affected rows
1996
- $ stmt = $ this ->query ($ insertQuery , $ bind );
2003
+ $ stmt = $ this ->query ($ query , $ bind );
1997
2004
$ result = $ stmt ->rowCount ();
1998
2005
1999
2006
return $ result ;
@@ -3635,6 +3642,26 @@ protected function _getInsertSqlQuery($tableName, array $columns, array $values)
3635
3642
return $ insertSql ;
3636
3643
}
3637
3644
3645
+ /**
3646
+ * Return replace sql query
3647
+ *
3648
+ * @param string $tableName
3649
+ * @param array $columns
3650
+ * @param array $values
3651
+ * @return string
3652
+ */
3653
+ protected function _getReplaceSqlQuery ($ tableName , array $ columns , array $ values )
3654
+ {
3655
+ $ tableName = $ this ->quoteIdentifier ($ tableName , true );
3656
+ $ columns = array_map ([$ this , 'quoteIdentifier ' ], $ columns );
3657
+ $ columns = implode (', ' , $ columns );
3658
+ $ values = implode (', ' , $ values );
3659
+
3660
+ $ replaceSql = sprintf ('REPLACE INTO %s (%s) VALUES %s ' , $ tableName , $ columns , $ values );
3661
+
3662
+ return $ replaceSql ;
3663
+ }
3664
+
3638
3665
/**
3639
3666
* Return ddl type
3640
3667
*
0 commit comments