jmoiron / sqlx

general purpose extensions to golang's database/sql
http://jmoiron.github.io/sqlx/
MIT License
16.3k stars 1.09k forks source link

NamedQuery processes parameter names within comment blocks. #894

Open ocket8888 opened 1 year ago

ocket8888 commented 1 year ago

In my project, my files all need to have Apache-2.0 license headers if possible. This is done with a comment block. My SQL queries are in separate files and then embedded like

//go:embed select.sql
var selectQuery string

and then the select query file looks like

-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at

--  http://www.apache.org/licenses/LICENSE-2.0

-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

SELECT * FROM my_table

Notice the URL. If you try to run this with a NamedQuery, it'll tell you that it cannot find the parameter with the name "", because it's trying to replace the : from the license URL.

Comment blocks should not be processed for any kind of parameter replacement.