Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 393111

Summary: [DB] Oracle SQL doesn't allow "AS" keyword for table alias
Product: [Modeling] EMF Reporter: Eike Stepper <stepper>
Component: cdo.dbAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 CC: dzonekl
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
queryXRefs for 4.2 patch none

Description Eike Stepper CLA 2012-10-30 01:45:15 EDT
Cloned from: 392994: [DB] Oracle SQL doesn't allow "AS" keyword for table alias
https://bugs.eclipse.org/bugs/show_bug.cgi?id=392994

Created attachment 222910 [details]
Patch

When using CDOView.queryXRefs() with Oracle DB, an error occurs because oracle doesn't allow to use the "AS" keyword for table alias:
	ORA-00933: SQL command not properly ended

Since the "AS" keyword is optional for the table alias in other DB's, we could just remove it. I tested it with H2 DB and it works fine.
If there is some DB that requires the "AS" we would need to set it as vendor-specific through the adapter.

The following code would need to be changed in order to not use the "AS" keyword.
Additionally, I also detected that the alias identifier must be defined inside double.quotes.

org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractListTableMapping.queryXRefs(IDBStoreAccessor, String, String, QueryXRefsContext, String)

Attached patch with these changes in case we don't need to distinguish between different DB vendors.
Comment 1 Eike Stepper CLA 2012-10-30 02:04:31 EDT
commit dba1cf4ec4f47020d1354297b57ba2617729790c
Comment 2 Eike Stepper CLA 2012-10-31 10:32:46 EDT
Opps, crash recovery was broken in H2. 

commit b5dea0f67edbe7132dfa65081747f9d08b71ec5a
Comment 3 Eike Stepper CLA 2012-11-01 11:08:53 EDT
Offline replication throws SQLException.
Comment 4 Eike Stepper CLA 2012-11-01 11:09:23 EDT
Forgot to surround table aliases with double quotes in two places...
Comment 5 Eike Stepper CLA 2012-11-01 11:09:57 EDT
commit 07222369448a147404dee6321c4f01dc484b4762
Comment 6 Eike Stepper CLA 2012-11-16 02:57:40 EST
Reopening to remove the double quotes around alias names because they don't seem to be necessary for Oracle (according to users) but harm when using Mysql...
Comment 7 Eike Stepper CLA 2012-11-16 03:01:53 EST
commit 224519d27971545c15ad050aa8a1aee382e3c00b
Comment 8 Christophe Bouhier CLA 2012-11-16 06:20:21 EST
I think you forgot one,

With quotes, I get the exception below, undoing commit, will help, but the AS keyword could be a conflict between DB vendors. 

dba1cf4ec4f47020d1354297b57ba2617729790c
 


DBException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '.cdo_source, "l_t".cdo_value, "l_t".cdo_idx FROM library_Equipment_metricRefs_li' at line 1
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractListTableMapping.queryXRefs(AbstractListTableMapping.java:449)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalClassMapping.queryXRefs(AbstractHorizontalClassMapping.java:812)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalMappingStrategy.queryXRefs(AbstractHorizontalMappingStrategy.java:155)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalMappingStrategy.queryXRefs(HorizontalMappingStrategy.java:189)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.queryXRefs(DBStoreAccessor.java:309)
	at org.eclipse.emf.cdo.internal.server.XRefsQueryHandler.executeQuery(XRefsQueryHandler.java:66)
	at org.eclipse.emf.cdo.internal.server.QueryManager$QueryContext.run(QueryManager.java:294)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '.cdo_source, "l_t".cdo_value, "l_t".cdo_idx FROM library_Equipment_metricRefs_li' at line 1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1557)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractListTableMapping.queryXRefs(AbstractListTableMapping.java:421)
	... 12 more

	at org.eclipse.net4j.signal.RemoteExceptionIndication.indicating(RemoteExceptionIndication.java:60)
	at org.eclipse.net4j.signal.Indication.doExtendedInput(Indication.java:57)
	at org.eclipse.net4j.signal.Signal.doInput(Signal.java:328)
	at org.eclipse.net4j.signal.Indication.execute(Indication.java:51)
	at org.eclipse.net4j.signal.Signal.runSync(Signal.java:253)
	at org.eclipse.net4j.signal.Signal.run(Signal.java:149)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
Comment 9 Christophe Bouhier CLA 2012-11-16 06:24:31 EST
this is the full query: 
SELECT "l_t".cdo_source, "l_t".cdo_value, "l_t".cdo_idx FROM library_Equipment_metricRefs_list "l_t", library_Equipment "a_t" WHERE "a_t".cdo_revised=0 AND "a_t".cdo_id="l_t".cdo_source AND cdo_value IN (209)
Comment 10 Eike Stepper CLA 2012-11-16 06:28:33 EST
I've got no clue how you can get that. The code looks like this:

    StringBuilder builder = new StringBuilder();
    builder.append("SELECT l_t."); //$NON-NLS-1$

There are no double quotes anymore. The whole cdo.server.db contains no double quote literals anymore (except some HTML rendering in DBBrowserPage).
Comment 11 Christophe Bouhier CLA 2012-11-16 06:36:42 EST
Created attachment 223652 [details]
queryXRefs for 4.2 patch
Comment 12 Christophe Bouhier CLA 2012-11-16 06:38:16 EST
OK, this is because, I haven't update the plugin in my workspace, which I checked-out two days ago, apologies for that.
Comment 13 Christophe Bouhier CLA 2012-11-16 06:53:49 EST
You, one lesson here, is the product had shipped with the plugin before this patch, so the customer reported the problem, and I resolved it around a checked-out plugin which is the same as the customer. It just happens this fixed was committed in between, and before fixing it, I should really have done a git pull first.
Comment 14 Eike Stepper CLA 2013-06-27 03:32:56 EDT
Available in R20130613-1157 (4.2)