
{$IFNDEF UNIDACPRO}
{$I ..\LiteDac.inc}

unit Devart.SQLiteDac.LiteCallCLR;
{$ENDIF}

interface

uses
  System.Runtime.InteropServices, System.Text,
  CRTypes, {$IFNDEF UNIDACPRO}LiteCall{$ELSE}LiteCallUni{$ENDIF};

const
  SQLiteDLL = SQLiteDLLName;
  
  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_open(
    filename: IntPtr;    // Database filename (UTF-8)
    out ppDb: pSQLite3      // OUT: SQLite db handle
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Unicode, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_open16(
    filename: IntPtr;    // Database filename (UTF-16)
    out ppDb: pSQLite3      // OUT: SQLite db handle
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_open_v2(
    filename: IntPtr;    // Database filename (UTF-8)
    out ppDb: pSQLite3;     // OUT: SQLite db handle
    flags: Integer;         // Flags
    zVfs: IntPtr         // Name of VFS module to use
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_close(
    pDb: pSQLite3
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_errcode(
    pDb: pSQLite3
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_extended_errcode(
    pDb: pSQLite3
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_extended_result_codes(
    pDb: pSQLite3;
    onoff: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_errmsg(
    pDb: pSQLite3
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_last_insert_rowid(
    pDb: pSQLite3
  ): Int64; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_changes(
    pDb: pSQLite3
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_prepare_v2(
    db: pSQLite3;               // Database handle
    zSql: IntPtr;               // SQL statement, UTF-8 encoded
    nByte: Integer;             // Maximum length of zSql in bytes.
    out ppStmt: pSQLite3Stmt;   // OUT: Statement handle
    out pzTail: IntPtr          // OUT: Pointer to unused portion of zSql
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_step(
    pStmt: pSQLite3Stmt
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_reset(
    pStmt: pSQLite3Stmt
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_finalize(
    pStmt: pSQLite3Stmt
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_count(
    pStmt: pSQLite3Stmt
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_type(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_name(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_origin_name(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_table_name(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_database_name(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_decltype(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_table_column_metadata(
    pDb: pSQLite3;
    zDbName: IntPtr;
    zTableName: IntPtr;
    zColumnName: IntPtr;
    out pzDataType: IntPtr;
    out pzCollSeq: IntPtr;
    out pNotNull: Integer;
    out pPrimaryKey: Integer;
    out pAutoinc: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_blob(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_bytes(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_double(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): double; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_int(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_int64(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): Int64; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_column_text(
    pStmt: pSQLite3Stmt; iCol: Integer
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_parameter_count(
    pStmt: pSQLite3Stmt
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_blob(
    pStmt: pSQLite3Stmt; Index: Integer; pBlob: IntPtr; size: Integer; pDestrType: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_double(
    pStmt: pSQLite3Stmt; Index: Integer; Value: double
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_int(
    pStmt: pSQLite3Stmt; Index: Integer; Value: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_int64(
    pStmt: pSQLite3Stmt; Index: Integer; Value: Int64
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_null(
    pStmt: pSQLite3Stmt; Index: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_bind_text(
    pStmt: pSQLite3Stmt; Index: Integer; Value: IntPtr; size: Integer; pDestrType: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_blob(
    pContext: pSQLite3Context; pBlob: IntPtr; Size: Integer; pDestrType: IntPtr
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_double(
    pContext: pSQLite3Context; Value: Double
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_error(
    pContext: pSQLite3Context; pMsg: IntPtr; Size: Integer
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_error16(
    pContext: pSQLite3Context; pMsg: IntPtr; Size: Integer
  );external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_error_toobig(
    pContext: pSQLite3Context
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_error_nomem(
    pContext: pSQLite3Context
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_error_code(
    pContext: pSQLite3Context; ErrorCode: Integer
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_int(
    pContext: pSQLite3Context; Value: Integer
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_int64(
    pContext: pSQLite3Context; Value: Int64
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_null(
    pContext: pSQLite3Context
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_text(
    pContext: pSQLite3Context; pStr: IntPtr; Size: Integer; pDestrType: IntPtr
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_text16(
    pContext: pSQLite3Context; pStr: IntPtr; Size: Integer; pDestrType: IntPtr
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_text16le(
    pContext: pSQLite3Context; pStr: IntPtr; Size: Integer; pDestrType: IntPtr
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_text16be(
    pContext: pSQLite3Context; pStr: IntPtr; Size: Integer; pDestrType: IntPtr
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_value(
    pContext: pSQLite3Context; Value: pSQLite3Value
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  procedure sqlite3_result_zeroblob(
    pContext: pSQLite3Context; Size: Integer
  ); external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_blob (
    pValue: IntPtr
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_bytes (
    pValue: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_bytes16 (
    pValue: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_double (
    pValue: IntPtr
  ): Double; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_int (
    pValue: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_int64 (
    pValue: IntPtr
  ): Int64; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_text (
    pValue: IntPtr
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_text16 (
    pValue: IntPtr
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_value_type (
    pValue: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_user_data (
    pContext: pSQLite3Context
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_libversion(
  ): IntPtr; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_libversion_number(
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_create_collation(
    pSQLite: pSQLite3; zName: IntPtr; eTextRep: Integer; userData: IntPtr; func: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_create_collation16(
    pSQLite: pSQLite3; zName: IntPtr; eTextRep: Integer; userData: IntPtr; func: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_create_function(
    pSQLite: pSQLite3; zFunctionName: IntPtr; nArg: Integer; eTextRep: Integer; pApp: IntPtr; xFunc: IntPtr; xStep: IntPtr; xFinal: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_create_function16(
    pSQLite: pSQLite3; zFunctionName: IntPtr; nArg: Integer; eTextRep: Integer; pApp: IntPtr; xFunc: IntPtr; xStep: IntPtr; xFinal: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_enable_shared_cache(
    Value: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_enable_load_extension(
    pSQLite: pSQLite3; OnOff: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_busy_timeout(
    pSQLite: pSQLite3; MilliSeconds: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_busy_handler(
    pSQLite: pSQLite3; func: IntPtr; userData: IntPtr
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_key(
    pSQLite: pSQLite3; Key: IntPtr; size: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_key_v2(
    pSQLite: pSQLite3; DbName, Key: IntPtr; size: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_rekey(
    pSQLite: pSQLite3; NewKey: IntPtr; size: Integer
  ): Integer; external;

  [DllImport(SQLiteDLL, CharSet = CharSet.Ansi, SetLastError = True, CallingConvention=CallingConvention.Cdecl)]
  function sqlite3_rekey_v2(
    pSQLite: pSQLite3; DbName, NewKey: IntPtr; size: Integer
  ): Integer; external;

implementation

end.
