本文整理匯總了Python中sqlalchemy.dialects.oracle.cx_oracle.dialect方法的典型用法代碼示例。如果您正苦於以下問題:Python cx_oracle.dialect方法的具體用法?Python cx_oracle.dialect怎麽用?Python cx_oracle.dialect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.dialects.oracle.cx_oracle
的用法示例。
在下文中一共展示了cx_oracle.dialect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_no_clobs_for_string_params
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_no_clobs_for_string_params(self):
"""test that simple string params get a DBAPI type of
VARCHAR, not CLOB. This is to prevent setinputsizes
from setting up cx_oracle.CLOBs on
string-based bind params [ticket:793]."""
class FakeDBAPI(object):
def __getattr__(self, attr):
return attr
dialect = oracle.OracleDialect()
dbapi = FakeDBAPI()
b = bindparam("foo", "hello world!")
eq_(b.type.dialect_impl(dialect).get_dbapi_type(dbapi), "STRING")
b = bindparam("foo", "hello world!")
eq_(b.type.dialect_impl(dialect).get_dbapi_type(dbapi), "STRING")
示例2: test_reflect_unicode_no_nvarchar
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_reflect_unicode_no_nvarchar(self):
metadata = self.metadata
Table("tnv", metadata, Column("data", sqltypes.Unicode(255)))
metadata.create_all()
m2 = MetaData(testing.db)
t2 = Table("tnv", m2, autoload=True)
assert isinstance(t2.c.data.type, sqltypes.VARCHAR)
if testing.against("oracle+cx_oracle"):
assert isinstance(
t2.c.data.type.dialect_impl(testing.db.dialect),
cx_oracle._OracleString,
)
data = u("m’a réveillé.")
t2.insert().execute(data=data)
res = t2.select().execute().first()["data"]
eq_(res, data)
assert isinstance(res, util.text_type)
示例3: test_were_getting_a_comma
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_were_getting_a_comma(self):
connection = self.engine.pool._creator()
cursor = connection.cursor()
try:
cx_Oracle = self.engine.dialect.dbapi
def output_type_handler(
cursor, name, defaultType, size, precision, scale
):
return cursor.var(
cx_Oracle.STRING, 255, arraysize=cursor.arraysize
)
cursor.outputtypehandler = output_type_handler
cursor.execute("SELECT 1.1 FROM DUAL")
row = cursor.fetchone()
eq_(row[0], "1,1")
finally:
cursor.close()
connection.close()
示例4: test_older_cx_oracle_warning
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_older_cx_oracle_warning(self, cx_Oracle, cx_oracle_type):
cx_Oracle.version = "6.3"
ignore_dialect = cx_oracle.dialect(
dbapi=cx_Oracle, encoding_errors="ignore"
)
ignore_outputhandler = (
ignore_dialect._generate_connection_outputtype_handler()
)
cursor = mock.Mock()
with testing.expect_warnings(
r"cx_oracle version \(6, 3\) does not support encodingErrors"
):
ignore_outputhandler(
cursor, "foo", cx_oracle_type, None, None, None
)
示例5: test_encoding_errors_cx_oracle_py3k
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_encoding_errors_cx_oracle_py3k(
self, cx_Oracle, cx_oracle_type,
):
ignore_dialect = cx_oracle.dialect(
dbapi=cx_Oracle, encoding_errors="ignore"
)
ignore_outputhandler = (
ignore_dialect._generate_connection_outputtype_handler()
)
cursor = mock.Mock()
ignore_outputhandler(cursor, "foo", cx_oracle_type, None, None, None)
eq_(
cursor.mock_calls,
[
mock.call.var(
mock.ANY, None, cursor.arraysize, encodingErrors="ignore",
)
],
)
示例6: test_no_encoding_errors_cx_oracle_py3k
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_no_encoding_errors_cx_oracle_py3k(
self, cx_Oracle, cx_oracle_type,
):
plain_dialect = cx_oracle.dialect(dbapi=cx_Oracle)
plain_outputhandler = (
plain_dialect._generate_connection_outputtype_handler()
)
cursor = mock.Mock()
plain_outputhandler(cursor, "foo", cx_oracle_type, None, None, None)
eq_(
cursor.mock_calls,
[mock.call.var(mock.ANY, None, cursor.arraysize)],
)
示例7: test_ora8_flags
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_ora8_flags(self):
dialect = self._dialect((8, 2, 5))
# before connect, assume modern DB
assert dialect._supports_char_length
assert dialect.use_ansi
assert not dialect._use_nchar_for_unicode
dialect.initialize(Mock())
assert not dialect.implicit_returning
assert not dialect._supports_char_length
assert not dialect.use_ansi
self.assert_compile(String(50), "VARCHAR2(50)", dialect=dialect)
self.assert_compile(Unicode(50), "VARCHAR2(50)", dialect=dialect)
self.assert_compile(UnicodeText(), "CLOB", dialect=dialect)
dialect = self._dialect((8, 2, 5), implicit_returning=True)
dialect.initialize(testing.db.connect())
assert dialect.implicit_returning
示例8: test_max_ident_122
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_max_ident_122(self):
dialect = self._dialect((12, 2, 0))
conn = mock.Mock(
exec_driver_sql=mock.Mock(
return_value=mock.Mock(scalar=lambda: "12.2.0")
)
)
dialect.initialize(conn)
eq_(dialect.server_version_info, (12, 2, 0))
eq_(
dialect._get_effective_compat_server_version_info(conn), (12, 2, 0)
)
eq_(
dialect.max_identifier_length,
oracle.OracleDialect.max_identifier_length,
)
示例9: test_max_ident_122_11compat_vparam_raises
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_max_ident_122_11compat_vparam_raises(self):
dialect = self._dialect((12, 2, 0))
def c122():
raise exc.DBAPIError(
"statement", None, "no such table", None, None
)
conn = mock.Mock(
exec_driver_sql=mock.Mock(return_value=mock.Mock(scalar=c122))
)
dialect.initialize(conn)
eq_(dialect.server_version_info, (12, 2, 0))
eq_(
dialect._get_effective_compat_server_version_info(conn), (12, 2, 0)
)
eq_(
dialect.max_identifier_length,
oracle.OracleDialect.max_identifier_length,
)
示例10: test_max_ident_122_11compat_vparam_cant_parse
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_max_ident_122_11compat_vparam_cant_parse(self):
dialect = self._dialect((12, 2, 0))
def c122():
return "12.thisiscrap.0"
conn = mock.Mock(
exec_driver_sql=mock.Mock(return_value=mock.Mock(scalar=c122))
)
dialect.initialize(conn)
eq_(dialect.server_version_info, (12, 2, 0))
eq_(
dialect._get_effective_compat_server_version_info(conn), (12, 2, 0)
)
eq_(
dialect.max_identifier_length,
oracle.OracleDialect.max_identifier_length,
)
示例11: test_limit_one
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_limit_one(self):
t = table("sometable", column("col1"), column("col2"))
s = select([t])
c = s.compile(dialect=oracle.OracleDialect())
assert t.c.col1 in set(c._create_result_map()["col1"][1])
s = select([t]).limit(10).offset(20)
self.assert_compile(
s,
"SELECT anon_1.col1, anon_1.col2 FROM "
"(SELECT anon_2.col1 AS col1, "
"anon_2.col2 AS col2, ROWNUM AS ora_rn FROM (SELECT "
"sometable.col1 AS col1, sometable.col2 AS "
"col2 FROM sometable) anon_2 WHERE ROWNUM <= "
"[POSTCOMPILE_param_1]) anon_1 WHERE ora_rn > "
"[POSTCOMPILE_param_2]",
checkparams={"param_1": 30, "param_2": 20},
)
c = s.compile(dialect=oracle.OracleDialect())
eq_(len(c._result_columns), 2)
assert t.c.col1 in set(c._create_result_map()["col1"][1])
示例12: test_limit_one_firstrows
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_limit_one_firstrows(self):
t = table("sometable", column("col1"), column("col2"))
s = select([t])
s = select([t]).limit(10).offset(20)
self.assert_compile(
s,
"SELECT anon_1.col1, anon_1.col2 FROM "
"(SELECT /*+ FIRST_ROWS([POSTCOMPILE_ora_frow_1]) */ "
"anon_2.col1 AS col1, "
"anon_2.col2 AS col2, ROWNUM AS ora_rn FROM (SELECT "
"sometable.col1 AS col1, sometable.col2 AS "
"col2 FROM sometable) anon_2 WHERE ROWNUM <= "
"[POSTCOMPILE_param_1]) anon_1 WHERE ora_rn > "
"[POSTCOMPILE_param_2]",
checkparams={"ora_frow_1": 10, "param_1": 30, "param_2": 20},
dialect=oracle.OracleDialect(optimize_limits=True),
)
示例13: test_limit_three
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_limit_three(self):
t = table("sometable", column("col1"), column("col2"))
s = select([t]).limit(10).offset(20).order_by(t.c.col2)
self.assert_compile(
s,
"SELECT anon_1.col1, anon_1.col2 FROM "
"(SELECT anon_2.col1 AS col1, "
"anon_2.col2 AS col2, ROWNUM AS ora_rn FROM (SELECT "
"sometable.col1 AS col1, sometable.col2 AS "
"col2 FROM sometable ORDER BY "
"sometable.col2) anon_2 WHERE ROWNUM <= "
"[POSTCOMPILE_param_1]) anon_1 "
"WHERE ora_rn > [POSTCOMPILE_param_2]",
checkparams={"param_1": 30, "param_2": 20},
)
c = s.compile(dialect=oracle.OracleDialect())
eq_(len(c._result_columns), 2)
assert t.c.col1 in set(c._create_result_map()["col1"][1])
示例14: test_use_binds_for_limits_disabled_one
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_use_binds_for_limits_disabled_one(self):
t = table("sometable", column("col1"), column("col2"))
with testing.expect_deprecated(
"The ``use_binds_for_limits`` Oracle dialect parameter is "
"deprecated."
):
dialect = oracle.OracleDialect(use_binds_for_limits=False)
self.assert_compile(
select([t]).limit(10),
"SELECT anon_1.col1, anon_1.col2 FROM "
"(SELECT sometable.col1 AS col1, "
"sometable.col2 AS col2 FROM sometable) anon_1 "
"WHERE ROWNUM <= [POSTCOMPILE_param_1]",
dialect=dialect,
)
示例15: test_use_binds_for_limits_disabled_two
# 需要導入模塊: from sqlalchemy.dialects.oracle import cx_oracle [as 別名]
# 或者: from sqlalchemy.dialects.oracle.cx_oracle import dialect [as 別名]
def test_use_binds_for_limits_disabled_two(self):
t = table("sometable", column("col1"), column("col2"))
with testing.expect_deprecated(
"The ``use_binds_for_limits`` Oracle dialect parameter is "
"deprecated."
):
dialect = oracle.OracleDialect(use_binds_for_limits=False)
self.assert_compile(
select([t]).offset(10),
"SELECT anon_1.col1, anon_1.col2 FROM (SELECT "
"anon_2.col1 AS col1, anon_2.col2 AS col2, ROWNUM AS ora_rn "
"FROM (SELECT sometable.col1 AS col1, sometable.col2 AS col2 "
"FROM sometable) anon_2) anon_1 "
"WHERE ora_rn > [POSTCOMPILE_param_1]",
dialect=dialect,
)