一、创建测试表 SQL语句如下: 1CREATE TABLE userinfo( 2 uid INTEGER PRIMARY KEY AUTOINCREMENT, 3 username TEXT NOT NULL, 4 departname TEXT NOT NULL, 5 created TEXT 6); 二、golang操作SQLite 具体语句如下: 1package main 2import ( 3 "database/sql" 4 "fmt" 5 _ "github.com/mattn/go-sqlite3" 6) 7func main() { 8 db, err := sql.Open("sqlite3", "./foo.db") 9 checkErr(err) 10 //插入数据 11 stmt, err := db.Prepare("INSERT INTO userinfo(username, departname, created) values(?,?,?)") 12 checkErr(err) 13 res, err := stmt.Exec("361way", "研发部", "2019-03-06") 14 checkErr(err) 15 id, err := res.LastInsertId() 16 checkErr(err) 17 fmt.Println(id) 18 //更新数……
Continue reading