diff --git a/internal/endtoend/testdata/mysql_concat_type/mysql/db.go b/internal/endtoend/testdata/mysql_concat_type/mysql/db.go new file mode 100644 index 0000000000..5770e0177f --- /dev/null +++ b/internal/endtoend/testdata/mysql_concat_type/mysql/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package mysql_concat_type + +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/mysql_concat_type/mysql/models.go b/internal/endtoend/testdata/mysql_concat_type/mysql/models.go new file mode 100644 index 0000000000..653cf4cecf --- /dev/null +++ b/internal/endtoend/testdata/mysql_concat_type/mysql/models.go @@ -0,0 +1,16 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package mysql_concat_type + +import ( + "time" +) + +type Ticket struct { + ID int64 + TicketStatus int8 + Title string + CreatedAt time.Time +} diff --git a/internal/endtoend/testdata/mysql_concat_type/mysql/query.sql.go b/internal/endtoend/testdata/mysql_concat_type/mysql/query.sql.go new file mode 100644 index 0000000000..ea0ca77c90 --- /dev/null +++ b/internal/endtoend/testdata/mysql_concat_type/mysql/query.sql.go @@ -0,0 +1,69 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package mysql_concat_type + +import ( + "context" + "database/sql" + "time" +) + +const getTickets = `-- name: GetTickets :many +SELECT + id, + title, + ticket_status, + created_at +FROM ticket +WHERE (? IS NULL OR created_at >= ?) + AND (? IS NULL OR title LIKE CONCAT(?, '%')) +ORDER BY id ASC +` + +type GetTicketsParams struct { + StartTime sql.NullTime + TitlePrefix sql.NullString +} + +type GetTicketsRow struct { + ID int64 + Title string + TicketStatus int8 + CreatedAt time.Time +} + +func (q *Queries) GetTickets(ctx context.Context, arg GetTicketsParams) ([]GetTicketsRow, error) { + rows, err := q.db.QueryContext(ctx, getTickets, + arg.StartTime, + arg.StartTime, + arg.TitlePrefix, + arg.TitlePrefix, + ) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetTicketsRow + for rows.Next() { + var i GetTicketsRow + if err := rows.Scan( + &i.ID, + &i.Title, + &i.TicketStatus, + &i.CreatedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/endtoend/testdata/mysql_concat_type/query.sql b/internal/endtoend/testdata/mysql_concat_type/query.sql new file mode 100644 index 0000000000..55467188cb --- /dev/null +++ b/internal/endtoend/testdata/mysql_concat_type/query.sql @@ -0,0 +1,10 @@ +-- name: GetTickets :many +SELECT + id, + title, + ticket_status, + created_at +FROM ticket +WHERE (sqlc.narg(start_time) IS NULL OR created_at >= sqlc.narg(start_time)) + AND (sqlc.narg(title_prefix) IS NULL OR title LIKE CONCAT(sqlc.narg(title_prefix), '%')) +ORDER BY id ASC; diff --git a/internal/endtoend/testdata/mysql_concat_type/schema.sql b/internal/endtoend/testdata/mysql_concat_type/schema.sql new file mode 100644 index 0000000000..a5d4a8de59 --- /dev/null +++ b/internal/endtoend/testdata/mysql_concat_type/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE ticket +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + ticket_status TINYINT NOT NULL, + title VARCHAR(255) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/internal/endtoend/testdata/mysql_concat_type/sqlc.json b/internal/endtoend/testdata/mysql_concat_type/sqlc.json new file mode 100644 index 0000000000..07f953c248 --- /dev/null +++ b/internal/endtoend/testdata/mysql_concat_type/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "2", + "sql": [ + { + "engine": "mysql", + "queries": "query.sql", + "schema": "schema.sql", + "gen": { + "go": { + "package": "mysql_concat_type", + "out": "mysql" + } + } + } + ] +} diff --git a/internal/engine/dolphin/stdlib.go b/internal/engine/dolphin/stdlib.go index 46ce500eb5..aa6dc30ad9 100644 --- a/internal/engine/dolphin/stdlib.go +++ b/internal/engine/dolphin/stdlib.go @@ -415,10 +415,10 @@ func defaultSchema(name string) *catalog.Schema { Name: "CONCAT", Args: []*catalog.Argument{ { - Type: &ast.TypeName{Name: "any"}, + Type: &ast.TypeName{Name: "text"}, }, { - Type: &ast.TypeName{Name: "any"}, + Type: &ast.TypeName{Name: "text"}, Mode: ast.FuncParamVariadic, }, },