dolt icon indicating copy to clipboard operation
dolt copied to clipboard

Prepared statement Issue

Open bheni opened this issue 1 year ago • 1 comments

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.

bheni avatar Jul 25 '22 17:07 bheni

Yikes. This is a bad one.

timsehn avatar Jul 25 '22 18:07 timsehn

Did we make any progress here @JCOR11599 or @max-hoffman ?

timsehn avatar Aug 31 '22 17:08 timsehn

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

jycor avatar Aug 31 '22 17:08 jycor

The fix for this along with tests have made it to main.

jycor avatar Aug 31 '22 23:08 jycor

We can resolve.

timsehn avatar Aug 31 '22 23:08 timsehn