Function Reference


_SQLite_Open

Opens/creates a SQLite database

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

Parameters

$sDatabase_Filename [optional] Database filename, by default will open a memory database.
$iAccessMode [optional] access mode flags. Defaults to $SQLITE_OPEN_READWRITE + $SQLITE_OPEN_CREATE
$iEncoding [optional] encoding mode flag, only used at creation time. Defaults to $SQLITE_ENCODING_UTF8

Return Value

Success: a database handle.
Failure: 0.
@error: -1 - SQLite Reported an Error (Check @extended Value)
1 - Error Calling SQLite API 'sqlite3_open_v2'
2 - Error while converting filename to UTF-8
3 - _SQLite_Startup() not yet called
@extended: value can be compared against $SQLITE_* constants

Remarks

There is no need to store the database handle, except if you use more than one database in the same session.
Functions that use the handle are using the last opened by default.

To create a database encoded in UFT16 just create it with $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.

Related

_SQLite_Close

Example

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

_SQLite_Startup()
If @error Then
        MsgBox($MB_SYSTEMMODAL, "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($MB_SYSTEMMODAL, "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($MB_SYSTEMMODAL, "SQLite Error", "Can't create a memory Database!")
        Exit -1
EndIf

Local $hTmpDb = _SQLite_Open('') ; Creates a temporary disk database
If @error Then
        MsgBox($MB_SYSTEMMODAL, "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($MB_SYSTEMMODAL, "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()