- New dialects: oursql, a new native dialect,
MySQL Connector/Python, a native Python port of MySQLdb,
and of course zxjdbc on Jython.
+
+ - VARCHAR/NVARCHAR will not render without a length, raises
+ an error before passing to MySQL. Doesn't impact
+ CAST since VARCHAR is not allowed in MySQL CAST anyway,
+ the dialect renders CHAR/NCHAR in those cases.
- all the _detect_XXX() functions now run once underneath
dialect.initialize()
if type_.length:
return self._extend_string(type_, {}, "VARCHAR(%d)" % type_.length)
else:
- return self._extend_string(type_, {}, "VARCHAR")
+ raise exc.InvalidRequestError("VARCHAR requires a length when rendered on MySQL")
def visit_CHAR(self, type_):
- return self._extend_string(type_, {'national':True}, "CHAR(%(length)s)" % {'length' : type_.length})
-
+ if type_.length:
+ return self._extend_string(type_, {}, "CHAR(%(length)s)" % {'length' : type_.length})
+ else:
+ return self._extend_string(type_, {}, "CHAR")
+
def visit_NVARCHAR(self, type_):
# We'll actually generate the equiv. "NATIONAL VARCHAR" instead
# of "NVARCHAR".
- return self._extend_string(type_, {'national':True}, "VARCHAR(%(length)s)" % {'length': type_.length})
+ if type_.length:
+ return self._extend_string(type_, {'national':True}, "VARCHAR(%(length)s)" % {'length': type_.length})
+ else:
+ raise exc.InvalidRequestError("NVARCHAR requires a length when rendered on MySQL")
def visit_NCHAR(self, type_):
# We'll actually generate the equiv. "NATIONAL CHAR" instead of "NCHAR".
- return self._extend_string(type_, {'national':True}, "CHAR(%(length)s)" % {'length': type_.length})
+ if type_.length:
+ return self._extend_string(type_, {'national':True}, "CHAR(%(length)s)" % {'length': type_.length})
+ else:
+ return self._extend_string(type_, {'national':True}, "CHAR")
def visit_VARBINARY(self, type_):
if type_.length:
# end Py2K
from sqlalchemy import *
-from sqlalchemy import sql, exc, schema
+from sqlalchemy import sql, exc, schema, types as sqltypes
from sqlalchemy.dialects.mysql import base as mysql
from sqlalchemy.test.testing import eq_
from sqlalchemy.test import *
select([t]).offset(10),
"SELECT t.col1, t.col2 FROM t LIMIT 10, 18446744073709551615"
)
-
+
+ def test_varchar_raise(self):
+ for type_ in (
+ String,
+ VARCHAR,
+ String(),
+ VARCHAR(),
+ NVARCHAR(),
+ Unicode,
+ Unicode(),
+ ):
+ type_ = sqltypes.to_instance(type_)
+ assert_raises(exc.InvalidRequestError, type_.compile, dialect=mysql.dialect())
+
def test_update_limit(self):
t = sql.table('t', sql.column('col1'), sql.column('col2'))
(DATE, "DATE"),
(TIME, "TIME"),
(CLOB, "CLOB"),
- (VARCHAR, "VARCHAR"),
- (NVARCHAR, ("NVARCHAR", "NATIONAL VARCHAR")),
+ (VARCHAR(10), "VARCHAR(10)"),
+ (NVARCHAR(10), ("NVARCHAR(10)", "NATIONAL VARCHAR(10)", "NVARCHAR2(10)")),
(CHAR, "CHAR"),
(NCHAR, ("NCHAR", "NATIONAL CHAR")),
(BLOB, "BLOB"),
if isinstance(expected, str):
expected = (expected, )
for exp in expected:
- compiled = type_().compile(dialect=dialect)
+ compiled = types.to_instance(type_).compile(dialect=dialect)
if exp in compiled:
break
else: