"""
-import datetime, decimal, inspect, re, sys
+import datetime, inspect, re, sys
from sqlalchemy import schema as sa_schema
from sqlalchemy import exc, log, sql, util
super(_FloatType, self).__init__(precision=precision, asdecimal=asdecimal, **kw)
self.scale = scale
-class _DecimalType(_NumericType):
- def bind_processor(self, dialect):
- return None
-
- def result_processor(self, dialect):
- # TODO: this behavior might by MySQLdb specific,
- # i.e. that Decimals are returned by the DBAPI
- if not self.asdecimal:
- def process(value):
- if isinstance(value, decimal.Decimal):
- return float(value)
- else:
- return value
- return process
- else:
- return None
-
class _IntegerType(_NumericType, sqltypes.Integer):
def __init__(self, display_width=None, **kw):
self.display_width = display_width
return util.buffer(value)
return process
-class NUMERIC(_DecimalType, sqltypes.NUMERIC):
+class NUMERIC(_NumericType, sqltypes.NUMERIC):
"""MySQL NUMERIC type."""
__visit_name__ = 'NUMERIC'
super(NUMERIC, self).__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
-class DECIMAL(_DecimalType, sqltypes.DECIMAL):
+class DECIMAL(_NumericType, sqltypes.DECIMAL):
"""MySQL DECIMAL type."""
__visit_name__ = 'DECIMAL'
create_engine('mysql:///mydb?charset=utf8&use_unicode=0')
"""
-from sqlalchemy.dialects.mysql.base import MySQLDialect, MySQLExecutionContext, MySQLCompiler
+import decimal
+import re
+
+from sqlalchemy.dialects.mysql.base import (DECIMAL, MySQLDialect, MySQLExecutionContext,
+ MySQLCompiler, NUMERIC, _NumericType)
from sqlalchemy.engine import base as engine_base, default
from sqlalchemy.sql import operators as sql_operators
-
-from sqlalchemy import exc, log, schema, sql, util
-import re
+from sqlalchemy import exc, log, schema, sql, types as sqltypes, util
class MySQL_mysqldbExecutionContext(MySQLExecutionContext):
def _lastrowid(self, cursor):
def post_process_text(self, text):
return text.replace('%', '%%')
-
+
+
+class _DecimalType(_NumericType):
+ def result_processor(self, dialect):
+ if self.asdecimal:
+ return
+ def process(value):
+ if isinstance(value, decimal.Decimal):
+ return float(value)
+ else:
+ return value
+ return process
+
+
+class _MySQLdbNumeric(_DecimalType, NUMERIC):
+ pass
+
+
+class _MySQLdbDecimal(_DecimalType, DECIMAL):
+ pass
+
+
class MySQL_mysqldb(MySQLDialect):
driver = 'mysqldb'
supports_unicode_statements = False
default_paramstyle = 'format'
execution_ctx_cls = MySQL_mysqldbExecutionContext
statement_compiler = MySQL_mysqldbCompiler
+
+ colspecs = util.update_copy(
+ MySQLDialect.colspecs,
+ {
+ sqltypes.Numeric: _MySQLdbNumeric,
+ DECIMAL: _MySQLdbDecimal
+ }
+ )
@classmethod
def dbapi(cls):
+"""Support for the MySQL database via Jython's zxjdbc JDBC connector.
+
+JDBC Driver
+-----------
+
+The official MySQL JDBC driver is at
+http://dev.mysql.com/downloads/connector/j/.
+
+"""
+import decimal
import re
-from sqlalchemy.dialects.mysql.base import MySQLDialect, MySQLExecutionContext
+from sqlalchemy.dialects.mysql.base import BIT, MySQLDialect, MySQLExecutionContext
from sqlalchemy.connectors.zxJDBC import ZxJDBCConnector
from sqlalchemy import types as sqltypes, util
cursor.close()
return lastrowid
-jdbc_colspecs = MySQLDialect.colspecs.copy()
-# Time's conversion not applicable
-jdbc_colspecs.pop(sqltypes.Time)
+
+class _JDBCBit(BIT):
+ def result_processor(self, dialect):
+ """Converts boolean or byte arrays from MySQL Connector/J to longs."""
+ def process(value):
+ if value is None:
+ return value
+ if isinstance(value, bool):
+ return int(value)
+ v = 0L
+ for i in value:
+ v = v << 8 | (i & 0xff)
+ value = v
+ return value
+ return process
+
class MySQL_jdbc(ZxJDBCConnector, MySQLDialect):
execution_ctx_cls = MySQL_jdbcExecutionContext
jdbc_db_name = 'mysql'
- jdbc_driver_name = "org.gjt.mm.mysql.Driver"
+ jdbc_driver_name = "com.mysql.jdbc.Driver"
- colspecs = jdbc_colspecs
+ colspecs = util.update_copy(
+ MySQLDialect.colspecs,
+ {
+ sqltypes.Time: sqltypes.Time,
+ BIT: _JDBCBit
+ }
+ )
def _detect_charset(self, connection):
"""Sniff out the character set in use for connection results."""