You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the integer is hardcoded like "INSERT INTO person (name, age) VALUES (?, 30)" I can insert successfully and I can scan into a Go int.
The database is in :memory:.
Any ideas why would it be trying to insert a null?
package main
import (
"database/sql""fmt""log"
_ "github.com/alexbrainman/odbc"// Import the ODBC driver
)
funcmain() {
// Set up connection stringconnString:="DSN=ddb;"// Connect to the databasedb, err:=sql.Open("odbc", connString)
iferr!=nil {
log.Fatal("Error connecting to database:", err)
}
deferdb.Close()
// Ping the database to verify connectionerr=db.Ping()
iferr!=nil {
log.Fatal("Error pinging database:", err)
}
fmt.Println("Connected to database!")
_, err=db.Exec("CREATE TABLE person (name VARCHAR(255), age INT NOT NULL)")
iferr!=nil {
log.Fatal("Error creating table:", err)
}
fmt.Println("Table created successfully!")
// Insert sample values_, err=db.Exec("INSERT INTO person (name, age) VALUES (?, 30)", "John")
iferr!=nil {
log.Fatal("Error inserting values 30:", err)
}
fmt.Println("This works; inserted successfully!")
insertStmt, err:=db.Prepare("INSERT INTO person (name, age) VALUES (?, ?)")
iferr!=nil {
log.Fatal("Error preparing insert statement:", err)
}
deferinsertStmt.Close()
// this below fails_, err=insertStmt.Exec("Alice", 25)
iferr!=nil {
log.Fatal("Error inserting values:", err)
}
fmt.Println("Sample values inserted successfully!")
// Select the first valuevarnamestringvarageinterr=db.QueryRow("SELECT name, age FROM person LIMIT 1").Scan(&name, &age)
iferr!=nil {
log.Fatal("Error retrieving data:", err)
}
fmt.Printf("First person: Name=%s, Age=%d\n", name, age)
}
I get
go run .
Connected to database!
Table created successfully!
2024/04/23 16:34:30 Error inserting values:SQLExecute: {HY000} ODBC_DuckDB->SingleExecuteStmt
Constraint Error: NOT NULL constraint failed: person.age
exit status 1
The text was updated successfully, but these errors were encountered:
I can insert and select strings / varchar.
If the integer is hardcoded like
"INSERT INTO person (name, age) VALUES (?, 30)"
I can insert successfully and I can scan into a Go int.The database is in :memory:.
Any ideas why would it be trying to insert a null?
I get
The text was updated successfully, but these errors were encountered: