summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-07-28 16:46:53 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-29 13:18:34 -0400
commitf582fd48b15ad6d2f57269bb1fbe6b8062f84d87 (patch)
treee794ddffb2bacd7d3d97bff5b12a9f7f4eaa5901 /lib/sqlalchemy/testing
parent9e1ee412b8650761af6df993e119906682604728 (diff)
downloadsqlalchemy-f582fd48b15ad6d2f57269bb1fbe6b8062f84d87.tar.gz
Consider default FROM DUAL for MySQL
MySQL claims it doesn't require FROM DUAL for no FROM clause even though the issue at #5481 locates a case which requires one. See if FROM DUAL the same way as Oracle without attempting to guess is potentially feasible. Fixes: #5481 Change-Id: I2a28876c10a8ce2d121cd344dcdd837db321d4ab
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py51
1 files changed, 50 insertions, 1 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py
index ad17ebb4a..9fb481676 100644
--- a/lib/sqlalchemy/testing/suite/test_select.py
+++ b/lib/sqlalchemy/testing/suite/test_select.py
@@ -1,6 +1,5 @@
import itertools
-from sqlalchemy import ForeignKey
from .. import AssertsCompiledSQL
from .. import AssertsExecutionResults
from .. import config
@@ -14,9 +13,12 @@ from ... import bindparam
from ... import case
from ... import column
from ... import Computed
+from ... import exists
from ... import false
+from ... import ForeignKey
from ... import func
from ... import Integer
+from ... import literal
from ... import literal_column
from ... import null
from ... import select
@@ -1018,6 +1020,53 @@ class ComputedColumnTest(fixtures.TablesTest):
eq_(res, [(100, 40), (1764, 168)])
+class ExistsTest(fixtures.TablesTest):
+ __backend__ = True
+
+ @classmethod
+ def define_tables(cls, metadata):
+ Table(
+ "stuff",
+ metadata,
+ Column("id", Integer, primary_key=True),
+ Column("data", String(50)),
+ )
+
+ @classmethod
+ def insert_data(cls, connection):
+ connection.execute(
+ cls.tables.stuff.insert(),
+ [
+ {"id": 1, "data": "some data"},
+ {"id": 2, "data": "some data"},
+ {"id": 3, "data": "some data"},
+ {"id": 4, "data": "some other data"},
+ ],
+ )
+
+ def test_select_exists(self, connection):
+ stuff = self.tables.stuff
+ eq_(
+ connection.execute(
+ select(literal(1)).where(
+ exists().where(stuff.c.data == "some data")
+ )
+ ).fetchall(),
+ [(1,)],
+ )
+
+ def test_select_exists_false(self, connection):
+ stuff = self.tables.stuff
+ eq_(
+ connection.execute(
+ select(literal(1)).where(
+ exists().where(stuff.c.data == "no data")
+ )
+ ).fetchall(),
+ [],
+ )
+
+
class DistinctOnTest(AssertsCompiledSQL, fixtures.TablesTest):
__backend__ = True
__requires__ = ("standard_cursor_sql",)