YEAR,
)
-Types which are specific to MySQL, or have MySQL-specific
+In addition to the above types, MariaDB also supports the following::
+
+ from sqlalchemy.dialects.mysql import (
+ INET4,
+ INET6,
+ )
+
+Types which are specific to MySQL or MariaDB, or have specific
construction arguments, are as follows:
.. note: where :noindex: is used, indicates a type that is not redefined
:members: __init__
+.. autoclass:: INET4
+
+.. autoclass:: INET6
+
.. autoclass:: INTEGER
:members: __init__
# mypy: ignore-errors
from .base import MariaDBIdentifierPreparer
from .base import MySQLDialect
+from .base import MySQLTypeCompiler
from ... import util
+from ...sql import sqltypes
from ...sql.sqltypes import UUID
from ...sql.sqltypes import Uuid
+class INET4(sqltypes.TypeEngine[str]):
+ """INET4 column type for MariaDB
+
+ .. versionadded:: 2.0.37
+ """
+
+ __visit_name__ = "INET4"
+
+
+class INET6(sqltypes.TypeEngine[str]):
+ """INET6 column type for MariaDB
+
+ .. versionadded:: 2.0.37
+ """
+
+ __visit_name__ = "INET6"
+
+
class _MariaDBUUID(UUID):
def __init__(self, as_uuid: bool = True, native_uuid: bool = True):
self.as_uuid = as_uuid
return None
+class MariaDBTypeCompiler(MySQLTypeCompiler):
+ def visit_INET4(self, type_, **kwargs) -> str:
+ return "INET4"
+
+ def visit_INET6(self, type_, **kwargs) -> str:
+ return "INET6"
+
+
class MariaDBDialect(MySQLDialect):
is_mariadb = True
supports_statement_cache = True
name = "mariadb"
preparer = MariaDBIdentifierPreparer
+ type_compiler_cls = MariaDBTypeCompiler
colspecs = util.update_copy(MySQLDialect.colspecs, {Uuid: _MariaDBUUID})
from sqlalchemy import types as sqltypes
from sqlalchemy import UnicodeText
from sqlalchemy.dialects.mysql import base as mysql
-from sqlalchemy.dialects.mysql.mariadb import MariaDBDialect
+from sqlalchemy.dialects.mysql import mariadb
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
def test_compile_upper(self):
self.assert_compile(sqltypes.UUID(), "UUID")
+
+class UUIDTest(fixtures.TestBase, AssertsCompiledSQL):
@testing.combinations(
(sqltypes.Uuid(), (10, 6, 5), "CHAR(32)"),
(sqltypes.Uuid(native_uuid=False), (10, 6, 5), "CHAR(32)"),
(sqltypes.UUID(), (10, 7, 0), "UUID"),
)
def test_mariadb_uuid_combinations(self, type_, version, res):
- dialect = MariaDBDialect()
+ dialect = mariadb.MariaDBDialect()
dialect.server_version_info = version
dialect.supports_native_uuid = version >= (10, 7)
self.assert_compile(type_, res, dialect=dialect)
self.assert_compile(type_, "CHAR(32)", dialect=dialect)
+class INETMariadbTest(fixtures.TestBase, AssertsCompiledSQL):
+ __dialect__ = mariadb.MariaDBDialect()
+
+ @testing.combinations(
+ (mariadb.INET4(), "INET4"),
+ (mariadb.INET6(), "INET6"),
+ )
+ def test_mariadb_inet6(self, type_, res):
+ self.assert_compile(type_, res)
+
+
class TypeRoundTripTest(fixtures.TestBase, AssertsExecutionResults):
__dialect__ = mysql.dialect()
__only_on__ = "mysql", "mariadb"