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

Add a mark to finish query #11

Open
robert-zaremba opened this issue Feb 25, 2016 · 6 comments
Open

Add a mark to finish query #11

robert-zaremba opened this issue Feb 25, 2016 · 6 comments

Comments

@robert-zaremba
Copy link

Let's say we use comments to group sql queries

Example

-- file user.sql

--- UPDATE QUERIES ---

--name: EmailUpdate
UPDATE users SET email = $1 where user_id = $2

--name: LevelUpdate
UPDATE users SET level = $1 where user_id = $2

---  REPORTS ---

...

In current implementation --- REPORTS--- comment belongs to LevelUpdate query. Problem is when LevelUpdate is not complete and we update the query on the program side. Let's imagine t hat we have the following:

--name: LevelUpdate
UPDATE users SET level = $1 where user_id IN

and in the application:

q := queries.LevelUpdate + fmt.Sprintf(" (%s)", strings.Join(userIDs, ","))

This will fail: ERROR: syntax error at end of input (SQLSTATE 42601) - because queries.LevelUpdate is finishing with a comment. I know that we can bind here the sqlx solution, however this is just a simple example.

We need a phrase to end the query, eg: --end
@qustavo
Copy link
Owner

qustavo commented Feb 25, 2016

Good question, a simpler solution would be strip all the comments when parsing the file, so you don't have to write specific annotations.
Does that make sense to you?

@robert-zaremba
Copy link
Author

Yes, this is a good idea.

@hxzhao527
Copy link
Contributor

hxzhao527 commented Oct 20, 2018

emmmm, is there a risk of sql-injection?

I know that we can bind here the sqlx solution,

sqlx.In maybe better.

@vagra
Copy link

vagra commented Mar 11, 2023

i have many sql in dot.sql, i want using comment to splite these lines, but i can't using ---------------- or /**************/

@vagra
Copy link

vagra commented Mar 11, 2023

comment must start as -- name: now. example:

-- name: ----------------------------------------
-- this is general sql comments
--------------------------------------------------

-- name: -------- update sql for files ----------

@vagra
Copy link

vagra commented Mar 11, 2023

refer to my current dot.sql , it’s a bit embarrassing to write comments like this, I hope it can be improved.

https://github.com/vagra/botools/blob/c6ab0c0a5e4ccba302caf261100cf9cc890cf6f4/dot.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants