Created
February 24, 2012 16:17
-
-
Save vendion/1901836 to your computer and use it in GitHub Desktop.
Example code of gosqlite3 erroring if database already exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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