dolt
dolt copied to clipboard
Prepared statement Issue
create a new database and clone the us-jails database in it
mkdir ~/doltdbs/
cd doltdbs
dolt clone dolthub/us-jails
Run this query from the command line:
>dolt sql -q "SELECT count(*) FROM dolt_diff_jails WHERE from_commit=HASHOF('HEAD~2') AND to_commit=HASHOF('HEAD~1');"
+----------+
| count(*) |
+----------+
| 3 |
+----------+
Now running the following program with a dsn that points to your local doltdbs directory we created earlier:
package main
import (
"context"
"database/sql"
"fmt"
"os"
_ "github.com/dolthub/driver"
)
func errExit(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
}
func main() {
if len(os.Args) != 2 {
fmt.Println("Expected a single command line argument in the format: file:///path/to/doltdbs?commitname=<user_name>&commitemail=<email>&database=<database>")
return
}
dataSource := os.Args[1]
db, err := sql.Open("dolt", dataSource)
errExit(err)
ctx := context.Background()
stmt, err := db.PrepareContext(ctx, "SELECT count(*) FROM dolt_diff_jails WHERE from_commit=HASHOF(?) AND to_commit=HASHOF(?);")
errExit(err)
rows, err := stmt.QueryContext(ctx, "HEAD~2", "HEAD~1")
errExit(err)
var count int
rows.Next()
err = rows.Scan(&count)
errExit(err)
fmt.Println("COUNT(*) =", count)
}
The output is: COUNT(*) = 5320
Which does not match the results retrieved from the command line. It does match what you get from the command line if you do not include the where clause.
Yikes. This is a bad one.
Did we make any progress here @JCOR11599 or @max-hoffman ?
I believe this PR I have will fix it: https://github.com/dolthub/go-mysql-server/pull/1229
I'm still testing and double checking that everything is right
The fix for this along with tests have made it to main.
We can resolve.