Hi all,

Another patch; MySQL doesn't currently support correlated subqueries in FROM clauses. This improves the error message you get in that situation. (I didn't actually want or need a correlated subquery, but I also spent quite some considerable time trying to work out what was going on because MySQL threw a syntax error rather than explaining that it didn't like correlated subqueries in the FROM part of a SELECT.)

(Note: I have assumed that it's only possible to reach this code with a subquery in the FROM clause or the WHERE clause... if it's also possible to get here with a scalar or row subquery, then this code isn't quite right.)

Kind regards,

Alastair.

Index: lib/sqlalchemy/sql.py
===================================================================
--- lib/sqlalchemy/sql.py       (revision 926)
+++ lib/sqlalchemy/sql.py       (working copy)
@@ -1246,6 +1246,8 @@
                 return
             select.is_where = self.is_where
             select.issubquery = True
+ if not (self.is_where or select.engine.can_correlate_froms): + raise "The selected engine does not support correlated subqueries in the FROM clause. If it was not your intention to perform a correlated subquery, you may be missing a table alias from one of your mappers."
             if getattr(select, '_correlated', None) is None:
                 select._correlated = self.select._froms
Index: lib/sqlalchemy/databases/mysql.py
===================================================================
--- lib/sqlalchemy/databases/mysql.py   (revision 926)
+++ lib/sqlalchemy/databases/mysql.py   (working copy)
@@ -111,6 +111,7 @@
             self.module = mysql
         self.opts = opts or {}
         ansisql.ANSISQLEngine.__init__(self, **params)
+        self.can_correlate_froms = False
     def connect_args(self):
         return [[], self.opts]
Index: lib/sqlalchemy/engine.py
===================================================================
--- lib/sqlalchemy/engine.py    (revision 926)
+++ lib/sqlalchemy/engine.py    (working copy)
@@ -183,6 +183,7 @@
         self.echo_uow = echo_uow
         self.context = util.ThreadLocal(raiseerror=False)
         self.tables = {}
+        self.can_correlate_froms = True
         self._ischema = None
         self._figure_paramstyle()
         if logger is None:


--
http://www.alastairs-place.net




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to