本文整理汇总了Python中sqlalchemy.exc.CompileError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.CompileError方法的具体用法?Python exc.CompileError怎么用?Python exc.CompileError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.exc
的用法示例。
在下文中一共展示了exc.CompileError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_create_table
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def post_create_table(self, table):
raw_connection = table.bind.raw_connection()
# TODO Supports orc, avro, json, csv or tsv format
text = "STORED AS PARQUET\n"
location = (
raw_connection._kwargs["s3_dir"]
if "s3_dir" in raw_connection._kwargs
else raw_connection.s3_staging_dir
)
if not location:
raise exc.CompileError(
"`s3_dir` or `s3_staging_dir` parameter is required"
" in the connection string."
)
schema = table.schema if table.schema else raw_connection.schema_name
text += "LOCATION '{0}{1}/{2}/'\n".format(location, schema, table.name)
compression = raw_connection._kwargs.get("compression")
if compression:
text += "TBLPROPERTIES ('parquet.compress'='{0}')\n".format(
compression.upper()
)
return text
示例2: visit_column_default
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def visit_column_default(element, compiler, **kw):
if sqla_compat.has_computed and (
isinstance(element.default, sqla_compat.Computed)
or isinstance(element.existing_server_default, sqla_compat.Computed)
):
raise exc.CompileError(
'Adding or removing a "computed" construct, e.g. GENERATED '
"ALWAYS AS, to or from an existing column is not supported."
)
return "%s %s %s" % (
alter_table(compiler, element.table_name, element.schema),
alter_column(compiler, element.column_name),
"SET DEFAULT %s" % format_server_default(compiler, element.default)
if element.default is not None
else "DROP DEFAULT",
)
示例3: get_column_specification
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def get_column_specification(self, column, **kwargs):
if column.table is None:
raise exc.CompileError(
"Teradata requires Table-bound columns "
"in order to generate DDL")
colspec = (self.preparer.format_column(column) + " " +\
self.dialect.type_compiler.process(
column.type, type_expression=column))
# Null/NotNull
if column.nullable is not None:
if not column.nullable or column.primary_key:
colspec += " NOT NULL"
return colspec
示例4: post_create_table
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def post_create_table(self, table):
raw_connection = table.bind.raw_connection()
# TODO Supports orc, avro, json, csv or tsv format
text = "STORED AS PARQUET\n"
location = (
raw_connection._driver_kwargs["s3_dir"]
if "s3_dir" in raw_connection._driver_kwargs
else raw_connection.s3_staging_dir
)
if not location:
raise exc.CompileError(
"`s3_dir` or `s3_staging_dir` parameter is required"
" in the connection string."
)
text += "LOCATION '{0}{1}/{2}/'\n".format(location, table.schema, table.name)
compression = raw_connection._driver_kwargs.get("compression")
if compression:
text += "TBLPROPERTIES ('parquet.compress'='{0}')\n".format(
compression.upper()
)
return text
示例5: create_query
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def create_query(cls, sql: str, params: Dict[str, Any]) -> str:
text_sql: TextClause = text(sql)
kwargs = {'dialect': cls.DIALECT, 'compile_kwargs': {"literal_binds": True}}
try:
return str(
text_sql.bindparams(
**{k: null() if v is None else v for k, v in params.items()}
).compile(**kwargs)
)
except CompileError as e:
invalid_param_match = re.match(INVALID_PARAMETER_MESSAGE, e.args[0])
if invalid_param_match: # pragma: no cover
raise BadRequestException(
message=f'Cannot find parameter: {invalid_param_match.group(1)}'
)
raise # pragma: no cover
except ArgumentError as e:
undefined_param_match = re.match(UNDEFINED_PARAMETER_MESSAGE, e.args[0])
if undefined_param_match: # pragma: no cover
undefined_param: str = undefined_param_match.group(1)
return cls.create_query(
sql, {k: v for k, v in params.items() if k != undefined_param}
)
raise # pragma: no cover
示例6: test_on_conflict_clause_check_constraint_from_column
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_on_conflict_clause_check_constraint_from_column(self):
meta = MetaData()
t = Table(
"n",
meta,
Column(
"x",
Integer,
CheckConstraint("x > 1", sqlite_on_conflict="FAIL"),
),
)
assert_raises_message(
exc.CompileError,
"SQLite does not support on conflict "
"clause for column check constraint",
CreateTable(t).compile,
dialect=sqlite.dialect(),
)
示例7: test_match_kw_raises
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_match_kw_raises(self):
m = MetaData()
Table("t1", m, Column("id", Integer, primary_key=True))
t2 = Table(
"t2",
m,
Column(
"id",
Integer,
ForeignKey("t1.id", match="XYZ"),
primary_key=True,
),
)
assert_raises_message(
exc.CompileError,
"MySQL ignores the 'MATCH' keyword while at the same time causes "
"ON UPDATE/ON DELETE clauses to be ignored.",
schema.CreateTable(t2).compile,
dialect=mysql.dialect(),
)
示例8: test_varchar_raise
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_varchar_raise(self, type_):
type_ = sqltypes.to_instance(type_)
assert_raises_message(
exc.CompileError,
"VARCHAR requires a length on dialect mysql",
type_.compile,
dialect=mysql.dialect(),
)
t1 = Table("sometable", MetaData(), Column("somecolumn", type_))
assert_raises_message(
exc.CompileError,
r"\(in table 'sometable', column 'somecolumn'\)\: "
r"(?:N)?VARCHAR requires a length on dialect mysql",
schema.CreateTable(t1).compile,
dialect=mysql.dialect(),
)
示例9: test_server_default_absent_value
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_server_default_absent_value(self):
metadata = MetaData()
table = Table(
"sometable",
metadata,
Column("id", Integer, primary_key=True),
Column("data", String),
Column("foo", Integer, server_default=func.foobar()),
)
values = [
{"id": 1, "data": "data1", "foo": "plainfoo"},
{"id": 2, "data": "data2"},
{"id": 3, "data": "data3", "foo": "otherfoo"},
]
assert_raises_message(
exc.CompileError,
"INSERT value for column sometable.foo is explicitly rendered "
"as a boundparameter in the VALUES clause; a Python-side value or "
"SQL expression is required",
table.insert().values(values).compile,
)
示例10: test_limit_offset_no_int_coercion_two
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_limit_offset_no_int_coercion_two(self):
exp1 = literal_column("Q")
exp2 = literal_column("Y")
sel = select([1]).limit(exp1).offset(exp2)
assert_raises_message(
exc.CompileError,
"This SELECT structure does not use a simple integer "
"value for limit",
getattr,
sel,
"_limit",
)
assert_raises_message(
exc.CompileError,
"This SELECT structure does not use a simple integer "
"value for offset",
getattr,
sel,
"_offset",
)
示例11: test_limit_offset_no_int_coercion_three
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_limit_offset_no_int_coercion_three(self):
exp1 = bindparam("Q")
exp2 = bindparam("Y")
sel = select([1]).limit(exp1).offset(exp2)
assert_raises_message(
exc.CompileError,
"This SELECT structure does not use a simple integer "
"value for limit",
getattr,
sel,
"_limit",
)
assert_raises_message(
exc.CompileError,
"This SELECT structure does not use a simple integer "
"value for offset",
getattr,
sel,
"_offset",
)
示例12: test_fk_illegal_sql_phrases
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_fk_illegal_sql_phrases(self):
a = Table("a", MetaData(), Column("q", Integer))
b = Table("b", MetaData(), Column("p", Integer))
for kw in ("onupdate", "ondelete", "initially"):
for phrase in (
"NOT SQL",
"INITALLY NOT SQL",
"FOO RESTRICT",
"CASCADE WRONG",
"SET NULL",
):
const = schema.AddConstraint(
schema.ForeignKeyConstraint(
[a.c.q], [b.c.p], **{kw: phrase}
)
)
assert_raises_message(
exc.CompileError,
r"Unexpected SQL phrase: '%s'" % phrase,
const.compile,
)
示例13: test_colliding_col_label_from_index_flag_no_conv
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_colliding_col_label_from_index_flag_no_conv(self):
t1 = self._colliding_name_fixture({"ck": "foo"}, {"index": True})
idx = list(t1.indexes)[0]
# this behavior needs to fail, as of #4911 since we are testing it,
# ensure it raises a CompileError. In #4289 we may want to revisit
# this in some way, most likely specifically to Postgresql only.
assert_raises_message(
exc.CompileError,
"CREATE INDEX requires that the index have a name",
CreateIndex(idx).compile,
)
assert_raises_message(
exc.CompileError,
"DROP INDEX requires that the index have a name",
DropIndex(idx).compile,
)
示例14: test_columns_augmented_sql_illegal_label_reference
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_columns_augmented_sql_illegal_label_reference(self):
User, Address = self.classes.User, self.classes.Address
sess = create_session()
q = sess.query(User.id, User.name.label("foo"), Address.id).distinct(
"not a label"
)
from sqlalchemy.dialects import postgresql
assert_raises_message(
sa_exc.CompileError,
"Can't resolve label reference for ORDER BY / "
"GROUP BY / DISTINCT etc.",
q.with_labels().statement.compile,
dialect=postgresql.dialect(),
)
示例15: test_order_by_w_eager_five
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import CompileError [as 别名]
def test_order_by_w_eager_five(self):
"""essentially the same as test_eager_relations -> test_limit_3,
but test for textual label elements that are freeform.
this is again #3392."""
User = self.classes.User
Address = self.classes.Address
sess = create_session()
q = sess.query(User, Address.email_address.label("email_address"))
result = (
q.join("addresses")
.options(joinedload(User.orders))
.order_by("email_address desc")
.limit(1)
.offset(0)
)
assert_raises_message(
sa_exc.CompileError,
"Can't resolve label reference for ORDER BY / GROUP BY",
result.all,
)