Skip to content

Instantly share code, notes, and snippets.

@vendion
Created February 24, 2012 16:17
Show Gist options
  • Save vendion/1901836 to your computer and use it in GitHub Desktop.
Save vendion/1901836 to your computer and use it in GitHub Desktop.
Example code of gosqlite3 erroring if database already exists
package main
import (
"fmt"
"github.com/kuroneko/gosqlite3"
)
func main() {
db, err := sqlite3.Open("test.db") //IF test.db already exists and is valid SQLite3 database this throws error, but the database can be opened with sqlite3 command
if err != nil {
panic(err)
}
defer db.Close()
_, err = db.Execute( "CREATE TABLE foo (id INTEGER PRIMARY KEY ASC, name VARCHAR(10));" )
if err != nil {
panic(err)
}
_, err = db.Execute( "INSERT INTO foo (id,name) VALUES ('1', 'John');" )
if err != nil {
panic(err)
}
fmt.Println("Done with no error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment