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

Bug where using parameter for limit in prepare statement #509

Closed
wengwei-ola opened this issue Jul 25, 2021 · 1 comment · Fixed by #510
Closed

Bug where using parameter for limit in prepare statement #509

wengwei-ola opened this issue Jul 25, 2021 · 1 comment · Fixed by #510

Comments

@wengwei-ola
Copy link
Contributor

wengwei-ola commented Jul 25, 2021

There seems to be a bug when preparing statement like:
"SELECT test_user.uid FROM test_user WHERE test_user.uid = 123 limit ?"

The engine will returns error: Error 1105: unknown error: invalid type: LONGTEXT

The bug could re-produce with:

go.mod

go 1.16

require (
	github.com/dolthub/go-mysql-server v0.10.0
	github.com/go-sql-driver/mysql v1.6.0

)

main.go

package main

import (
	dbsql "database/sql"

	sqle "github.com/dolthub/go-mysql-server"
	"github.com/dolthub/go-mysql-server/auth"
	"github.com/dolthub/go-mysql-server/memory"
	"github.com/dolthub/go-mysql-server/server"
	"github.com/dolthub/go-mysql-server/sql"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, _ := dbsql.Open("mysql", "root:@tcp(127.0.0.1:3307)/test")
	defer db.Close()

	stmtOut, err := db.Prepare("SELECT `uid` FROM `test_user` WHERE `uid` = 123 limit ?")
	if err != nil {
		panic(err.Error())
	}
	defer stmtOut.Close()
}

func init() {
	engine := sqle.NewDefault()
	db := memory.NewDatabase("test")
	AddTestUserTable(db)
	engine.AddDatabase(db)

	config := server.Config{
		Protocol: "tcp",
		Address:  "localhost:3307",
		Auth:     auth.NewNativeSingle("root", "", auth.AllPermissions),
	}

	s, err := server.NewDefaultServer(config, engine)
	if err != nil {
		panic(err)
	}

	go s.Start()
}

func AddTestUserTable(db *memory.Database) {
	tableName := "test_user"
	t := memory.NewTable(tableName, sql.Schema{
		{Name: "uid", Type: sql.Uint32, Nullable: false, Source: "test_user",
			AutoIncrement: false, Comment: "", PrimaryKey: true},
	})
	db.AddTable(tableName, t)

	ctx := sql.NewEmptyContext()

	rows := []sql.Row{
		sql.NewRow(123),
	}

	for _, row := range rows {
		t.Insert(ctx, row)
	}
}
@wengwei-ola wengwei-ola changed the title Bug where passing limit parameter in prepare statement Bug where using parameter for limit in prepare statement Jul 25, 2021
@VinaiRachakonda
Copy link
Contributor

Great catch @Weng-Wei. We'll have a review out soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants