Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepared statement Issue with dolt_diff_<table> #3916

Closed
bheni opened this issue Jul 25, 2022 · 5 comments
Closed

Prepared statement Issue with dolt_diff_<table> #3916

bheni opened this issue Jul 25, 2022 · 5 comments
Assignees
Labels
bug Something isn't working sql Issue with SQL

Comments

@bheni
Copy link
Contributor

bheni commented Jul 25, 2022

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.

@timsehn
Copy link
Sponsor Contributor

timsehn commented Jul 25, 2022

Yikes. This is a bad one.

@fulghum fulghum added the bug Something isn't working label Jul 25, 2022
@timsehn timsehn added the sql Issue with SQL label Aug 24, 2022
@timsehn
Copy link
Sponsor Contributor

timsehn commented Aug 31, 2022

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

@timsehn timsehn changed the title Prepared statement Issue Prepared statement Issue with dolt_diff_<table> Aug 31, 2022
@jycor
Copy link
Contributor

jycor commented Aug 31, 2022

I believe this PR I have will fix it: dolthub/go-mysql-server#1229

I'm still testing and double checking that everything is right

@jycor
Copy link
Contributor

jycor commented Aug 31, 2022

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

@timsehn
Copy link
Sponsor Contributor

timsehn commented Aug 31, 2022

We can resolve.

@timsehn timsehn closed this as completed Aug 31, 2022
@jycor jycor closed this as completed Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

5 participants