You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLITE VERSION: 3.7.13
GO VERSION: 1.3.1
Latest go-sqlite3 as of 9/5/14
No error is being thrown while trying to insert when select is active. Should be getting some type of database is locked error. This issue is highly related to #39. The only difference is here we use transactions.
Here is some sample code. Every time code is run, there should be addition of 1 new record. However we are seeing a maximum of 2 rows, with the second row continuously being replaced with the newer record.
We can correct the code either by
changing
rows, err := db.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='TEMP';")
to
rows, err := tx.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='TEMP';")
No error is displayed because you are ignoring the error returned by the Commit.
Here is a quick fix:
defer func() {
if err := tx.Commit(); err != nil {
log.Fatalln("could not commit:", err)
}
}()
You're welcome.
I think that the following bradfitz's statement: https://groups.google.com/forum/#!topic/golang-nuts/FBgjdhHApuk
"Never defer a file Close when the file was opened for writing."
applies to Tx.Commit.
"Never defer a transaction Commit (without checking the error)."
SQLITE VERSION: 3.7.13
GO VERSION: 1.3.1
Latest go-sqlite3 as of 9/5/14
No error is being thrown while trying to insert when select is active. Should be getting some type of database is locked error. This issue is highly related to #39. The only difference is here we use transactions.
Here is some sample code. Every time code is run, there should be addition of 1 new record. However we are seeing a maximum of 2 rows, with the second row continuously being replaced with the newer record.
We can correct the code either by
changing
rows, err := db.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='TEMP';")
to
rows, err := tx.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='TEMP';")
Or applying the fix to #39 which is to change
db, err := sql.Open("sqlite3", "locked.sqlite")
to
db, err := sql.Open("sqlite3", "file:locked.sqlite?cache=shared&mode=rwc")
Or we can manually close the row. However some type of error should be displayed.
The text was updated successfully, but these errors were encountered: