所以我必须用golang程序创建一个sqlite表,所以我这样做了:
package main
import (
"database/sql"
"log"
_ "github.com/mattn/go-sqlite3"
)
func main() {
database, err := sql.Open("sqlite3", "./ProjetForum.db")
if err != nil {
log.Fatal(err)
}
defer database.Close()
statement, err := database.Prepare("CREATE TABLE IF NOT EXISTS Users (UserID integer NOT NULL primary key, Pseudo text NOT NULL , Email text NOT NULL , Rank integer NOT NULL DEFAULT 0, Phone text , Description text , ArrivingDate integer NOT NULL DEFAULT CURRENT_TIMESTAMP , Key text NOT NULL , Verified integer NOT NULL DEFAULT 0 , Banned integer NOT NULL DEFAULT 0 , Deleted integer NOT NULL DEFAULT 0 , Points integer NOT NULL DEFAULT 0 , Staff integer NOT NULL DEFAULT 0 , Image blob )")
if err != nil {
log.Fatal(err)
}
statement.Exec()
statement, erro := database.Prepare("CREATE TABLE IF NOT EXISTS Posts (PostID integer NOT NULL primary key , Title text NOT NULL , Description text NOT NULL , PublishDate integer NOT NULL DEFAULT CURRENT_TIMESTAMP, Closed integer NOT NULL DEFAULT 0 , Verified integer NOT NULL DEFAULT 0 , ReviewID integer NOT NULL DEFAULT 0 , Deleted text NOT NULL , ToReview integer NOT NULL DEFAULT 0 , Points integer NOT NULL DEFAULT 0 , Likes integer NOT NULL DEFAULT 0 , Dislikes integer NOT NULL DEFAULT 0 , UserID integer NOT NULL DEFAULT 0, FOREIGN KEY (`UserID`) references Users(`UserID`)) ")
if erro != nil {
log.Fatal(erro)
}
statement.Exec()
}
第二个不想自己执行它,第一个是正确的创建自身,但无法创建表。Post
繁星点点滴滴
相关分类