Hi!
> Try out the ischema_names thing for now.
Works like a charm - thanks a lot!
I know about manually overwriting column types (which works a sw ell of course), but I wanted to keep the application independent from the table structure (which is in a migrate repository)...
This looks very nice:
>
my_float = FLOAT(53).with_variant(postgresql.DOUBLE_PRECISION(), "postgresql").with_variant(OracleBinaryDouble, "oracle")
However, it doesn't work for me (v0.7.6), or am I doing something wrong? -
----<code>---------
# Imports
import sqlalchemy
import sqlalchemy.types
import sqlalchemy.orm
import sqlalchemy.dialects
# Define User customized type
class OracleBinaryDouble(sqlalchemy.types.UserDefinedType):
def get_col_spec(self):
return "BINARY_DOUBLE"
BinaryDouble = sqlalchemy.types.FLOAT(53).with_variant(OracleBinaryDouble, "oracle")
# Database connection
engine = sqlalchemy.create_engine("oracle://XXX:ppp@tcdbs2:1521/YYY")
conn = engine.connect()
metadata = sqlalchemy.MetaData()
# Define a table using the custom data type
table = sqlalchemy.Table('test_table', metadata, sqlalchemy.Column('double', BinaryDouble))
# Create and insert something
metadata.create_all(engine)
conn.execute(table.insert(), double = 5.0)
conn.close()
----</code>------------
which throws an error:
Traceback (most recent call last):
File "sqla_cust_types.py", line 30, in <module>
conn.execute(table.insert(), double = 5.0)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1450, in execute
params)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1583, in _execute_clauseelement
compiled_sql, distilled_params
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1650, in _execute_context
None, None)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1646, in _execute_context
context = constructor(dialect, self, conn, *args)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in _init_compiled
processors = compiled._bind_processors
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 485, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 287, in _bind_processors
for bindparam in self.bind_names )
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 284, in <genexpr>
(key, value) for key, value in
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 287, in <genexpr>
for bindparam in self.bind_names )
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/types.py", line 201, in _cached_bind_processor
d = self._dialect_info(dialect)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/types.py", line 226, in _dialect_info
impl = self._gen_dialect_impl(dialect)
File "/homespace/grasppf/linux/11.1/intel/lib/python2.7/site-packages/sqlalchemy/types.py", line 492, in _gen_dialect_impl
typedesc = self.load_dialect_impl(dialect).dialect_impl(dialect)
sqlalchemy.exc.StatementError: unbound method dialect_impl() must be called with OracleBinaryDouble instance as first argument (got OracleDialect_cx_oracle instance instead) (original cause: TypeError: unbound method dialect_impl() must be called with OracleBinaryDouble instance as first argument (got OracleDialect_cx_oracle instance instead)) 'INSERT INTO test_table (double) VALUES (:double)' [{'double': 5.0}]
Thanks again!
Christian.