函数参考


_SQLite_Open

打开或创建 SQLite 数据库.

#include <SQLite.au3>
_SQLite_Open ( [ $sDatabase_Filename = ":memory:" [,$iAccessMode [,$iEncoding ]]] )

参数

$sDatabase_Filename [可选参数] 数据库文件名,默认打开内存中的数据库.
$iAccessMode [可选参数] 访问模式标志. 默认为 $SQLITE_OPEN_READWRITE + $SQLITE_OPEN_CREATE
$iEncoding [可选参数] 编码模式标志,只用于创建时间.默认为 $SQLITE_ENCODING_UTF8

返回值

成功: Returns 数据库句柄.
失败: 返回 0.
@error: -1 - SQLite 报告一个错误 (检查 @extended 的值)
@extended: value can be compared against $SQLITE_* constants

注意/说明

除非您在同一会话中操作多个数据库,否则您没有必要存储数据库句柄.
函数使用的句柄是上次使用默认打开的句柄.

要创建一个数据库中UFT16编码,使用 $iEncoding=$SQLITE_ENCODING_UTF16.

Memory, temporary and permanent databases can be opened:
     $hDb = _SQLite_Open() ; opens a temporary private memory DB
     $hDb = _SQLite_Open(Default, ...) ; ditto
     $hDb = _SQLite_Open(':memory:', ...) ; ditto

     $hDb = _SQLite_Open('', ...) ; opens a temporary private on-disk DB

     $hDb = _SQLite_Open('abc.db', ...) ; opens or creates a permanent shareable on-disk DB named 'abc.db'

  In case you insist confusing yourself:
     $hDb = _SQLite_Open('./:memory:', ...) ; opens or creates a permanent shareable on-disk DB named ':memory:'

Contrary to permanent disk-based DBs, memory and temporary DBs can't be shared nor be used for IPC (Inter Process Communication) and are destroyed at the end of the connection.

相关

_SQLite_Close

示例/演示


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

_SQLite_Startup()
If @error Then
    MsgBox(16, "SQLite Error", "SQLite3.dll Can't be Loaded!")
    Exit -1
EndIf
ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)

_SQLite_Open() ; Creates a :memory: database and don't use its handle to refer to it
If @error Then
    MsgBox(16, "SQLite Error", "Can't create a memory Database!")
    Exit -1
EndIf
_SQLite_Close()

Local $hMemDb = _SQLite_Open() ; Creates a :memory: database
If @error Then
    MsgBox(16, "SQLite Error", "Can't create a memory Database!")
    Exit -1
EndIf

Local $hTmpDb = _SQLite_Open('') ; Creates a temporary disk database
If @error Then
    MsgBox(16, "SQLite Error", "Can't create a temporary Database!")
    Exit -1
EndIf

Local $sDbName = _TempFile()
Local $hDskDb = _SQLite_Open($sDbName) ; Open a permanent disk database
If @error Then
    MsgBox(16, "SQLite Error", "Can't open or create a permanent Database!")
    Exit -1
EndIf

; we can use the 3 database as needed by refering to their handle

; close the Dbs we created, in any order
_SQLite_Close($hTmpDb) ; temporary database are deleted automatically at Close
_SQLite_Close($hDskDb) ; DB is a regular file that could be reopened later
_SQLite_Close($hMemDb)

; we don't really need that DB
FileDelete($sDbName)

_SQLite_Shutdown()