@@ -174,35 +174,45 @@ public function setProfile($profile)
174
174
* High speed row insertion.
175
175
*
176
176
* @note This is might be very MySQL specifc. Not recomended for normal usage.
177
+ * @note We assume `pf_insRecordExtraParse`.
177
178
*
178
179
* @param array $pv_records Records to be inserted.
179
180
* @return int 0 upon error
180
181
* @throws Exception If \a pv_tableName was not set.
181
182
*/
182
- public function pf_insRecords (&$ pv_records )
183
+ public function pf_insRecords (&$ pv_records, $ fileId )
183
184
{
184
185
if (empty ($ this ->pv_tableName ))
185
186
{
186
187
throw new Exception ("Tabel name is empty " );
187
188
}
188
189
190
+ // static values
191
+ $ pv_staticRecord = array ();
192
+ $ pv_staticRecord ['csv_file ' ] = $ fileId ;
193
+ $ this ->pf_insRecordExtraParse ($ pv_staticRecord ); // Note! Assuming it only adds values.
194
+ $ pv_staticValues = "" ;
195
+ foreach ($ pv_staticRecord as $ pv_val )
196
+ {
197
+ $ pv_staticValues .= "' " .mysql_real_escape_string ($ pv_val )."', " ;
198
+ }
199
+ $ pv_staticValues = rtrim ($ pv_staticValues , ", " );
200
+
189
201
// Prepare "header" of the INSERT statement
190
- $ pv_record = $ pv_records [0 ];
191
- $ this ->pf_insRecordExtraParse ($ pv_record );
192
- $ pv_ins_sql_arr = $ this ->pf_getInsSQLArrays ($ pv_record );
202
+ $ pv_headerRecord = array_merge ($ pv_records [0 ], $ pv_staticRecord );
203
+ $ pv_ins_sql_arr = $ this ->pf_getInsSQLArrays ($ pv_headerRecord );
193
204
$ sql = "INSERT INTO {$ this ->pv_tableName } {$ pv_ins_sql_arr ['' ]['keys ' ]}
194
205
VALUES "
195
206
;
196
207
197
208
// Build SQL
198
209
foreach ($ pv_records as &$ pv_record ) {
199
210
$ values = "" ;
200
- $ this ->pf_insRecordExtraParse ($ pv_record );
201
211
foreach ($ pv_record as $ pv_val )
202
212
{
203
213
$ values .= "' " .mysql_real_escape_string ($ pv_val )."', " ;
204
214
}
205
- $ sql .= "\n( " . rtrim ( $ values, " , " ) . " ), " ;
215
+ $ sql .= "\n( $ values $ pv_staticValues ), " ;
206
216
}
207
217
$ sql = rtrim ($ sql , ", " );
208
218
0 commit comments