函数参考


_SQLite_SetTimeout

为忙碌的处理程序设置超时

#include <SQLite.au3>
_SQLite_SetTimeout ( [ $hDB = -1 [, $iTimeout = 1000 ]] )

参数

$hDB [可选参数] 打开的数据库,如为 -1, 则使用最后打开的数据库
$iTimeout [可选参数] 超时值 [毫秒]

返回值

成功: 返回 $SQLITE_OK
失败: 返回值可能违反 $SQLITE_* 常量@错误:
-1 - SQLite 报告错误 (检查返回值)
1 - 错误调用 SQLite API 'sqlite3_busy_timeout'
2 - 调用被安全模式阻止

注意/说明

 此例程设置一个繁忙的处理程序暂时锁定表,. 该处理程序将休眠多次,
 至少到 “ms” 毫秒休眠时间已经完成. 休眠 "ms" 毫秒以后,
 处理程序返回 0, 导致 sqlite3_exec() 返回 SQLITE_BUSY.

相关

示例/演示


#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <File.au3>

_SQLite_Startup()
ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)

Local $sDatabase, $hDB_a, $hDB_b, $iTimer, $iRval
$sDatabase = _TempFile()
$hDB_a = _SQLite_Open($sDatabase)
$hDB_b = _SQLite_Open($sDatabase)

_SQLite_Exec($hDB_a, "BEGIN EXCLUSIVE;")
_SQLite_Exec($hDB_a, "CREATE TABLE test (a,b,c);")
_SQLite_Exec($hDB_a, "INSERT INTO test VALUES (1,2,3);")
; 'test' 现在正忙...

_SQLite_SetTimeout($hDB_b, 0)
$iTimer = TimerInit()
$iRval = _SQLite_Exec($hDB_b, "SELECT * FROM test") ; 此操作将失败
MsgBox(4096, "_SQLite_SetTimeout Example No Timeout", "Time: " & TimerDiff($iTimer) & @CRLF _
         & "Error: " & _SQLite_ErrMsg($hDB_b) & @CRLF)
_SQLite_SetTimeout($hDB_b, 5000)
$iTimer = TimerInit()
$iRval = _SQLite_Exec($hDB_b, "SELECT * FROM test") ; 此操作将失败
MsgBox(4096, "_SQLite_SetTimeout Example 5 Sec Timeout", "Time: " & TimerDiff($iTimer) & @CRLF _
         & "Error: " & _SQLite_ErrMsg($hDB_b) & @CRLF)
_SQLite_Exec($hDB_a, "END;")
_SQLite_Close($hDB_a)
_SQLite_Close($hDB_b)
_SQLite_Shutdown()
FileDelete($sDatabase)