本文整理匯總了Python中sqlalchemy.util.warn方法的典型用法代碼示例。如果您正苦於以下問題:Python util.warn方法的具體用法?Python util.warn怎麽用?Python util.warn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.util
的用法示例。
在下文中一共展示了util.warn方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: define_constraint_cascades
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def define_constraint_cascades(self, constraint):
text = ""
if constraint.ondelete is not None:
text += " ON DELETE %s" % constraint.ondelete
# oracle has no ON UPDATE CASCADE -
# its only available via triggers
# http://asktom.oracle.com/tkyte/update_cascade/index.html
if constraint.onupdate is not None:
util.warn(
"Oracle does not contain native UPDATE CASCADE "
"functionality - onupdates will not be rendered for foreign "
"keys. Consider using deferrable=True, initially='deferred' "
"or triggers.")
return text
示例2: get_columns
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def get_columns(self, connection, table_name, schema=None, **kw):
table = self._get_table(connection, table_name, schema)
columns = self._get_columns_helper(table.schema, [])
result = []
for col in columns:
try:
coltype = _type_map[col.field_type]
except KeyError:
util.warn("Did not recognize type '%s' of column '%s'" % (col.field_type, col.name))
result.append({
'name': col.name,
'type': types.ARRAY(coltype) if col.mode == 'REPEATED' else coltype,
'nullable': col.mode == 'NULLABLE' or col.mode == 'REPEATED',
'default': None,
})
return result
示例3: _get_column_info
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def _get_column_info(self, name, type_, nullable, autoincrement, default,
precision, scale, length):
coltype = self.ischema_names.get(type_, None)
kwargs = {}
if coltype in (NUMERIC, DECIMAL):
args = (precision, scale)
elif coltype == FLOAT:
args = (precision,)
elif coltype in (CHAR, VARCHAR, UNICHAR, UNIVARCHAR, NCHAR, NVARCHAR):
args = (length,)
else:
args = ()
if coltype:
coltype = coltype(*args, **kwargs)
# is this necessary
# if is_array:
# coltype = ARRAY(coltype)
else:
util.warn("Did not recognize type '%s' of column '%s'" %
(type_, name))
coltype = sqltypes.NULLTYPE
if default:
default = re.sub("DEFAULT", "", default).strip()
default = re.sub("^'(.*)'$", lambda m: m.group(1), default)
else:
default = None
column_info = dict(name=name, type=coltype, nullable=nullable,
default=default, autoincrement=autoincrement)
return column_info
示例4: __init__
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def __init__(self, **kwargs):
SQLiteDialect.__init__(self, **kwargs)
if self.dbapi is not None:
sqlite_ver = self.dbapi.version_info
if sqlite_ver < (2, 1, 3):
util.warn(
("The installed version of pysqlite2 (%s) is out-dated "
"and will cause errors in some cases. Version 2.1.3 "
"or greater is recommended.") %
'.'.join([str(subver) for subver in sqlite_ver]))
示例5: _get_column_info
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def _get_column_info(self, name, type_, nullable, autoincrement, default,
precision, scale, length):
coltype = self.ischema_names.get(type_, None)
kwargs = {}
if coltype in (NUMERIC, DECIMAL):
args = (precision, scale)
elif coltype == FLOAT:
args = (precision,)
elif coltype in (CHAR, VARCHAR, UNICHAR, UNIVARCHAR, NCHAR, NVARCHAR):
args = (length,)
else:
args = ()
if coltype:
coltype = coltype(*args, **kwargs)
# is this necessary
# if is_array:
# coltype = ARRAY(coltype)
else:
util.warn("Did not recognize type '%s' of column '%s'" %
(type_, name))
coltype = sqltypes.NULLTYPE
if default:
default = default.replace("DEFAULT", "").strip()
default = re.sub("^'(.*)'$", lambda m: m.group(1), default)
else:
default = None
column_info = dict(name=name, type=coltype, nullable=nullable,
default=default, autoincrement=autoincrement)
return column_info
示例6: define_constraint_cascades
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def define_constraint_cascades(self, constraint):
text = ""
if constraint.ondelete is not None:
text += " ON DELETE %s" % constraint.ondelete
# oracle has no ON UPDATE CASCADE -
# its only available via triggers http://asktom.oracle.com/tkyte/update_cascade/index.html
if constraint.onupdate is not None:
util.warn(
"Oracle does not contain native UPDATE CASCADE "
"functionality - onupdates will not be rendered for foreign keys. "
"Consider using deferrable=True, initially='deferred' or triggers.")
return text
示例7: _get_column_info
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def _get_column_info(self, name, type_, nullable, autoincrement, default,
precision, scale, length):
coltype = self.ischema_names.get(type_, None)
kwargs = {}
if coltype in (NUMERIC, DECIMAL):
args = (precision, scale)
elif coltype == FLOAT:
args = (precision,)
elif coltype in (CHAR, VARCHAR, UNICHAR, UNIVARCHAR, NCHAR, NVARCHAR):
args = (length,)
else:
args = ()
if coltype:
coltype = coltype(*args, **kwargs)
#is this necessary
#if is_array:
# coltype = ARRAY(coltype)
else:
util.warn("Did not recognize type '%s' of column '%s'" %
(type_, name))
coltype = sqltypes.NULLTYPE
if default:
default = re.sub("DEFAULT", "", default).strip()
default = re.sub("^'(.*)'$", lambda m: m.group(1), default)
else:
default = None
column_info = dict(name=name, type=coltype, nullable=nullable,
default=default, autoincrement=autoincrement)
return column_info
示例8: get_columns
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def get_columns(self, connection, table_name, schema=None, **kwargs):
schema = schema or self.default_schema_name
result = connection.execute(
sql.text(
"""SELECT COLUMN_NAME, DATA_TYPE_NAME, DEFAULT_VALUE, IS_NULLABLE, LENGTH, SCALE, COMMENTS FROM (
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, POSITION, DATA_TYPE_NAME, DEFAULT_VALUE, IS_NULLABLE,
LENGTH, SCALE, COMMENTS FROM SYS.TABLE_COLUMNS UNION ALL SELECT SCHEMA_NAME, VIEW_NAME AS TABLE_NAME,
COLUMN_NAME, POSITION, DATA_TYPE_NAME, DEFAULT_VALUE, IS_NULLABLE, LENGTH, SCALE, COMMENTS FROM
SYS.VIEW_COLUMNS) AS COLUMS WHERE SCHEMA_NAME=:schema AND TABLE_NAME=:table ORDER BY POSITION"""
).bindparams(
schema=self.denormalize_name(schema),
table=self.denormalize_name(table_name)
)
)
columns = []
for row in result.fetchall():
column = {
'name': self.normalize_name(row[0]),
'default': row[2],
'nullable': row[3] == "TRUE",
'comment': row[6]
}
if hasattr(types, row[1]):
column['type'] = getattr(types, row[1])
elif hasattr(hana_types, row[1]):
column['type'] = getattr(hana_types, row[1])
else:
util.warn("Did not recognize type '%s' of column '%s'" % (
row[1], column['name']
))
column['type'] = types.NULLTYPE
if column['type'] == types.DECIMAL:
column['type'] = types.DECIMAL(row[4], row[5])
elif column['type'] == types.VARCHAR:
column['type'] = types.VARCHAR(row[4])
columns.append(column)
return columns
示例9: _get_column_info
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def _get_column_info(
self,
name,
type_,
nullable,
autoincrement,
default,
precision,
scale,
length,
):
coltype = self.ischema_names.get(type_, None)
kwargs = {}
if coltype in (NUMERIC, DECIMAL):
args = (precision, scale)
elif coltype == FLOAT:
args = (precision,)
elif coltype in (CHAR, VARCHAR, UNICHAR, UNIVARCHAR, NCHAR, NVARCHAR):
args = (length,)
else:
args = ()
if coltype:
coltype = coltype(*args, **kwargs)
# is this necessary
# if is_array:
# coltype = ARRAY(coltype)
else:
util.warn(
"Did not recognize type '%s' of column '%s'" % (type_, name)
)
coltype = sqltypes.NULLTYPE
if default:
default = default.replace("DEFAULT", "").strip()
default = re.sub("^'(.*)'$", lambda m: m.group(1), default)
else:
default = None
column_info = dict(
name=name,
type=coltype,
nullable=nullable,
default=default,
autoincrement=autoincrement,
)
return column_info
示例10: _fixture
# 需要導入模塊: from sqlalchemy import util [as 別名]
# 或者: from sqlalchemy.util import warn [as 別名]
def _fixture(self, explode_on_exec, initialize):
class DBAPIError(Exception):
pass
def MockDBAPI():
def cursor():
while True:
if explode_on_exec:
yield Mock(
description=[],
close=Mock(side_effect=DBAPIError("explode")),
execute=Mock(side_effect=DBAPIError("explode")),
)
else:
yield Mock(
description=[],
close=Mock(side_effect=Exception("explode")),
)
def connect():
while True:
yield Mock(
spec=["cursor", "commit", "rollback", "close"],
cursor=Mock(side_effect=cursor()),
)
return Mock(
Error=DBAPIError,
paramstyle="qmark",
connect=Mock(side_effect=connect()),
)
dbapi = MockDBAPI()
from sqlalchemy.engine import default
url = Mock(
get_dialect=lambda: default.DefaultDialect,
_get_entrypoint=lambda: default.DefaultDialect,
_instantiate_plugins=lambda kwargs: (),
translate_connect_args=lambda: {},
query={},
)
eng = testing_engine(
url, options=dict(module=dbapi, _initialize=initialize)
)
eng.pool.logger = Mock()
def get_default_schema_name(connection):
try:
cursor = connection.connection.cursor()
connection._cursor_execute(cursor, "statement", {})
cursor.close()
except exc.DBAPIError:
util.warn("Exception attempting to detect")
eng.dialect._get_default_schema_name = get_default_schema_name
return eng