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

copyfrom does not respect table name casing #3633

Open
loissascha opened this issue Oct 5, 2024 · 0 comments
Open

copyfrom does not respect table name casing #3633

loissascha opened this issue Oct 5, 2024 · 0 comments
Labels

Comments

@loissascha
Copy link

Version

1.27.0

What happened?

I've defined a new query like this:

-- name: BulkInsertAnalyseResult :copyfrom
INSERT INTO AnalyseResults (Id, StoreId, ProductId, AmountDelivery, AmountRemission, AmountBel, AmountGsr, AmountDifference) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?);

and when I create the go code with sqlc generate this is what I get:

func (q *Queries) BulkInsertAnalyseResult(ctx context.Context, arg []BulkInsertAnalyseResultParams) (int64, error) {
	pr, pw := io.Pipe()
	defer pr.Close()
	rh := fmt.Sprintf("BulkInsertAnalyseResult_%d", atomic.AddUint32(&readerHandlerSequenceForBulkInsertAnalyseResult, 1))
	mysql.RegisterReaderHandler(rh, func() io.Reader { return pr })
	defer mysql.DeregisterReaderHandler(rh)
	go convertRowsForBulkInsertAnalyseResult(pw, arg)
	// The string interpolation is necessary because LOAD DATA INFILE requires
	// the file name to be given as a literal string.
	result, err := q.db.ExecContext(ctx, fmt.Sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE `analyseresults` %s (id, storeid, productid, amountdelivery, amountremission, amountbel, amountgsr, amountdifference)", "Reader::"+rh, mysqltsv.Escaping))
	if err != nil {
		return 0, err
	}
	return result.RowsAffected()
}

When I run this code, I get an error telling me that the table "analyseresults" does not exist. However when I change it to "AnalyseResults" it works. I believe it should respect the casing I've defined in the original query.

Relevant log output

ERROR: Error 1146 (42S02): Table 'piaNetTest.analyseresults' doesn't exist

Database schema

CREATE TABLE `AnalyseResults` (
  `Id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `StoreId` int(11) NOT NULL,
  `ProductId` int(11) NOT NULL,
  `AmountDelivery` int(11) NOT NULL,
  `AmountRemission` int(11) NOT NULL,
  `AmountBel` int(11) NOT NULL,
  `AmountGsr` int(11) NOT NULL,
  `AmountDifference` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

SQL queries

-- name: BulkInsertAnalyseResult :copyfrom
INSERT INTO AnalyseResults (Id, StoreId, ProductId, AmountDelivery, AmountRemission, AmountBel, AmountGsr, AmountDifference) 
VALUES (?, ?, ?, ?, ?, ?, ?, ?);

Configuration

version: "2"
sql:
  - engine: "mysql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "piadb"
        sql_package: "database/sql"
        sql_driver: "github.com/go-sql-driver/mysql"
        out: "piadb"

Playground URL

https://play.sqlc.dev/p/464af3d350ad8039e9e1da6ab6fdc64b958cf6b8ed510f560d9932602e47aa8d

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

@loissascha loissascha added the bug Something isn't working label Oct 5, 2024
@loissascha loissascha changed the title MySql :copyfrom does not respect table name casing copyfrom does not respect table name casing Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant