我的代码如下:
CALL:ECHOCOLOR "Executing on server:[S059D526\TCH] db:CS filename:[9990294_UPDATE_Concessions.sql]." Cyan
SET CURRENT_SCRIPT="9990294_UPDATE_Concessions.sql"
if not exist "9990294_UPDATE_Concessions.sql" (
CALL:ECHOCOLOR "skipping execution of file [9990294_UPDATE_Concessions.sql]. Possibly it was renamed because it has already ran" Yellow
)
if exist "9990294_UPDATE_Concessions.sql" (
CALL:ECHOCOLOR "executing script [9990294_UPDATE_Concessions.sql]" Cyan
sqlcmd -V 1 -r1 -E -S S059D526\TCH -d "CS" -i "9990294_UPDATE_Concessions.sql" -o "9990294_UPDATE_Concessions.sql.run_20120508_12_19_36.log"
)
CALL:ECHORESULT "result [OK=0,ERR=any other]: %errorlevel%" %errorlevel%
if NOT ERRORLEVEL 0 GOTO FINAL_ERROR
if exist "9990294_UPDATE_Concessions.sql" rename "9990294_UPDATE_Concessions.sql" "9990294_UPDATE_Concessions.sql.ok"
我面临的问题是errorlevel
,因为在我运行数据库脚本后它总是返回 0。这是因为指令CALL:ECHORESULT "result [OK=0,ERR=any other]: %errorlevel%" %errorlevel%
. 如果脚本运行时出错,它永远不会转到FINAL_ERROR
. 当我遇到脚本错误时,我不知道如何进行验证以停止该过程。