问题遇到的现象和发生背景
想要学习一下使用Go操作SQLite数据库
问题相关代码,请勿粘贴截图
package main
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type LogStatistics struct {
gorm.Model
logStatisticsId string
topVisitArticleList string
topCoastTimeRequestList string
createTime int64
updateTime int64
}
func main() {
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
// 迁移 schema
err = db.AutoMigrate(&LogStatistics{})
if err != nil {
return
}
// Create
db.Create(&LogStatistics{topVisitArticleList: "00", topCoastTimeRequestList: "xx"})
// Read
var logStatistics LogStatistics
// 根据整型主键查找
db.First(&logStatistics, 1)
// 查找 code 字段值为 D42 的记录
db.First(&logStatistics, "topVisitArticleList = ?", "00")
//// Update - 将 logStatistics 的 price 更新为 200
//db.Model(&logStatistics).Update("Price", 200)
//// Update - 更新多个字段
//db.Model(&logStatistics).Updates(Product{Price: 200, Code: "F42"}) // 仅更新非零值字段
//db.Model(&logStatistics).Updates(map[string]interface{}{"Price": 200, "Code": "F42"})
//
//// Delete - 删除 logStatistics
//db.Delete(&logStatistics, 1)
}
运行结果及报错内容
GOROOT=D:\ProgramData\GOPATH\go1.17.7 #gosetup
GOPATH=D:\ProgramData\GOPATH #gosetup
D:\ProgramData\GOPATH\go1.17.7\bin\go.exe build -o C:\Users\HP\AppData\Local\Temp\GoLand\___go_build_admin_data_show.exe admin_data_show #gosetup
# github.com/mattn/go-sqlite3
cc1plus.exe: warning: command line option '-std=gnu99' is valid for C/ObjC but not for C++
_cgo_export.c: In function 'void _cgo_1ad64cd63b8b_Cfunc__Cmalloc(void*)':
_cgo_export.c:233:53: error: invalid conversion from 'void*' to '_cgo_1ad64cd63b8b_Cfunc__Cmalloc(void*)::<unnamed struct>*' [-fpermissive]
} __attribute__((__packed__, __gcc_struct__)) *a = v;
Compilation finished with exit code 2
我的解答思路和尝试过的方法
根据网上的一些教程:尝试安装https://jmeubank.github.io/tdm-gcc/articles/2021-05/10.3.0-release的GCC程序,没用,依旧是这个报错
Go初学者,无从下手了
我想要达到的结果
正常运行并能够操作数据库