【发布时间】:2018-03-27 08:47:44
【问题描述】:
使用机器人框架连接 Sybase DB 然后删除行,更新表中的行。
在机器人框架中执行以下查询时,它工作正常。
Sybase 数据库连接 - 一次性删除和更新
connect To Database Using Custom Params pyodbc "Driver={Adaptive Server Enterprise}; server=<myserver>; port=<myport>;db=<mydb>;uid=<myuser>; pwd=<mypasswd>;"
# Run Select Query
@{selectQuery} Query select * from TABLE where FIELD1 = '1000'
Log Many @{selectQuery}
Log "Selected Query Executed"
# Run Delete Query
@{DeleteQuery} Execute Sql String set chained off ; Delete from TABLE where FIELD1 = '1000' AND FIELD2 = 'VALUE2' AND FIELD3 = 'VALUE3'
Log Many @{DeleteQuery}
Log "Delete Query Executed"
#Run Update Query
@{updateQuery} Execute Sql String set chained off ; UPDATE TABLE SET FIELD2 = 'VALUE2' where FIELD1 = '1001'
Log Many @{updateQuery}
Log "Update Query Executed"
Disconnect From Database
而当使用 for 循环时:
Sybase 数据库连接 - 使用 for 循环删除多遍
connect To Database Using Custom Params pyodbc "Driver={Adaptive Server Enterprise}; server=<myserver>; port=<myport>;db=<mydb>;uid=<myuser>; pwd=<mypasswd>;"
#Run DELETE Query
:FOR ${num} IN RANGE 100
\ Execute Sql String set chained off ; Delete from TABLE where FIELD1 = ${num} and FIELD2= "${VALUE2[${num}]}" and FIELD3 = "${VALUE3[${num}]}"
\ sleep 1
失败并出现以下错误:
[Sybase][ODBC Driver][Adaptive Server Enterprise]SET CHAINED command not allowed within multi-statement transaction.\n (226) (SQLExecDirectW);
[Sybase][ODBC Driver][Adaptive Server Enterprise]Stored procedure 'abc_sp' may be run only in unchained transaction mode. The 'SET CHAINED OFF' command will cause the current session to use unchained transaction mode.\n (7713)")
【问题讨论】:
标签: database robotframework sybase sap-ase