from sqlalchemy.sql.elements import quoted_name
from sqlalchemy import types as sqltypes, schema as sa_schema
from sqlalchemy.types import VARCHAR, NVARCHAR, CHAR, \
- BLOB, CLOB, TIMESTAMP, FLOAT
+ BLOB, CLOB, TIMESTAMP, FLOAT, INTEGER
from itertools import groupby
RESERVED_WORDS = \
comment = row[7]
if coltype == 'NUMBER':
- coltype = NUMBER(precision, scale)
+ if precision is None and scale == 0:
+ coltype = INTEGER()
+ else:
+ coltype = NUMBER(precision, scale)
elif coltype in ('VARCHAR2', 'NVARCHAR2', 'CHAR'):
coltype = self.ischema_names.get(coltype)(length)
elif 'WITH TIME ZONE' in coltype:
# coding: utf-8
-from sqlalchemy.testing import eq_
+from sqlalchemy.testing import eq_, is_
from sqlalchemy import exc
from sqlalchemy.sql import table
from sqlalchemy.testing import fixtures, AssertsCompiledSQL
literal_column, VARCHAR, create_engine, Date, NVARCHAR, \
ForeignKeyConstraint, Sequence, Float, DateTime, cast, UnicodeText, \
union, except_, type_coerce, or_, outerjoin, DATE, NCHAR, outparam, \
- PrimaryKeyConstraint, FLOAT
+ PrimaryKeyConstraint, FLOAT, INTEGER
+from sqlalchemy.dialects.oracle.base import NUMBER
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing.engines import testing_engine
from sqlalchemy.testing.schema import Table, Column
eq_(list(t.primary_key), [t.c.id])
+class TypeReflectionTest(fixtures.TestBase):
+ __only_on__ = 'oracle'
+ __backend__ = True
+
+ @testing.provide_metadata
+ def _run_test(self, specs, attributes):
+ columns = [Column('c%i' % (i + 1), t[0]) for i, t in enumerate(specs)]
+ m = self.metadata
+ Table('oracle_types', m, *columns)
+ m.create_all()
+ m2 = MetaData(testing.db)
+ table = Table('oracle_types', m2, autoload=True)
+ for i, (reflected_col, spec) in enumerate(zip(table.c, specs)):
+ expected_spec = spec[1]
+ reflected_type = reflected_col.type
+ is_(type(reflected_type), type(expected_spec))
+ for attr in attributes:
+ eq_(
+ getattr(reflected_type, attr),
+ getattr(expected_spec, attr),
+ "Column %s: Attribute %s value of %s does not "
+ "match %s for type %s" % (
+ "c%i" % (i + 1),
+ attr,
+ getattr(reflected_type, attr),
+ getattr(expected_spec, attr),
+ spec[0]
+ )
+ )
+
+ def test_integer_types(self):
+ specs = [
+ (Integer, INTEGER(),),
+ (Numeric, INTEGER(),),
+ ]
+ self._run_test(specs, [])
+
+ def test_number_types(self):
+ specs = [
+ (Numeric(5, 2), NUMBER(5, 2),),
+ (NUMBER, NUMBER(),),
+ ]
+ self._run_test(specs, ['precision', 'scale'])