summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2017-02-01 18:13:06 -0500
committerGerrit Code Review <gerrit@awstats.zzzcomputing.com>2017-02-01 18:13:06 -0500
commitd71f4b47186972c5248c94ee2d04364da95a0965 (patch)
tree5f558d187ad8f8c587077092699c823909067983 /lib/sqlalchemy
parent8342ca6c6932b8a30f4ea9650721244eeda35d51 (diff)
parent388d8db68d0db6f38e72d60386023c9eef263034 (diff)
downloadsqlalchemy-d71f4b47186972c5248c94ee2d04364da95a0965.tar.gz
Merge "Accept FetchedValue, text() for column "default" value"
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/engine/reflection.py34
-rw-r--r--lib/sqlalchemy/events.py24
2 files changed, 40 insertions, 18 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index bd250131d..dfa81f4ca 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -340,20 +340,17 @@ class Inspector(object):
Given a string `table_name` and an optional string `schema`, return
column information as a list of dicts with these keys:
- name
- the column's name
+ * ``name`` - the column's name
- type
+ * ``type`` - the type of this column; an instance of
:class:`~sqlalchemy.types.TypeEngine`
- nullable
- boolean
+ * ``nullable`` - boolean flag if the column is NULL or NOT NULL
- default
- the column's default value
+ * ``default`` - the column's server default value - this is returned
+ as a string SQL expression.
- attrs
- dict containing optional column attributes
+ * ``attrs`` - dict containing optional column attributes
:param table_name: string name of the table. For special quoting,
use :class:`.quoted_name`.
@@ -362,6 +359,9 @@ class Inspector(object):
of the database connection. For special quoting,
use :class:`.quoted_name`.
+ :return: list of dictionaries, each representing the definition of
+ a database column.
+
"""
col_defs = self.dialect.get_columns(self.bind, table_name, schema,
@@ -649,14 +649,14 @@ class Inspector(object):
colargs = []
if col_d.get('default') is not None:
- # the "default" value is assumed to be a literal SQL
- # expression, so is wrapped in text() so that no quoting
- # occurs on re-issuance.
- colargs.append(
- sa_schema.DefaultClause(
- sql.text(col_d['default']), _reflected=True
- )
- )
+ default = col_d['default']
+ if isinstance(default, sql.elements.TextClause):
+ default = sa_schema.DefaultClause(default, _reflected=True)
+ elif not isinstance(default, sa_schema.FetchedValue):
+ default = sa_schema.DefaultClause(
+ sql.text(col_d['default']), _reflected=True)
+
+ colargs.append(default)
if 'sequence' in col_d:
self._reflect_col_sequence(col_d, colargs)
diff --git a/lib/sqlalchemy/events.py b/lib/sqlalchemy/events.py
index 2ed44f5dd..7aa30015c 100644
--- a/lib/sqlalchemy/events.py
+++ b/lib/sqlalchemy/events.py
@@ -178,7 +178,29 @@ class DDLEvents(event.Events):
The dictionary of column information as returned by the
dialect is passed, and can be modified. The dictionary
is that returned in each element of the list returned
- by :meth:`.reflection.Inspector.get_columns`.
+ by :meth:`.reflection.Inspector.get_columns`:
+
+ * ``name`` - the column's name
+
+ * ``type`` - the type of this column, which should be an instance
+ of :class:`~sqlalchemy.types.TypeEngine`
+
+ * ``nullable`` - boolean flag if the column is NULL or NOT NULL
+
+ * ``default`` - the column's server default value. This is
+ normally specified as a plain string SQL expression, however the
+ event can pass a :class:`.FetchedValue`, :class:`.DefaultClause`,
+ or :func:`.sql.expression.text` object as well.
+
+ .. versionchanged:: 1.1.6
+
+ The :meth:`.DDLEvents.column_reflect` event allows a non
+ string :class:`.FetchedValue`,
+ :func:`.sql.expression.text`, or derived object to be
+ specified as the value of ``default`` in the column
+ dictionary.
+
+ * ``attrs`` - dict containing optional column attributes
The event is called before any action is taken against
this dictionary, and the contents can be modified.