I have a problem sending an array of arrays of bytes along with my query to SqlX.
I'll give a concrete example, consider the following:
I have these hashes:
hash1 := []byte("84ce419844366f84de5352c257f06e356fe1ee4c4248e774c66cd44a7cf24c84f6492e988287db9fc3e540dac4efbd4813ce6f82afa9f552b1f5d46376dcac30")
hash2 := []byte("84ce419844366f84de5352c257f06e356fe1ee4c4248e774c66cd44a7cf24c84f6492e988287db9fc3e540dac4efbd4813ce6f82afa9f552b1f5d46376dcac30")
hash3 := []byte("84ce419844366f84de5352c257f06e356fe1ee4c4248e774c66cd44a7cf24c84f6492e988287db9fc3e540dac4efbd4813ce6f82afa9f552b1f5d46376dcac30")
hash4 := []byte("84ce419844366f84de5352c257f06e356fe1ee4c4248e774c66cd44a7cf24c84f6492e988287db9fc3e540dac4efbd4813ce6f82afa9f552b1f5d46376dcac30")
Stored like this:
hashes := [][]byte{}
hashes = append(txsHashes, txHash1)
hashes = append(txsHashes, txHash2)
hashes = append(txsHashes, txHash3)
hashes = append(txsHashes, txHash4)
Now I want to delete all rows that their hash is in the hashes array.
Query:
query := "DELETE SomeTable WHERE hash IN (?)"
I'm creating the DB connection:
db := &sqlx.DB{}
sqlDriverStr := "sqlite3"
dataSourcePath := "./mock.db"
sqlDriver, err := sql.Open(sqlDriverStr, dataSourcePath)
if err != nil {
log.Fatal(err)
}
db = sqlx.NewDb(sqlDriver, sqlDriverStr)
err = db.Ping()
if err != nil {
log.Fatal(err)
}
Execute the query:
deleteQuery := "DELETE SomeTable WHERE hash IN (?)"
_, err = db.Exec(deleteQuery, txsHashes)
if err != nil {
log.Fatal(err)
}
I get an error back:
2018/12/07 00:57:59 sql: converting argument $1 type: unsupported type [][]uint8, a slice of slice
Any idea what can I do?
Thanks