# Function Reference

# _SQLite_Encode

Binary encodes a string, number or binary data for use as BLOB in SQLite statements

#include <SQLite.au3>
_SQLite_Encode ( $vData )

## Parameters

$vData | Data To be encoded (String, Number or Binary)

## Return Value

Success: | an encoded string.
Failure: | Empty string and sets the @error flag to non-zero.

## Remarks

The encoded string is already wrapped with single quotes.
For example Chr(0) & Chr(1) would look like X'0001'.
The encoded string can be decoded by Sqlite and stored in binary state as a BLOB.
For strings to be stored as TEXT use _SQLite_Escape().
For numeric value to be stored as such, use simple concatenation.

## Related

_SQLite_Escape

## Example

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

    Local $hFile, $vData, $sFileName, $sData, $hQuery, $aRow, $sMsg
    _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()
    _SQLite_Exec(-1, "CREATE TABLE IF NOT EXISTS Test (data blob);")
    $vData = Binary("Hello" & Chr(0) & "World"); = 48656C6C6F00576F726C64
    $sData = _SQLite_Encode($vData)
    _SQLite_Exec(-1, "INSERT INTO Test VALUES (" & $sData & ");")
    $vData = Binary(Chr(0) & @CRLF); = 000D0A
    $sData = _SQLite_Encode($vData)
    _SQLite_Exec(-1, "INSERT INTO Test VALUES (" & $sData & ");")
    $vData = Binary(Chr(0)); = 00 but this is interpreted as Number and returns 0000000000000000
    $sData = _SQLite_Encode($vData)
    _SQLite_Exec(-1, "INSERT INTO Test VALUES ( " & $sData & " );")
    _SQLite_Query(-1, "SELECT * FROM Test;", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow, 1) = $SQLITE_OK
        $sMsg &= Hex($aRow[0]) & @CRLF
    WEnd
    MsgBox($MB_SYSTEMMODAL, "Result", $sMsg)
    _SQLite_Close()
    _SQLite_Shutdown()