On 7 February 2017 at 15:11, Simon Slavin <slav...@bigfraud.org> wrote:
> > On 7 Feb 2017, at 6:56am, Niti Agarwal <n...@ionosnetworks.com> wrote: > > > Thanks for your reply. The length matters as I am appending 100 rows at a > > time in a sql statement. It is making very fast as compared to single sql > > insert in For loop. > > Copied the code below for reference. Here the list size is 100 > > Any better way to do this? Like I read about *bind*...not sure how I can > do > > it in Golang. > > Okay. By using an INSERT command with lots of value sets you are doing > things more efficiently than I thought. Each INSERT is its own transaction > so you are doing 100 INSERTs per transaction. > It would a lot simpler though to move the db.Begin() outside the for loop and execute multiple INSERT statements within the loop. > I am not familiar with GoLang. Can someone say if it’s appropriate to use > the two functions > > PathInfoStmt, err := db.Prepare(sql_PathInfo) > err = tx.Stmt(PathInfoStmt).Exec(valsPath…) > > like that ? I would expect Prepare to go with Step instead but I could > understand if the library being used makes it okay. > Yes, that's ok. These are not sqlite specific bindings, go takes a ODBC like approach where a standard interface[1] is used to connect to various database engines. [1] https://golang.org/pkg/database/sql/ Exec() is designed for INSERT/UPDATEs where you're not asking the DB for information. The read equivalent is Query() which returns a sql.Rows structure that you iterate over using Rows.Next(). -Rowan _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users