Welcome Guest, Not a member yet? Register   Sign In
insert_batch not inserting everything?
#1

[eluser]sotoz[/eluser]
Hello I'm using insert_batch to mass insert 10.000 rows into a table in a database. I'm making some tests and I have noticed that sometimes all the 10.000 rows are getting inserted correctly but in some occasions I miss 100+ rows in my table's total count.

If one insert has wrong parameters (and could not obviously be inserted into the table due to field restrictions for example), it won't affect the other inserts into the table? Or if one insert fails it will rollback the whole insert_batch, like a transaction?

How can I debug insert_batch() for such an occasion?
#2

[eluser]sotoz[/eluser]
I have made some changes on the DB_active_rec.php to do some logging during the insert_batch and so far I can't successfully reproduce the problem to see what is going wrong. But as far as the problem appeared 2-3 times at the beginning and I did not major changes to my logic to fix it, I can't leave it like this as I don't trust codeigniter's insert_batch function for production.

I have to think something else for inserting thousands of rows into my database.

anyone has any clue for this kind of problem?
#3

[eluser]jairoh_[/eluser]
IMO, if i were you, i won't use insert_batch, i will just loop over and put every insert in a catching exception or add @ as prefix so it will continue looping even though some inserts fail.
ex.
Code:
for ( .... ) {
                try {
                       //insert query here
                      //or also you can add @ prefix
                      @this->db->...... insert ...
                } catch ( ... ) {
                }
}

try doing it sir. just my one cent. tnx
#4

[eluser]sotoz[/eluser]
Hi jairoh_, thanks for your answer but doing one insert per time isn't going to be a viable solution for me as for 10k+ inserts that would take many minutes to complete and with batch insert that takes seconds.

The next thing I'm going to try is not using CI's insert_batch (as it seems it isn't working right), and try implementing my own logic for mass inserts.


EDIT : I just did a test and I tried inserting 19890 rows which only 19789 were inserted into my database...




Theme © iAndrew 2016 - Forum software by © MyBB