SQLite "database is locked"

875 views
Skip to first unread message

Mike Appenzellar

unread,
Apr 29, 2014, 4:44:58 PM4/29/14
to golan...@googlegroups.com
I am trying to loop through table A and do a basic insert into table B based on whats found in table A. Should be easy/simple but I am getting a "database is locked" error. Thoughts? Here is a gist - https://gist.github.com/mappenzellar/21cc8ee10777ce8ff3b4

Tad Glines

unread,
Apr 29, 2014, 5:05:25 PM4/29/14
to Mike Appenzellar, golang-nuts
If I'm reading this (www.sqlite.org/lockingv3.html) correctly, you cannot concurrently read and write to the same sqlite db.
You'll have to read all the results from the rows instance and then close it before performing any writes.

-Tad

On Tue, Apr 29, 2014 at 1:44 PM, Mike Appenzellar <mappen...@gmail.com> wrote:
I am trying to loop through table A and do a basic insert into table B based on whats found in table A. Should be easy/simple but I am getting a "database is locked" error. Thoughts? Here is a gist - https://gist.github.com/mappenzellar/21cc8ee10777ce8ff3b4

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gwenn...@gmail.com

unread,
Apr 30, 2014, 2:10:37 AM4/30/14
to golan...@googlegroups.com
You should use a transaction (http://golang.org/pkg/database/sql/#DB.Begin) to make sure the {db=>tx}.Query and {db=>tx}.Exec are using the same underlying/native connection.
Reply all
Reply to author
Forward
0 new messages