php - LOAD DATA INFILE - Set Value on Count -


user's can upload csv , define them columns.
csv hasn't statick definition, more every user can define csv want. users bought account limited number of products can "activate".
example make things clear:
user has account allows him activate 1000 products.
in csv uploading, set 1100 products active.
load csv our mysql-db load data infile query.

to avoid behavior user can activate more products csv account limited - there possible solution say, like:

active = if(@active = 1 , counter <= 1000, (1 , counter++), 0 ) 

ok, solved und came following solution - inspired eggyal's comment.
know problem highly individual, if abstract ( try abstract answer ) maybe helpfull other or similar problems load data infile querys.
1) load csv-values temporary table.
in cases enough modify several values.
in probelm wasn't cause important, how many products active after in final table.
active values can change, products active in final table set inactive csv, can't sure final sum of active products after loaded hole csv final table. move on step 2. ( if allready modified values in step 1)

2) push csv-values loaded table_tmp table_final
query example may you:

update  table_final, table_tmp set  table_final.value1 = table_tmp.value1, table_final.value2 = table_tmp.value2  table_final.some_key = table_tmp.some_key 

3) cut things, on limit
did update-query limit-param.
4) delete rows in table_final

final thoughts:
problem discovered is, can't put values buck in order order of user's csv. if wan't start setting "active"-value these products last in csv, kind of lost, because cant order. if know way restore order, - or come better solution - please let know ;)


Comments