@@ -112,17 +112,17 @@ class MysqliDb
112112 */
113113 protected $ isSubQuery = false ;
114114
115- /**
116- * Name of the auto increment column
117- *
118- */
119- protected $ lastInsertId = null ;
115+ /**
116+ * Name of the auto increment column
117+ *
118+ */
119+ protected $ _lastInsertId = null ;
120120
121- /**
122- * Column names for update when using onDuplicate method
123- *
124- */
125- protected $ updateColumns = null ;
121+ /**
122+ * Column names for update when using onDuplicate method
123+ *
124+ */
125+ protected $ _updateColumns = null ;
126126
127127 /**
128128 * Return type: 'Array' to return results as array, 'Object' as object
@@ -247,6 +247,8 @@ protected function reset()
247247 $ this ->returnType = 'Array ' ;
248248 $ this ->_nestJoin = false ;
249249 $ this ->_tableName = '' ;
250+ $ this ->_lastInsertId = null ;
251+ $ this ->_updateColumns = null ;
250252 }
251253
252254 /**
@@ -562,17 +564,17 @@ public function where($whereProp, $whereValue = 'DBNULL', $operator = '=', $cond
562564 return $ this ;
563565 }
564566
565- /**
567+ /**
566568 * This function store update column's name and column name of the
567569 * autoincrement column
568570 *
569571 * @param Array Variable with values
570572 * @param String Variable value
571573 */
572- public function onDuplicate ($ updateColumns , $ lastInsertId = null )
574+ public function onDuplicate ($ _updateColumns , $ _lastInsertId = null )
573575 {
574- $ this ->lastInsertId = $ lastInsertId ;
575- $ this ->updateColumns = $ updateColumns ;
576+ $ this ->_lastInsertId = $ _lastInsertId ;
577+ $ this ->_updateColumns = $ _updateColumns ;
576578 }
577579
578580 /**
@@ -804,28 +806,54 @@ private function _buildInsert ($tableName, $insertData, $operation)
804806 return true ;
805807 }
806808
807- /**
809+ /**
808810 * Helper function to add variables into the query statement
809811 *
810812 * @param Array Variable with values
811813 */
812814 protected function _buildDuplicate ($ tableData )
813815 {
814- if (is_array ($ this ->updateColumns ) && !empty ($ this ->updateColumns )) {
816+ if (is_array ($ this ->_updateColumns ) && !empty ($ this ->_updateColumns )) {
815817 $ this ->_query .= " on duplicate key update " ;
816- if ($ this ->lastInsertId ) {
817- $ this ->_lastQuery .= $ this ->lastInsertId ."=LAST_INSERT_ID( " .$ this ->lastInsertId ."), " ;
818- $ this ->lastInsertId = null ;
818+ if ($ this ->_lastInsertId ) {
819+ $ this ->_lastQuery .= $ this ->_lastInsertId ."=LAST_INSERT_ID( " .$ this ->_lastInsertId ."), " ;
820+ $ this ->_lastInsertId = null ;
819821 }
820-
821- foreach ($ this ->updateColumns as $ value ) {
822- $ this ->_bindParam ($ tableData [$ value ]);
823- $ this ->_query .= "` " . $ value . "` = ?, " ;
822+
823+ foreach ($ this ->_updateColumns as $ column ) {
824+ $ this ->_query .= "` " . $ column . "` = " ;
825+
826+ // Simple value
827+ if (!is_array ($ tableData [$ column ])) {
828+ $ this ->_bindParam ($ tableData [$ column ]);
829+ $ this ->_query .= '?, ' ;
830+ continue ;
831+ }
832+
833+ // Function value
834+ $ arr = $ tableData [$ column ];
835+ $ key = key ($ arr );
836+ $ val = $ arr [$ key ];
837+ switch ($ key ) {
838+ case '[I] ' :
839+ $ this ->_query .= $ column . $ val . ", " ;
840+ break ;
841+ case '[F] ' :
842+ $ this ->_query .= $ val [0 ] . ", " ;
843+ if (!empty ($ val [1 ]))
844+ $ this ->_bindParams ($ val [1 ]);
845+ break ;
846+ case '[N] ' :
847+ if ($ val == null )
848+ $ this ->_query .= "! " . $ column . ", " ;
849+ else
850+ $ this ->_query .= "! " . $ val . ", " ;
851+ break ;
852+ default :
853+ die ("Wrong operation " );
854+ }
824855 }
825-
826856 $ this ->_query = rtrim ($ this ->_query , ', ' );
827- $ this ->lastInsertId = null ;
828- $ this ->updateColumns = null ;
829857 }
830858 }
831859
0 commit comments