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

Use """insert into ParserRule(name)""" instead of """insert into ParserRule(name)""" #571

Open
zhaohangbo opened this issue Oct 10, 2016 · 7 comments

Comments

@zhaohangbo
Copy link

image

I think it's a bug need to be fixed

By default it's like
 """
insert into ParserRule(
        name,
        conf
      ) values (
        {name},
        {conf}
      )
"""

But we should add the special comma to it
 """
insert into ParserRule(
        `name`,
        `conf`
      ) values (
        {name},
        {conf}
      )
"""
@seratch
Copy link
Member

seratch commented Oct 10, 2016

@zhaohangbo I've not figured out what your problem is. What can we do for you on scalikejdbc library side?

@wuranbo
Copy link

wuranbo commented Oct 11, 2016

@seratch desc is the keyword of SQL, this is the problem. So when we has a column name 'desc', the insert sql won't work.

    mysql> create table T(`desc` varchar(255) PRIMARY KEY)
    -> ;
   Query OK, 0 rows affected (0.02 sec)
   mysql> insert into T(desc) VALUES("s");
   ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that  corresponds to your MySQL server version for the right syntax to use near 'desc) VALUES("s")' at line 1

The solution is add ` in any column name in SQL.

@seratch
Copy link
Member

seratch commented Oct 11, 2016

@wuranbo If you're talking about QueryDSL feature, there is room for improvement. It's reasonable to enable to automatically enclose columns with backquotes.

But your above examples are simply SQL interpolation or SQL string value. In the case, you can freely use backquotes in your queries.

@wuranbo
Copy link

wuranbo commented Oct 11, 2016

@seratch Thanks for it, wish to see in 3.0.0.
Yes, I mean QueryDSL. The QueryDSL now will not enclose columns with backquotes. So the table T I show above, and @zhaohangbo shows code in our project, will not work with the QueryDSL now. So @zhaohangbo want to fix it by modify the reverse-engine generated code.

@zhaohangbo
Copy link
Author

zhaohangbo commented Oct 12, 2016

@seratch Thanks for your reply.

The batchInsert() and create() methods in the model, which generated by Reverse Engineering, have a bug needs to be fixed.

In the picture I uploaded above,
the auto-generated SQL by Reverse Engineering:
insert into ParserRule(name, desc) ...... will fail to execute,
because the column name desc is also a key word of MYSQL.

it should be insert into ParserRule(name, desc) ...... to avoid such failure
All the QueryDSL sentences in model generated by Reverse Engineering should add with backquote in case some special words occur in the sentences.

@tototoshi
Copy link
Member

I'm using QueryDSL and now in trouble with this problem.

It's reasonable to enable to automatically enclose columns with backquotes.

@seratch Do you have any plan to do this?

@seratch
Copy link
Member

seratch commented Jul 12, 2017

@tototoshi Frankly, I myself don't have enough time to work on the implementation right now. If someone properly does a code contribution for it, I'd love to merge it and will release new versions promptly.

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

No branches or pull requests

4 participants