Database Batch Write judgment problem
My function is an order import function, the data inside the XLS import into MySQL, each time around 1000.
Now the problem is that each record has a code, I have to check the coding system has not been built, built well, on the import, if not built on this whole batch are not imported system, how should I do??
------Solution--------------------
Not understand, each record a code, but this code is not built well, how to a whole batch can not be imported, not this one can not import it?
If it is the one I want to not import, you can do this:
First read the 1000 data from the XLS file, at the same time read the Code table from the database, to encode the primary key to create an array, and then loop through your 1000 data, each time with this data encoding to find the encoding array in the existence, not exist then skip, the existence is saved into the database. Of course you can write SQL statements last-time save.
------Solution--------------------
It's nothing but trouble.
It's easy to implement, for each piece of content
First check if the encoding exists (select)
Reinsert (insert) based on results
Obviously your system uses a foreign key (it's self-made trouble for yourself)
In fact, direct insertion does not matter, it is not an error or insert invalid