From 5c252559e21594d7af475c03371556f5a1560557 Mon Sep 17 00:00:00 2001 From: hiroebe Date: Tue, 11 Jul 2023 23:03:33 +0900 Subject: [PATCH 1/3] fix missing unsigned param --- internal/compiler/resolve.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/compiler/resolve.go b/internal/compiler/resolve.go index c71d896126..3093752031 100644 --- a/internal/compiler/resolve.go +++ b/internal/compiler/resolve.go @@ -458,6 +458,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, OriginalName: c.Name, DataType: dataType(&c.Type), NotNull: p.NotNull(), + Unsigned: c.IsUnsigned, IsArray: c.IsArray, Table: &ast.TableName{Schema: schema, Name: rel}, Length: c.Length, From 85a4e85d2ebc2070ae0892daf931a6f3a1dcdd3e Mon Sep 17 00:00:00 2001 From: hiroebe Date: Tue, 25 Jul 2023 23:50:13 +0900 Subject: [PATCH 2/3] fix test --- .../testdata/schema_scoped_create/mysql/go/query.sql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/endtoend/testdata/schema_scoped_create/mysql/go/query.sql.go b/internal/endtoend/testdata/schema_scoped_create/mysql/go/query.sql.go index 454dc085a6..c270d18dfa 100644 --- a/internal/endtoend/testdata/schema_scoped_create/mysql/go/query.sql.go +++ b/internal/endtoend/testdata/schema_scoped_create/mysql/go/query.sql.go @@ -15,7 +15,7 @@ INSERT INTO foo.bar (id, name) VALUES (?, ?) ` type SchemaScopedCreateParams struct { - ID int64 + ID uint64 Name string } From f5069900cd23cdb8b17eb61dfb4d520b197aac78 Mon Sep 17 00:00:00 2001 From: hiroebe Date: Wed, 26 Jul 2023 00:27:52 +0900 Subject: [PATCH 3/3] add end-to-end test for unsigned_params --- .../testdata/unsigned_params/mysql/go/db.go | 31 +++++++++++++++++++ .../unsigned_params/mysql/go/models.go | 11 +++++++ .../unsigned_params/mysql/go/query.sql.go | 19 ++++++++++++ .../testdata/unsigned_params/mysql/query.sql | 4 +++ .../testdata/unsigned_params/mysql/sqlc.json | 12 +++++++ 5 files changed, 77 insertions(+) create mode 100644 internal/endtoend/testdata/unsigned_params/mysql/go/db.go create mode 100644 internal/endtoend/testdata/unsigned_params/mysql/go/models.go create mode 100644 internal/endtoend/testdata/unsigned_params/mysql/go/query.sql.go create mode 100644 internal/endtoend/testdata/unsigned_params/mysql/query.sql create mode 100644 internal/endtoend/testdata/unsigned_params/mysql/sqlc.json diff --git a/internal/endtoend/testdata/unsigned_params/mysql/go/db.go b/internal/endtoend/testdata/unsigned_params/mysql/go/db.go new file mode 100644 index 0000000000..fb6ae669f6 --- /dev/null +++ b/internal/endtoend/testdata/unsigned_params/mysql/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.19.1 + +package querytest + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/unsigned_params/mysql/go/models.go b/internal/endtoend/testdata/unsigned_params/mysql/go/models.go new file mode 100644 index 0000000000..5b3e1ef551 --- /dev/null +++ b/internal/endtoend/testdata/unsigned_params/mysql/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.19.1 + +package querytest + +import () + +type Foo struct { + ID uint32 +} diff --git a/internal/endtoend/testdata/unsigned_params/mysql/go/query.sql.go b/internal/endtoend/testdata/unsigned_params/mysql/go/query.sql.go new file mode 100644 index 0000000000..42320b2259 --- /dev/null +++ b/internal/endtoend/testdata/unsigned_params/mysql/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.19.1 +// source: query.sql + +package querytest + +import ( + "context" +) + +const createFoo = `-- name: CreateFoo :exec +INSERT INTO foo (id) VALUES (?) +` + +func (q *Queries) CreateFoo(ctx context.Context, id uint32) error { + _, err := q.db.ExecContext(ctx, createFoo, id) + return err +} diff --git a/internal/endtoend/testdata/unsigned_params/mysql/query.sql b/internal/endtoend/testdata/unsigned_params/mysql/query.sql new file mode 100644 index 0000000000..bb2844627d --- /dev/null +++ b/internal/endtoend/testdata/unsigned_params/mysql/query.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo (id INT UNSIGNED NOT NULL); + +-- name: CreateFoo :exec +INSERT INTO foo (id) VALUES (?); diff --git a/internal/endtoend/testdata/unsigned_params/mysql/sqlc.json b/internal/endtoend/testdata/unsigned_params/mysql/sqlc.json new file mode 100644 index 0000000000..445bbd1589 --- /dev/null +++ b/internal/endtoend/testdata/unsigned_params/mysql/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "mysql", + "name": "querytest", + "schema": "query.sql", + "queries": "query.sql" + } + ] +}