summaryrefslogtreecommitdiff
path: root/test/dialect/mysql/test_reflection.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/dialect/mysql/test_reflection.py')
-rw-r--r--test/dialect/mysql/test_reflection.py55
1 files changed, 52 insertions, 3 deletions
diff --git a/test/dialect/mysql/test_reflection.py b/test/dialect/mysql/test_reflection.py
index 99733e397..957a7eb21 100644
--- a/test/dialect/mysql/test_reflection.py
+++ b/test/dialect/mysql/test_reflection.py
@@ -7,6 +7,7 @@ from sqlalchemy.dialects.mysql import base as mysql
from sqlalchemy.testing import fixtures, AssertsExecutionResults
from sqlalchemy import testing
+
class ReflectionTest(fixtures.TestBase, AssertsExecutionResults):
__only_on__ = 'mysql'
@@ -23,13 +24,12 @@ class ReflectionTest(fixtures.TestBase, AssertsExecutionResults):
DefaultClause(''), nullable=False),
Column('c2', String(10), DefaultClause('0')),
Column('c3', String(10), DefaultClause('abc')),
- Column('c4', TIMESTAMP, DefaultClause('2009-04-05 12:00:00'
- )),
+ Column('c4', TIMESTAMP, DefaultClause('2009-04-05 12:00:00')),
Column('c5', TIMESTAMP),
Column('c6', TIMESTAMP,
DefaultClause(sql.text("CURRENT_TIMESTAMP "
"ON UPDATE CURRENT_TIMESTAMP"))),
- )
+ )
def_table.create()
try:
reflected = Table('mysql_def', MetaData(testing.db),
@@ -284,6 +284,55 @@ class ReflectionTest(fixtures.TestBase, AssertsExecutionResults):
self.assert_('TABLES' in view_names)
@testing.provide_metadata
+ def test_nullable_reflection(self):
+ """test reflection of NULL/NOT NULL, in particular with TIMESTAMP
+ defaults where MySQL is inconsistent in how it reports CREATE TABLE.
+
+ """
+ meta = self.metadata
+ Table('nn_t', meta)
+ testing.db.execute("""
+ CREATE TABLE nn_t (
+ x INTEGER NULL,
+ y INTEGER NOT NULL,
+ z INTEGER,
+ q TIMESTAMP NULL,
+ p TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
+ r TIMESTAMP NOT NULL,
+ s TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ t TIMESTAMP,
+ u TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+ )
+ """)
+ eq_(
+ [
+ {
+ "name": d['name'],
+ "nullable": d['nullable'],
+ "default": d['default'],
+ }
+ for d in
+ inspect(testing.db).get_columns('nn_t')
+ ],
+ [
+ {'name': 'x', 'nullable': True, 'default': None},
+ {'name': 'y', 'nullable': False, 'default': None},
+ {'name': 'z', 'nullable': True, 'default': None},
+ {'name': 'q', 'nullable': True, 'default': None},
+ {'name': 'p', 'nullable': True,
+ 'default': 'CURRENT_TIMESTAMP'},
+ {'name': 'r', 'nullable': False,
+ 'default': "'0000-00-00 00:00:00'"},
+ {'name': 's', 'nullable': False,
+ 'default': 'CURRENT_TIMESTAMP'},
+ {'name': 't', 'nullable': False,
+ 'default': "'0000-00-00 00:00:00'"},
+ {'name': 'u', 'nullable': False,
+ 'default': 'CURRENT_TIMESTAMP'},
+ ]
+ )
+
+ @testing.provide_metadata
def test_reflection_with_unique_constraint(self):
insp = inspect(testing.db)