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

Delete DSL with as got Syntax Error with MySQL #567

Open
wuranbo opened this issue Sep 24, 2016 · 5 comments
Open

Delete DSL with as got Syntax Error with MySQL #567

wuranbo opened this issue Sep 24, 2016 · 5 comments

Comments

@wuranbo
Copy link

wuranbo commented Sep 24, 2016

use DSL like this

delete.from(SavedSchedule as s).where.eq(s.ownerId, ids_str.toInt)

will generate the SQL

delete from SavedSchedule s where s.owner_id = 9;

got the ERROR:

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 's where s.owner_id = 9' at line 1

Is it a MySQL SQL compatible bug?

scalikejdbc: "org.scalikejdbc" %% "scalikejdbc" % "2.3.4",
MySQL: 5.5.47

@jeffbondlink
Copy link

This is an old and existing issue with mysql, delete does not support table
aliases, so unless the as s is important for some reason, just write them
as delete.from(SavedSchedule).where.eq(column.ownerId, ids_str.toInt). Not
the use of column, there may be other ways, but that will work.

On Sat, Sep 24, 2016 at 11:46 AM, Wu Ranbo notifications@github.com wrote:

use DSL like this

delete.from(SavedSchedule as s).where.eq(s.ownerId, ids_str.toInt)

will generate the SQL

delete from SavedSchedule s where s.owner_id = 9;

got the ERROR:

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 's where s.owner_id = 9' at line 1

Is it a MySQL SQL compatible bug?

scalikejdbc: "org.scalikejdbc" %% "scalikejdbc" % "2.3.4",
MySQL: 5.5.47


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#567, or mute the
thread
https://github.com/notifications/unsubscribe-auth/APdcMzdApUE3oMH8getpcUjSiNIigK2iks5qtUXjgaJpZM4KFrBL
.

@seratch
Copy link
Member

seratch commented Sep 25, 2016

Indeed, it's a little bit confusing but you need to use #column instead for insert/update/delete SQLs instead. http://scalikejdbc.org/documentation/query-dsl.html#delete

@wuranbo
Copy link
Author

wuranbo commented Sep 25, 2016

@jeffbondlink @seratch thanks.
Just it's kind of easy to write wrong code, and not being checked in compiling time superised me much.
Dose we got some thinking to improve it? I saw the source code QueryBuilder is splited to C.R.U.D already, then we can mixin the diffrent Database as trait (or else) to solve this? just chat chat. ^_^

@seratch
Copy link
Member

seratch commented Sep 26, 2016

Introducing some kind of "marked" SQLSyntax may improve type safety of the APIs but it would bring backward incompatibility. It might be considerable in 3.0 (no plan yet though)

@wuranbo
Copy link
Author

wuranbo commented Sep 26, 2016

@seratch got it. Thx.

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

No branches or pull requests

3 participants