如何使用prepare_statement OCI Python SDK 和NoSQL 云服务?
How to use prepare_statement with OCI Python SDK and NoSQL cloud service?
我计划使用 OCI Python SDK 在 OCI 上使用 Oracle NoSQL 云服务。我使用 API 调用进行了一些测试,我想使用 Python SDK 进行相同的查询。
如何使用准备好的语句而不是常规语句(见下文)以及我需要设置什么值
print("second attempt")
table_name = 'table1'
statement = 'declare $id integer; select * from ' + table_name + ' where id=$id'
id_value = '1'
#nosqlClient.prepare_statement(compartment_id=comp_ocid,statement=statement),
query_response = nosqlClient.query(
query_details=oci.nosql.models.QueryDetails(
compartment_id=comp_ocid,
statement=statement,
is_prepared=True,
consistency="EVENTUAL",
variables={
'$id': id_value}))# Get the data from response
print(query_response.data)
目前我有以下错误:
oci.exceptions.ServiceError:
{'opc-request-id': '94E0B7EA0C864B379D66ED1C5215652A',
'code': 'InvalidParameter',
'message': 'QUERY: Illegal Argument: Deserialize prep query failed: Hash provided for prepared query does not match payload', 'status': 400}
问题出在 QueryDetails 的“statement”属性上。
- 使用
nosqlClient.prepare_statement
的结果(注意脚本末尾的逗号)
- 使用以下参数调用 oci.nosql.models.QueryDetails
statement=prepare_statement_response.data.statement, is_prepared=True and variables
table_name = 'table1'
statement = 'declare $Id long; select * from ' + table_name + ' where id = $Id'
id_value = 1
prepare_statement_response = nosqlClient.prepare_statement(compartment_id=comp_ocid,statement=statement)
print(prepare_statement_response.data.statement)
query_response = nosqlClient.query(
query_details=oci.nosql.models.QueryDetails(
compartment_id=comp_ocid,
statement=prepare_statement_response.data.statement,
is_prepared=True,
consistency="EVENTUAL",
variables={
'$Id': id_value}))
print(query_response.data)
希望对您有所帮助
我计划使用 OCI Python SDK 在 OCI 上使用 Oracle NoSQL 云服务。我使用 API 调用进行了一些测试,我想使用 Python SDK 进行相同的查询。
如何使用准备好的语句而不是常规语句(见下文)以及我需要设置什么值
print("second attempt")
table_name = 'table1'
statement = 'declare $id integer; select * from ' + table_name + ' where id=$id'
id_value = '1'
#nosqlClient.prepare_statement(compartment_id=comp_ocid,statement=statement),
query_response = nosqlClient.query(
query_details=oci.nosql.models.QueryDetails(
compartment_id=comp_ocid,
statement=statement,
is_prepared=True,
consistency="EVENTUAL",
variables={
'$id': id_value}))# Get the data from response
print(query_response.data)
目前我有以下错误:
oci.exceptions.ServiceError:
{'opc-request-id': '94E0B7EA0C864B379D66ED1C5215652A',
'code': 'InvalidParameter',
'message': 'QUERY: Illegal Argument: Deserialize prep query failed: Hash provided for prepared query does not match payload', 'status': 400}
问题出在 QueryDetails 的“statement”属性上。
- 使用
nosqlClient.prepare_statement
的结果(注意脚本末尾的逗号) - 使用以下参数调用 oci.nosql.models.QueryDetails
statement=prepare_statement_response.data.statement, is_prepared=True and variables
table_name = 'table1'
statement = 'declare $Id long; select * from ' + table_name + ' where id = $Id'
id_value = 1
prepare_statement_response = nosqlClient.prepare_statement(compartment_id=comp_ocid,statement=statement)
print(prepare_statement_response.data.statement)
query_response = nosqlClient.query(
query_details=oci.nosql.models.QueryDetails(
compartment_id=comp_ocid,
statement=prepare_statement_response.data.statement,
is_prepared=True,
consistency="EVENTUAL",
variables={
'$Id': id_value}))
print(query_response.data)
希望对您有所帮助