Skip to content

last rune is truncated if query.sql doesn't end with ; (mysql) #1240

Closed
@Funzinator

Description

@Funzinator

Version

1.10.0

What happened?

Hi.

I just noticed a small issue when playing around with sqlc.
Using the example from the documentation (but forgetting the last ;)

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name

will result in code generated like this:

const listAuthors = `-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY nam
`

sqlc generate parses the file properly but resulting in wrong code. The easy fix is to add the ; back but maybe it's better to show an error during sqlc generate?

I've also tried this with the current main branch. Happens there as well.

PS: Only happens in mysql mode. Postgres mode is rejecting the query.sql.

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGINT  NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name text    NOT NULL,
  bio  text
);

SQL queries

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name

Configuration

version: 1
packages:
  - path: "tutorial"
    name: "tutorial"
    engine: "mysql"
    schema: "schema.sql"
    queries: "query.sql"
    emit_prepared_queries: true

Playground URL

https://play.sqlc.dev/p/a1d7202b8184fb6896ff9e6366363473b8bbc92549738764a4012b5021d8c19d

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNew issues that hasn't been reviewed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions