summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-01-18 03:00:05 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-01-18 03:00:05 +0000
commit9680e6483f4a811e147dd75bf3f5ccab989f01e0 (patch)
tree55d13b9a50e139561b127cde18e57fc85fb3db82 /lib/sqlalchemy/dialects
parente9076d04b0ec82a403a885be7999eab7d346923b (diff)
downloadsqlalchemy-9680e6483f4a811e147dd75bf3f5ccab989f01e0.tar.gz
- added native INTERVAL type to the dialect. This supports
only the DAY TO SECOND interval type so far due to lack of support in cx_oracle for YEAR TO MONTH. [ticket:1467] - The Interval type includes a "native" flag which controls if native INTERVAL types (postgresql + oracle) are selected if available, or not. "day_precision" and "second_precision" arguments are also added which propagate as appropriately to these native types. Related to [ticket:1467]. - DefaultDialect.type_descriptor moves back to being per-dialect. TypeEngine/TypeDecorator key type impls to the dialect class + server_version_info so that the colspecs dict can be modified per-dialect based on server version. - Fixed TypeDecorator's incorrect usage of _impl_dict
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/oracle/__init__.py4
-rw-r--r--lib/sqlalchemy/dialects/oracle/base.py51
-rw-r--r--lib/sqlalchemy/dialects/oracle/cx_oracle.py8
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py4
4 files changed, 62 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/__init__.py b/lib/sqlalchemy/dialects/oracle/__init__.py
index 7b4d6aeab..eb47e80cb 100644
--- a/lib/sqlalchemy/dialects/oracle/__init__.py
+++ b/lib/sqlalchemy/dialects/oracle/__init__.py
@@ -5,11 +5,11 @@ base.dialect = cx_oracle.dialect
from sqlalchemy.dialects.oracle.base import \
VARCHAR, NVARCHAR, CHAR, DATE, DATETIME, NUMBER,\
BLOB, BFILE, CLOB, NCLOB, TIMESTAMP, RAW,\
- FLOAT, DOUBLE_PRECISION, LONG, dialect
+ FLOAT, DOUBLE_PRECISION, LONG, dialect, INTERVAL
__all__ = (
'VARCHAR', 'NVARCHAR', 'CHAR', 'DATE', 'DATETIME', 'NUMBER',
'BLOB', 'BFILE', 'CLOB', 'NCLOB', 'TIMESTAMP', 'RAW',
-'FLOAT', 'DOUBLE_PRECISION', 'LONG', 'dialect'
+'FLOAT', 'DOUBLE_PRECISION', 'LONG', 'dialect', 'INTERVAL'
)
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py
index b63953959..882505a40 100644
--- a/lib/sqlalchemy/dialects/oracle/base.py
+++ b/lib/sqlalchemy/dialects/oracle/base.py
@@ -162,6 +162,40 @@ class BFILE(sqltypes.Binary):
class LONG(sqltypes.Text):
__visit_name__ = 'LONG'
+
+class INTERVAL(sqltypes.TypeEngine):
+ __visit_name__ = 'INTERVAL'
+
+ def __init__(self,
+ day_precision=None,
+ second_precision=None):
+ """Construct an INTERVAL.
+
+ Note that only DAY TO SECOND intervals are currently supported.
+ This is due to a lack of support for YEAR TO MONTH intervals
+ within available DBAPIs (cx_oracle and zxjdbc).
+
+ :param day_precision: the day precision value. this is the number of digits
+ to store for the day field. Defaults to "2"
+ :param second_precision: the second precision value. this is the number of digits
+ to store for the fractional seconds field. Defaults to "6".
+
+ """
+ self.day_precision = day_precision
+ self.second_precision = second_precision
+
+ @classmethod
+ def _adapt_from_generic_interval(cls, interval):
+ return INTERVAL(day_precision=interval.day_precision,
+ second_precision=interval.second_precision)
+
+ def adapt(self, impltype):
+ return impltype(day_precision=self.day_precision,
+ second_precision=self.second_precision)
+
+ @property
+ def _type_affinity(self):
+ return sqltypes.Interval
class _OracleBoolean(sqltypes.Boolean):
def get_dbapi_type(self, dbapi):
@@ -169,6 +203,7 @@ class _OracleBoolean(sqltypes.Boolean):
colspecs = {
sqltypes.Boolean : _OracleBoolean,
+ sqltypes.Interval : INTERVAL,
}
ischema_names = {
@@ -204,7 +239,17 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler):
def visit_unicode(self, type_):
return self.visit_NVARCHAR(type_)
-
+
+ def visit_INTERVAL(self, type_):
+ return "INTERVAL DAY%s TO SECOND%s" % (
+ type_.day_precision is not None and
+ "(%d)" % type_.day_precision or
+ "",
+ type_.second_precision is not None and
+ "(%d)" % type_.second_precision or
+ "",
+ )
+
def visit_DOUBLE_PRECISION(self, type_):
return self._generate_numeric(type_, "DOUBLE PRECISION")
@@ -512,6 +557,10 @@ class OracleDialect(default.DefaultDialect):
self.implicit_returning = self.server_version_info > (10, ) and \
self.__dict__.get('implicit_returning', True)
+ if self.server_version_info < (9,):
+ self.colspecs = self.colspecs.copy()
+ self.colspecs.pop(sqltypes.Interval)
+
def do_release_savepoint(self, connection, name):
# Oracle does not support RELEASE SAVEPOINT
pass
diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
index 5a94efccb..6b1d7e5b9 100644
--- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py
+++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
@@ -167,15 +167,19 @@ class _OracleBinary(_LOBMixin, sqltypes.Binary):
def bind_processor(self, dialect):
return None
-
+class _OracleInterval(oracle.INTERVAL):
+ def get_dbapi_type(self, dbapi):
+ return dbapi.INTERVAL
+
class _OracleRaw(oracle.RAW):
pass
-
colspecs = {
sqltypes.Date : _OracleDate,
sqltypes.Binary : _OracleBinary,
sqltypes.Boolean : oracle._OracleBoolean,
+ sqltypes.Interval : _OracleInterval,
+ oracle.INTERVAL : _OracleInterval,
sqltypes.Text : _OracleText,
sqltypes.UnicodeText : _OracleUnicodeText,
sqltypes.CHAR : _OracleChar,
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 308e23bae..2c8f896e9 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -109,6 +109,10 @@ class INTERVAL(sqltypes.TypeEngine):
def adapt(self, impltype):
return impltype(self.precision)
+ @classmethod
+ def _adapt_from_generic_interval(cls, interval):
+ return INTERVAL(precision=interval.second_precision)
+
@property
def _type_affinity(self):
return sqltypes.Interval