sql - Can't insert more than 150 rows -


i using go-sql-driver/mysql insert ton of movies omdb data dump. parsing data , inserting following code:

_, err = database.query("insert `movies` (`name`, `year`, `release_date`, `full_plot`, `genre`, `imdb_id`) values (?, ?, ?, ?, ?, ?)", movie.name, movie.year, movie.releasedate, movie.fullplot, movie.genre, movie.imdbid)  if err != nil {     return false, nil } return true, nil 

it works, 150 rows. doing wrong?

your code seems discard error value returned, shouldn't do; handle gracefully. see error is, if you're opening many connections db, should use database connection pool , set (*db) setmaxopenconns value.

(*db)query typically used select statements return rows, use (*db)exec or (*stmt)exec insert.

i'd advise using db connection pool, , (*sql.db)prepare prepare statement , run inserts (even concurrently) using prepared statement.

see https://golang.org/pkg/database/sql/#db.prepare


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -