我正在开发一个使用以太坊区块链的项目,我想用块数据填充数据库,但对于 block_id 自动增量不起作用。
下面的代码是创建查询
stmt, err := db.Prepare("CREATE TABLE IF NOT EXISTS block( block_id bigint NOT NULL AUTO_INCREMENT, block_num varchar(200), block_hash varchar(200), tx_count int, PRIMARY KEY (block_id) );")
下面的代码用于插入数据
func InsertBlock(db *sql.DB, block_num string, block_hash string, tx_count int) {
stmt, err := db.Prepare("INSERT INTO block VALUES(?, ?, ?)")
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("Preparation successfull for block insert: ")
}
_, err = stmt.Exec(block_num, block_hash, tx_count)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("Entry is block table is successfull: ")
}
}
怎样才能让它自动递增呢?
这是我收到的错误:
Error 1136: Column count doesn't match value count at row 1
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x4e1930]
慕田峪4524236
相关分类