Autor Beitrag
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: So 09.10.11 11:27 
Meinte etwas anderes.
Es müssen doch eigentlich nur solche Funktionen
ausblenden Delphi-Quelltext
1:
function SQLite3_Version(): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_libversion';					
in die Klasse, da die aus der DLL stammen. Aber solche function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString; sollen nicht rein. So ist es, oder?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 09.10.11 11:50 
Ach so, doch, die können ja auch rein, die gehören ja dazu, auch wenn sie nicht aus der DLL stammen. Die Kapselung in einer Klasse dient aber auch der Zusammenfassung der Funktionen, deshalb macht es Sinn alles reinzupacken.
(Denn theoretisch würde sich das auch ohne eigene Klasse machen lassen, aber nicht so schön.)
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: So 09.10.11 13:25 
Puuuuh...Fertig! Habe nun alles in der Unit wie beschrieben verändert.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
unit sqlite3;

{$IFDEF FPC}
  {$MODE DELPHI}
  {$H+}            (* use AnsiString *)
  {$PACKENUM 4}    (* use 4-byte enums *)
  {$PACKRECORDS C} (* C/C++-compatible record packing *)
{$ELSE}
  {$MINENUMSIZE 4} (* use 4-byte enums *)
{$ENDIF}

interface

uses SysUtils, Windows;

const
  SQLITE_OK          =  0// Successful result
  (* beginning-of-error-codes *)
  SQLITE_ERROR       =  1// SQL error or missing database
  SQLITE_INTERNAL    =  2// An internal logic error in SQLite
  SQLITE_PERM        =  3// Access permission denied
  SQLITE_ABORT       =  4// Callback routine requested an abort
  SQLITE_BUSY        =  5// The database file is locked
  SQLITE_LOCKED      =  6// A table in the database is locked
  SQLITE_NOMEM       =  7// A malloc() failed
  SQLITE_READONLY    =  8// Attempt to write a readonly database
  SQLITE_INTERRUPT   =  9// Operation terminated by sqlite3_interrupt()
  SQLITE_IOERR       = 10// Some kind of disk I/O error occurred
  SQLITE_CORRUPT     = 11// The database disk image is malformed
  SQLITE_NOTFOUND    = 12// (Internal Only) Table or record not found
  SQLITE_FULL        = 13// Insertion failed because database is full
  SQLITE_CANTOPEN    = 14// Unable to open the database file
  SQLITE_PROTOCOL    = 15// Database lock protocol error
  SQLITE_EMPTY       = 16// Database is empty
  SQLITE_SCHEMA      = 17// The database schema changed
  SQLITE_TOOBIG      = 18// Too much data for one row of a table
  SQLITE_CONSTRAINT  = 19// Abort due to contraint violation
  SQLITE_MISMATCH    = 20// Data type mismatch
  SQLITE_MISUSE      = 21// Library used incorrectly
  SQLITE_NOLFS       = 22// Uses OS features not supported on host
  SQLITE_AUTH        = 23// Authorization denied
  SQLITE_FORMAT      = 24// Auxiliary database format error
  SQLITE_RANGE       = 25// 2nd parameter to sqlite3_bind out of range
  SQLITE_NOTADB      = 26// File opened that is not a database file
  SQLITE_ROW         = 100// sqlite3_step() has another row ready
  SQLITE_DONE        = 101// sqlite3_step() has finished executing

  SQLITE_INTEGER = 1;
  SQLITE_FLOAT   = 2;
  SQLITE_TEXT    = 3;
  SQLITE_BLOB    = 4;
  SQLITE_NULL    = 5;

  SQLITE_UTF8     = 1;
  SQLITE_UTF16    = 2;
  SQLITE_UTF16BE  = 3;
  SQLITE_UTF16LE  = 4;
  SQLITE_ANY      = 5;

  SQLITE_STATIC    {: TSQLite3Destructor} = Pointer(0);
  SQLITE_TRANSIENT {: TSQLite3Destructor} = Pointer(-1);

type
  TSQLiteDB = Pointer;
  TSQLiteResult = ^PAnsiChar;
  TSQLiteStmt = Pointer;

type
  PPAnsiCharArray = ^TPAnsiCharArray; 
  TPAnsiCharArray = array[0 .. (MaxInt div SizeOf(PAnsiChar))-1of PAnsiChar;

type
  TSQLiteExecCallback = function(UserData: Pointer; NumCols: integer; ColValues:
    PPAnsiCharArray; ColNames: PPAnsiCharArray): integer; cdecl;
  TSQLiteBusyHandlerCallback = function(UserData: Pointer; P2: integer): integer; cdecl;

  //function prototype for define own collate
  TCollateXCompare = function(UserData: pointer; Buf1Len: integer; Buf1: pointer;
    Buf2Len: integer; Buf2: pointer): integer; cdecl;

type
  TSQLite3Destructor = procedure(Ptr: Pointer); cdecl;

// Hier deine Klasse
type
  EDLLNotLoadedException = class(Exception)
  public
    constructor Create(const ARoutine: string); overload;
  end;

  TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
  TSQLite3_Close = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_Exec = function(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl;
  TSQLite3_Version = function(): PAnsiChar; cdecl;
  TSQLite3_ErrMsg = function(db: TSQLiteDB): PAnsiChar; cdecl;
  TSQLite3_ErrCode = function(db: TSQLiteDB): integer; cdecl;
  TSQlite3_Free = procedure(P: PAnsiChar); cdecl;
  TSQLite3_GetTable = function(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl;
  TSQLite3_FreeTable = procedure(Table: TSQLiteResult); cdecl;
  TSQLite3_Complete = function(P: PAnsiChar): boolean; cdecl;
  TSQLite3_LastInsertRowID = function(db: TSQLiteDB): int64; cdecl;
  TSQLite3_Interrupt = procedure(db: TSQLiteDB); cdecl;
  TSQLite3_BusyHandler = procedure(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl;
  TSQLite3_BusyTimeout = procedure(db: TSQLiteDB; TimeOut: integer); cdecl;
  TSQLite3_Changes = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_TotalChanges = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_Prepare = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
  TSQLite3_Prepare_v2 = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
  TSQLite3_ColumnCount = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_ColumnName = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_ColumnDeclType = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_Step = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_DataCount = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_ColumnBlob = function(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl;
  TSQLite3_ColumnBytes = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnDouble = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnInt = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnText = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_ColumnType = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnInt64 = function(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl;
  TSQLite3_Finalize = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_Reset = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_bind_blob = function(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
  TSQLite3_bind_text = function(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
  TSQLite3_bind_double = function(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer; cdecl;
  TSQLite3_bind_int = function(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer; cdecl;
  TSQLite3_bind_int64 = function(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer; cdecl;
  TSQLite3_bind_null = function(hStmt: TSqliteStmt; ParamNum: integer): integer; cdecl;
  TSQLite3_bind_parameter_index = function(hStmt: TSqliteStmt; zName: PAnsiChar): integer; cdecl;
  TSQLite3_create_collation = function(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer; cdecl;

  TSQLiteDLLLoader = class
  private
    FSQLiteDLLHandle: THandle;
    FSQLite3_Open: TSQLite3_Open;
    FSQLite3_Close: TSQLite3_Close;
    FSQLite3_Exec: TSQLite3_Exec;
    FSQLite3_Version: TSQLite3_Version;
    FSQLite3_ErrMsg: TSQLite3_ErrMsg;
    FSQLite3_ErrCode: TSQLite3_ErrCode;
    FSQlite3_Free: TSQlite3_Free;
    FSQLite3_GetTable: TSQLite3_GetTable;
    FSQLite3_FreeTable: TSQLite3_FreeTable;
    FSQLite3_Complete: TSQLite3_Complete;
    FSQLite3_LastInsertRowID: TSQLite3_LastInsertRowID;
    FSQLite3_Interrupt: TSQLite3_Interrupt;
    FSQLite3_BusyHandler: TSQLite3_BusyHandler;
    FSQLite3_BusyTimeout: TSQLite3_BusyTimeout;
    FSQLite3_Changes: TSQLite3_Changes;
    FSQLite3_TotalChanges: TSQLite3_TotalChanges;
    FSQLite3_Prepare: TSQLite3_Prepare;
    FSQLite3_Prepare_v2: TSQLite3_Prepare_v2;
    FSQLite3_ColumnCount: TSQLite3_ColumnCount;
    FSQLite3_ColumnName: TSQLite3_ColumnName;
    FSQLite3_ColumnDeclType: TSQLite3_ColumnDeclType;
    FSQLite3_Step: TSQLite3_Step;
    FSQLite3_DataCount: TSQLite3_DataCount;
    FSQLite3_ColumnBlob: TSQLite3_ColumnBlob;
    FSQLite3_ColumnBytes: TSQLite3_ColumnBytes;
    FSQLite3_ColumnDouble: TSQLite3_ColumnDouble;
    FSQLite3_ColumnInt: TSQLite3_ColumnInt;
    FSQLite3_ColumnText: TSQLite3_ColumnText;
    FSQLite3_ColumnType: TSQLite3_ColumnType;
    FSQLite3_ColumnInt64: TSQLite3_ColumnInt64;
    FSQLite3_Finalize: TSQLite3_Finalize;
    FSQLite3_Reset: TSQLite3_Reset;
    FSQLite3_bind_blob: TSQLite3_bind_blob;

    FSQLite3_bind_text: TSQLite3_bind_text;
    FSQLite3_bind_double: TSQLite3_bind_double;
    FSQLite3_bind_int: TSQLite3_bind_int;
    FSQLite3_bind_int64: TSQLite3_bind_int64;
    FSQLite3_bind_null: TSQLite3_bind_null;
    FSQLite3_bind_parameter_index: TSQLite3_bind_parameter_index;
    FSQLite3_create_collation: TSQLite3_create_collation;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
    function SQLite3_Close(db: TSQLiteDB): integer;
    function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
    function SQLite3_Version(): PAnsiChar;
    function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar;
    function SQLite3_ErrCode(db: TSQLiteDB): integer;
    procedure SQlite3_Free(P: PAnsiChar);
    function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
    procedure SQLite3_FreeTable(Table: TSQLiteResult);
    function SQLite3_Complete(P: PAnsiChar): boolean;
    function SQLite3_LastInsertRowID(db: TSQLiteDB): int64;
    procedure SQLite3_Interrupt(db: TSQLiteDB);
    procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
    procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer);
    function SQLite3_Changes(db: TSQLiteDB): integer;
    function SQLite3_TotalChanges(db: TSQLiteDB): integer;
    function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_Step(hStmt: TSqliteStmt): integer;
    function SQLite3_DataCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
    function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
    function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
    function SQLite3_Finalize(hStmt: TSqliteStmt): integer;
    function SQLite3_Reset(hStmt: TSqliteStmt): integer;

    function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
    function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
    function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
    function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
    function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
    function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
    function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
    function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer;
  end;



// Diese Funktionen müssen ja auch noch in die Klasse?

function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;

implementation

// HIER DIE GANZEN FUNKTIONEN UMGESCHRIEBEN


function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
begin
  case SQLiteFieldTypeCode of
    SQLITE_INTEGER: Result := 'Integer';
    SQLITE_FLOAT: Result := 'Float';
    SQLITE_TEXT: Result := 'Text';
    SQLITE_BLOB: Result := 'Blob';
    SQLITE_NULL: Result := 'Null';
  else
    Result := 'Unknown SQLite Field Type Code "' + IntToStr(SQLiteFieldTypeCode) + '"';
  end;
end;

function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;
begin
  case SQLiteErrorCode of
    SQLITE_OK: Result := 'Successful result';
    SQLITE_ERROR: Result := 'SQL error or missing database';
    SQLITE_INTERNAL: Result := 'An internal logic error in SQLite';
    SQLITE_PERM: Result := 'Access permission denied';
    SQLITE_ABORT: Result := 'Callback routine requested an abort';
    SQLITE_BUSY: Result := 'The database file is locked';
    SQLITE_LOCKED: Result := 'A table in the database is locked';
    SQLITE_NOMEM: Result := 'A malloc() failed';
    SQLITE_READONLY: Result := 'Attempt to write a readonly database';
    SQLITE_INTERRUPT: Result := 'Operation terminated by sqlite3_interrupt()';
    SQLITE_IOERR: Result := 'Some kind of disk I/O error occurred';
    SQLITE_CORRUPT: Result := 'The database disk image is malformed';
    SQLITE_NOTFOUND: Result := '(Internal Only) Table or record not found';
    SQLITE_FULL: Result := 'Insertion failed because database is full';
    SQLITE_CANTOPEN: Result := 'Unable to open the database file';
    SQLITE_PROTOCOL: Result := 'Database lock protocol error';
    SQLITE_EMPTY: Result := 'Database is empty';
    SQLITE_SCHEMA: Result := 'The database schema changed';
    SQLITE_TOOBIG: Result := 'Too much data for one row of a table';
    SQLITE_CONSTRAINT: Result := 'Abort due to contraint violation';
    SQLITE_MISMATCH: Result := 'Data type mismatch';
    SQLITE_MISUSE: Result := 'Library used incorrectly';
    SQLITE_NOLFS: Result := 'Uses OS features not supported on host';
    SQLITE_AUTH: Result := 'Authorization denied';
    SQLITE_FORMAT: Result := 'Auxiliary database format error';
    SQLITE_RANGE: Result := '2nd parameter to sqlite3_bind out of range';
    SQLITE_NOTADB: Result := 'File opened that is not a database file';
    SQLITE_ROW: Result := 'sqlite3_step() has another row ready';
    SQLITE_DONE: Result := 'sqlite3_step() has finished executing';
  else
    Result := 'Unknown SQLite Error Code "' + IntToStr(SQLiteErrorCode) + '"';
  end;
end;

function ColValueToStr(Value: PAnsiChar): AnsiString;
begin
  if (Value = nilthen
    Result := 'NULL'
  else
    Result := Value;
end;

constructor EDLLNotLoadedException.Create(const ARoutine: string);
begin
  inherited Create('The SQLite library was not loaded before calling ' + ARoutine);
end;
  
function TSQLiteDLLLoader.LoadDLL(ADLLPath: string): Boolean;
begin
  FSQLiteDLLHandle := LoadLibrary(PChar(ADLLPath));
  Result := FSQLiteDLLHandle <> 0;
  if Result then
  begin
    @FSQLite3_Open := GetProcAddress(FSQLiteDLLHandle, 'SQLite3_Open');
  end;
end;

procedure TSQLiteDLLLoader.UnloadDLL;
begin
  if FSQLiteDLLHandle <> 0 then
  begin
    FreeLibrary(FSQLiteDLLHandle);
    FSQLiteDLLHandle := 0;
  end;
end;

function TSQLiteDLLLoader.SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
begin
  if Assigned(FSQLite3_Open) then
    Result := FSQLite3_Open(PAnsiChar(AFilename), db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;

function TSQLiteDLLLoader.SQLite3_Close(db: TSQLiteDB): integer;
begin
  if Assigned(FSQLite3_Close) then
   Result := FSQLite3_Close(db)
  else
   raise EDLLNotLoadedException.Create('SQLite3_Close');
end;

function TSQLiteDLLLoader.SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_Exec) then
   Result := FSQLite3_Exec(db, SQLStatement, CallbackPtr, UserData, ErrMsg)
  else
   raise EDLLNotLoadedException.Create('SQLite3_Exec');
end;

function TSQLiteDLLLoader.SQLite3_Version(): PAnsiChar;
begin
  if Assigned(FSQLite3_Version) then
    Result := FSQLite3_Version()
  else
    raise EDLLNotLoadedException.Create('SQLite3_Version');
end;

function TSQLiteDLLLoader.SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar;
begin
  if Assigned(FSQLite3_ErrMsg) then
    Result := FSQLite3_ErrMsg(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ErrMsg');
end;
function TSQLiteDLLLoader.SQLite3_ErrCode(db: TSQLiteDB): integer;
begin
  if Assigned(FSQLite3_ErrCode) then
    Result := FSQLite3_ErrCode(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ErrCode');
end;

procedure TSQLiteDLLLoader.SQlite3_Free(P: PAnsiChar);
begin
  if Assigned(FSQlite3_Free) then
    FSQlite3_Free(P)
  else
    raise EDLLNotLoadedException.Create('SQlite3_Free');
end;

function TSQLiteDLLLoader.SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_GetTable) then
    Result := FSQLite3_GetTable(db, SQLStatement, ResultPtr, Rowcount, ColCount, ErrMsg)
  else
    raise EDLLNotLoadedException.Create('SQLite3_GetTable');
end;

procedure TSQLiteDLLLoader.SQLite3_FreeTable(Table: TSQLiteResult);
begin
  if Assigned(FSQLite3_FreeTable) then
    FSQLite3_FreeTable(Table)
  else
    raise EDLLNotLoadedException.Create('SQLite3_FreeTable');
end;

function TSQLiteDLLLoader.SQLite3_Complete(P: PAnsiChar): boolean;
begin
  if Assigned(FSQLite3_Complete) then
    Result := FSQLite3_Complete(P)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Complete');
end;

function TSQLiteDLLLoader.SQLite3_LastInsertRowID(db: TSQLiteDB): int64;
begin
 if Assigned(FSQLite3_LastInsertRowID) then
   Result := FSQLite3_LastInsertRowID(db)
 else
   raise EDLLNotLoadedException.Create('SQLite3_LastInsertRowID');
end;

procedure TSQLiteDLLLoader.SQLite3_Interrupt(db: TSQLiteDB);
begin
 if Assigned(FSQLite3_Interrupt) then
   FSQLite3_Interrupt(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Interrupt');
end;

procedure TSQLiteDLLLoader.SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
begin
  if Assigned(FSQLite3_BusyHandler) then
    FSQLite3_BusyHandler(db, CallbackPtr, UserData)
  else
    raise EDLLNotLoadedException.Create('SQLite3_BusyHandler');
end;

procedure TSQLiteDLLLoader.SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer);
begin
  if Assigned(FSQLite3_BusyTimeout) then
    FSQLite3_BusyTimeout(db, TimeOut)
  else
    raise EDLLNotLoadedException.Create('SQLite3_BusyTimeout');
end;

function TSQLiteDLLLoader.SQLite3_Changes(db: TSQLiteDB): integer;
begin
  if Assigned(FSQLite3_Changes) then
    Result := FSQLite3_Changes(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Changes');
end;

function TSQLiteDLLLoader.SQLite3_TotalChanges(db: TSQLiteDB): integer;
 begin
  if Assigned(FSQLite3_TotalChanges) then
    Result := FSQLite3_TotalChanges(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_TotalChanges');
end;

function TSQLiteDLLLoader.SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_Prepare) then
    Result := FSQLite3_Prepare(db, SQLStatement, nBytes, hStmt, pzTail)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Prepare');
end;

function TSQLiteDLLLoader.SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_Prepare_v2) then
    Result := FSQLite3_Prepare_v2(db, SQLStatement, nBytes, hStmt, pzTail)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Prepare_v2');
end;

function TSQLiteDLLLoader.SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_ColumnCount) then
    Result := FSQLite3_ColumnCount(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnCount');
end;

function TSQLiteDLLLoader.SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
begin
  if Assigned(FSQLite3_ColumnName) then
    Result := FSQLite3_ColumnName(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnName');
end;

function TSQLiteDLLLoader.SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
begin
  if Assigned(FSQLite3_ColumnDeclType) then
    Result := FSQLite3_ColumnDeclType(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnDeclType');
end;

function TSQLiteDLLLoader.SQLite3_Step(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_Step) then
    Result := FSQLite3_Step(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Step');
end;

function TSQLiteDLLLoader.SQLite3_DataCount(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_DataCount) then
    Result := FSQLite3_DataCount(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_DataCount');
end;

function TSQLiteDLLLoader.SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
begin
  if Assigned(FSQLite3_ColumnBlob) then
    Result := FSQLite3_ColumnBlob(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnBlob');
end;

function TSQLiteDLLLoader.SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
begin
  if Assigned(FSQLite3_ColumnBytes) then
    Result := FSQLite3_ColumnBytes(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnBytes');
end;

function TSQLiteDLLLoader.SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
 begin
  if Assigned(FSQLite3_ColumnBytes) then
    Result := FSQLite3_ColumnBytes(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnBytes');
end;

function TSQLiteDLLLoader.SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
 begin
  if Assigned(FSQLite3_ColumnInt) then
    Result := FSQLite3_ColumnInt(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnInt');
end;

function TSQLiteDLLLoader.SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
begin
  if Assigned(FSQLite3_ColumnText) then
    Result := FSQLite3_ColumnText(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnText');
end;

function TSQLiteDLLLoader.SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
begin
  if Assigned(FSQLite3_ColumnType) then
    Result := FSQLite3_ColumnType(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnType');
end;

function TSQLiteDLLLoader.SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
begin
  if Assigned(FSQLite3_ColumnInt64) then
    Result := FSQLite3_ColumnInt64(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnInt64');
end;

function TSQLiteDLLLoader.SQLite3_Finalize(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_Finalize) then
    Result := FSQLite3_Finalize(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;

function TSQLiteDLLLoader.SQLite3_Reset(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_Reset) then
    Result := FSQLite3_Reset(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;

function TSQLiteDLLLoader.SQLite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
begin
  if Assigned(FSQLite3_bind_blob) then
    Result := FSQLite3_bind_blob(hStmt, ParamNum, ptrData, numBytes, ptrDestructor)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_blob');
end;

function TSQLiteDLLLoader.SQLite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
begin
  if Assigned(FSQLite3_bind_text) then
    Result := FSQLite3_bind_text(hStmt, ParamNum, Text, numBytes, ptrDestructor)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_text');
end;

function TSQLiteDLLLoader.SQLite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
begin
  if Assigned(FSQLite3_bind_double) then
    Result := FSQLite3_bind_double(hStmt, ParamNum, Data)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_double');
end;

function TSQLiteDLLLoader.SQLite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
begin
  if Assigned(FSQLite3_bind_int) then
    Result := FSQLite3_bind_int(hStmt, ParamNum, Data)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_int');
end;

function TSQLiteDLLLoader.SQLite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
begin
  if Assigned(FSQLite3_bind_int64) then
    Result := FSQLite3_bind_int64(hStmt, ParamNum, Data)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_int64');
end;

function TSQLiteDLLLoader.SQLite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
begin
  if Assigned(FSQLite3_bind_null) then
    Result := FSQLite3_bind_null(hStmt, ParamNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_null');
end;

function TSQLiteDLLLoader.SQLite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
 begin
  if Assigned(FSQLite3_bind_parameter_index) then
    Result := FSQLite3_bind_parameter_index(hStmt, zName)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_parameter_index');
end;

function TSQLiteDLLLoader.SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer;
begin
  if Assigned(FSQLite3_create_collation) then
    Result := FSQLite3_create_collation(db, Name, eTextRep, UserData, xCompare)
  else
    raise EDLLNotLoadedException.Create('SQLite3_create_collation');
end;

end.

Das kompilieren funktionier auch wunderbar. Nur beim gebrauch hakt es noch. So versuche ichs im Moment:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
begin
 DLLLoad:= TSQLiteDLLLoader.Create;
 DLLLoad.LoadDLL('C:\Users\Username\AppData\Local\Temp\SQLite3.dll');
 Start; // Irgendeine Procedure, die die DLL brauch
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 DLLLoad.UnloadDLL;
end;

Wenn ich das so mache, gibt die Fehlermedlung "The SQLite library was not loaded before calling SQLite3_Open".
Wie muss ich die Procedure dann aufrufen?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 09.10.11 13:56 
Erstens hast du vergessen auch die anderen Funktionen in LoadDLL zu laden und zweitens habe ich gerade nochmal ins Original geschaut, die Funktionsnamen in der DLL sind ja kleingeschrieben, also muss das auch so heißen. Außerdem hatte ich vergessen Result nochmal ggf. zu korrigieren. Aber den Rückghabewert von LoadDLL hast du ja in deinem Quelltext ohnehin weggeworfen und nicht geprüft.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function TSQLiteDLLLoader.LoadDLL(ADLLPath: string): Boolean;
begin
  FSQLiteDLLHandle := LoadLibrary(PChar(ADLLPath));
  Result := FSQLiteDLLHandle <> 0;
  if Result then
  begin
    @FSQLite3_Open := GetProcAddress(FSQLiteDLLHandle, 'sqlite3_open');
    @...

    Result := Assigned(FSQLite3_Open) and Assigned...
  end;
end;
// EDIT:
Nebenbei würde ich PAnsiChar überall durch AnsiString ersetzen in den Aufrufen von außen. Dann kannst du das immer an die Original-DLL-Funktion per Cast weitergeben, aber nach außen sind es normale Delphi-AnsiStrings. Das macht den Aufruf einfacher, deshalb hatte ich das auch so gemacht im Beispiel.
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: So 09.10.11 14:31 
Oke, habe ich nun auch erledigt:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
unit sqlite3;

{$IFDEF FPC}
  {$MODE DELPHI}
  {$H+}            (* use AnsiString *)
  {$PACKENUM 4}    (* use 4-byte enums *)
  {$PACKRECORDS C} (* C/C++-compatible record packing *)
{$ELSE}
  {$MINENUMSIZE 4} (* use 4-byte enums *)
{$ENDIF}

interface

uses SysUtils, Windows;

const
  SQLITE_OK          =  0// Successful result
  (* beginning-of-error-codes *)
  SQLITE_ERROR       =  1// SQL error or missing database
  SQLITE_INTERNAL    =  2// An internal logic error in SQLite
  SQLITE_PERM        =  3// Access permission denied
  SQLITE_ABORT       =  4// Callback routine requested an abort
  SQLITE_BUSY        =  5// The database file is locked
  SQLITE_LOCKED      =  6// A table in the database is locked
  SQLITE_NOMEM       =  7// A malloc() failed
  SQLITE_READONLY    =  8// Attempt to write a readonly database
  SQLITE_INTERRUPT   =  9// Operation terminated by sqlite3_interrupt()
  SQLITE_IOERR       = 10// Some kind of disk I/O error occurred
  SQLITE_CORRUPT     = 11// The database disk image is malformed
  SQLITE_NOTFOUND    = 12// (Internal Only) Table or record not found
  SQLITE_FULL        = 13// Insertion failed because database is full
  SQLITE_CANTOPEN    = 14// Unable to open the database file
  SQLITE_PROTOCOL    = 15// Database lock protocol error
  SQLITE_EMPTY       = 16// Database is empty
  SQLITE_SCHEMA      = 17// The database schema changed
  SQLITE_TOOBIG      = 18// Too much data for one row of a table
  SQLITE_CONSTRAINT  = 19// Abort due to contraint violation
  SQLITE_MISMATCH    = 20// Data type mismatch
  SQLITE_MISUSE      = 21// Library used incorrectly
  SQLITE_NOLFS       = 22// Uses OS features not supported on host
  SQLITE_AUTH        = 23// Authorization denied
  SQLITE_FORMAT      = 24// Auxiliary database format error
  SQLITE_RANGE       = 25// 2nd parameter to sqlite3_bind out of range
  SQLITE_NOTADB      = 26// File opened that is not a database file
  SQLITE_ROW         = 100// sqlite3_step() has another row ready
  SQLITE_DONE        = 101// sqlite3_step() has finished executing

  SQLITE_INTEGER = 1;
  SQLITE_FLOAT   = 2;
  SQLITE_TEXT    = 3;
  SQLITE_BLOB    = 4;
  SQLITE_NULL    = 5;

  SQLITE_UTF8     = 1;
  SQLITE_UTF16    = 2;
  SQLITE_UTF16BE  = 3;
  SQLITE_UTF16LE  = 4;
  SQLITE_ANY      = 5;

  SQLITE_STATIC    {: TSQLite3Destructor} = Pointer(0);
  SQLITE_TRANSIENT {: TSQLite3Destructor} = Pointer(-1);

type
  TSQLiteDB = Pointer;
  TSQLiteResult = ^PAnsiChar;
  TSQLiteStmt = Pointer;

type
  PPAnsiCharArray = ^TPAnsiCharArray; 
  TPAnsiCharArray = array[0 .. (MaxInt div SizeOf(PAnsiChar))-1of PAnsiChar;

type
  TSQLiteExecCallback = function(UserData: Pointer; NumCols: integer; ColValues:
    PPAnsiCharArray; ColNames: PPAnsiCharArray): integer; cdecl;
  TSQLiteBusyHandlerCallback = function(UserData: Pointer; P2: integer): integer; cdecl;

  //function prototype for define own collate
  TCollateXCompare = function(UserData: pointer; Buf1Len: integer; Buf1: pointer;
    Buf2Len: integer; Buf2: pointer): integer; cdecl;

type
  TSQLite3Destructor = procedure(Ptr: Pointer); cdecl;

// Hier deine Klasse
type
  EDLLNotLoadedException = class(Exception)
  public
    constructor Create(const ARoutine: string); overload;
  end;

  TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
  TSQLite3_Close = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_Exec = function(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl;
  TSQLite3_Version = function(): PAnsiChar; cdecl;
  TSQLite3_ErrMsg = function(db: TSQLiteDB): PAnsiChar; cdecl;
  TSQLite3_ErrCode = function(db: TSQLiteDB): integer; cdecl;
  TSQlite3_Free = procedure(P: PAnsiChar); cdecl;
  TSQLite3_GetTable = function(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl;
  TSQLite3_FreeTable = procedure(Table: TSQLiteResult); cdecl;
  TSQLite3_Complete = function(P: PAnsiChar): boolean; cdecl;
  TSQLite3_LastInsertRowID = function(db: TSQLiteDB): int64; cdecl;
  TSQLite3_Interrupt = procedure(db: TSQLiteDB); cdecl;
  TSQLite3_BusyHandler = procedure(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl;
  TSQLite3_BusyTimeout = procedure(db: TSQLiteDB; TimeOut: integer); cdecl;
  TSQLite3_Changes = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_TotalChanges = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_Prepare = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
  TSQLite3_Prepare_v2 = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
  TSQLite3_ColumnCount = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_ColumnName = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_ColumnDeclType = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_Step = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_DataCount = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_ColumnBlob = function(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl;
  TSQLite3_ColumnBytes = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnDouble = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnInt = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnText = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_ColumnType = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnInt64 = function(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl;
  TSQLite3_Finalize = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_Reset = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_bind_blob = function(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
  TSQLite3_bind_text = function(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
  TSQLite3_bind_double = function(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer; cdecl;
  TSQLite3_bind_int = function(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer; cdecl;
  TSQLite3_bind_int64 = function(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer; cdecl;
  TSQLite3_bind_null = function(hStmt: TSqliteStmt; ParamNum: integer): integer; cdecl;
  TSQLite3_bind_parameter_index = function(hStmt: TSqliteStmt; zName: PAnsiChar): integer; cdecl;
  TSQLite3_create_collation = function(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer; cdecl;

  TSQLiteDLLLoader = class
  private
    FSQLiteDLLHandle: THandle;
    FSQLite3_Open: TSQLite3_Open;
    FSQLite3_Close: TSQLite3_Close;
    FSQLite3_Exec: TSQLite3_Exec;
    FSQLite3_Version: TSQLite3_Version;
    FSQLite3_ErrMsg: TSQLite3_ErrMsg;
    FSQLite3_ErrCode: TSQLite3_ErrCode;
    FSQlite3_Free: TSQlite3_Free;
    FSQLite3_GetTable: TSQLite3_GetTable;
    FSQLite3_FreeTable: TSQLite3_FreeTable;
    FSQLite3_Complete: TSQLite3_Complete;
    FSQLite3_LastInsertRowID: TSQLite3_LastInsertRowID;
    FSQLite3_Interrupt: TSQLite3_Interrupt;
    FSQLite3_BusyHandler: TSQLite3_BusyHandler;
    FSQLite3_BusyTimeout: TSQLite3_BusyTimeout;
    FSQLite3_Changes: TSQLite3_Changes;
    FSQLite3_TotalChanges: TSQLite3_TotalChanges;
    FSQLite3_Prepare: TSQLite3_Prepare;
    FSQLite3_Prepare_v2: TSQLite3_Prepare_v2;
    FSQLite3_ColumnCount: TSQLite3_ColumnCount;
    FSQLite3_ColumnName: TSQLite3_ColumnName;
    FSQLite3_ColumnDeclType: TSQLite3_ColumnDeclType;
    FSQLite3_Step: TSQLite3_Step;
    FSQLite3_DataCount: TSQLite3_DataCount;
    FSQLite3_ColumnBlob: TSQLite3_ColumnBlob;
    FSQLite3_ColumnBytes: TSQLite3_ColumnBytes;
    FSQLite3_ColumnDouble: TSQLite3_ColumnDouble;
    FSQLite3_ColumnInt: TSQLite3_ColumnInt;
    FSQLite3_ColumnText: TSQLite3_ColumnText;
    FSQLite3_ColumnType: TSQLite3_ColumnType;
    FSQLite3_ColumnInt64: TSQLite3_ColumnInt64;
    FSQLite3_Finalize: TSQLite3_Finalize;
    FSQLite3_Reset: TSQLite3_Reset;
    FSQLite3_bind_blob: TSQLite3_bind_blob;

    FSQLite3_bind_text: TSQLite3_bind_text;
    FSQLite3_bind_double: TSQLite3_bind_double;
    FSQLite3_bind_int: TSQLite3_bind_int;
    FSQLite3_bind_int64: TSQLite3_bind_int64;
    FSQLite3_bind_null: TSQLite3_bind_null;
    FSQLite3_bind_parameter_index: TSQLite3_bind_parameter_index;
    FSQLite3_create_collation: TSQLite3_create_collation;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
    function SQLite3_Close(db: TSQLiteDB): integer;
    function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
    function SQLite3_Version(): PAnsiChar;
    function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar;
    function SQLite3_ErrCode(db: TSQLiteDB): integer;
    procedure SQlite3_Free(P: PAnsiChar);
    function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
    procedure SQLite3_FreeTable(Table: TSQLiteResult);
    function SQLite3_Complete(P: PAnsiChar): boolean;
    function SQLite3_LastInsertRowID(db: TSQLiteDB): int64;
    procedure SQLite3_Interrupt(db: TSQLiteDB);
    procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
    procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer);
    function SQLite3_Changes(db: TSQLiteDB): integer;
    function SQLite3_TotalChanges(db: TSQLiteDB): integer;
    function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_Step(hStmt: TSqliteStmt): integer;
    function SQLite3_DataCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
    function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
    function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
    function SQLite3_Finalize(hStmt: TSqliteStmt): integer;
    function SQLite3_Reset(hStmt: TSqliteStmt): integer;

    function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
    function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
    function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
    function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
    function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
    function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
    function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
    function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer;
  end;



// Diese Funktionen müssen ja auch noch in die Klasse?

function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;

implementation

// HIER DIE GANZEN FUNKTIONEN UMGESCHRIEBEN


function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
begin
  case SQLiteFieldTypeCode of
    SQLITE_INTEGER: Result := 'Integer';
    SQLITE_FLOAT: Result := 'Float';
    SQLITE_TEXT: Result := 'Text';
    SQLITE_BLOB: Result := 'Blob';
    SQLITE_NULL: Result := 'Null';
  else
    Result := 'Unknown SQLite Field Type Code "' + IntToStr(SQLiteFieldTypeCode) + '"';
  end;
end;

function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;
begin
  case SQLiteErrorCode of
    SQLITE_OK: Result := 'Successful result';
    SQLITE_ERROR: Result := 'SQL error or missing database';
    SQLITE_INTERNAL: Result := 'An internal logic error in SQLite';
    SQLITE_PERM: Result := 'Access permission denied';
    SQLITE_ABORT: Result := 'Callback routine requested an abort';
    SQLITE_BUSY: Result := 'The database file is locked';
    SQLITE_LOCKED: Result := 'A table in the database is locked';
    SQLITE_NOMEM: Result := 'A malloc() failed';
    SQLITE_READONLY: Result := 'Attempt to write a readonly database';
    SQLITE_INTERRUPT: Result := 'Operation terminated by sqlite3_interrupt()';
    SQLITE_IOERR: Result := 'Some kind of disk I/O error occurred';
    SQLITE_CORRUPT: Result := 'The database disk image is malformed';
    SQLITE_NOTFOUND: Result := '(Internal Only) Table or record not found';
    SQLITE_FULL: Result := 'Insertion failed because database is full';
    SQLITE_CANTOPEN: Result := 'Unable to open the database file';
    SQLITE_PROTOCOL: Result := 'Database lock protocol error';
    SQLITE_EMPTY: Result := 'Database is empty';
    SQLITE_SCHEMA: Result := 'The database schema changed';
    SQLITE_TOOBIG: Result := 'Too much data for one row of a table';
    SQLITE_CONSTRAINT: Result := 'Abort due to contraint violation';
    SQLITE_MISMATCH: Result := 'Data type mismatch';
    SQLITE_MISUSE: Result := 'Library used incorrectly';
    SQLITE_NOLFS: Result := 'Uses OS features not supported on host';
    SQLITE_AUTH: Result := 'Authorization denied';
    SQLITE_FORMAT: Result := 'Auxiliary database format error';
    SQLITE_RANGE: Result := '2nd parameter to sqlite3_bind out of range';
    SQLITE_NOTADB: Result := 'File opened that is not a database file';
    SQLITE_ROW: Result := 'sqlite3_step() has another row ready';
    SQLITE_DONE: Result := 'sqlite3_step() has finished executing';
  else
    Result := 'Unknown SQLite Error Code "' + IntToStr(SQLiteErrorCode) + '"';
  end;
end;

function ColValueToStr(Value: PAnsiChar): AnsiString;
begin
  if (Value = nilthen
    Result := 'NULL'
  else
    Result := Value;
end;

constructor EDLLNotLoadedException.Create(const ARoutine: string);
begin
  inherited Create('The SQLite library was not loaded before calling ' + ARoutine);
end;

function TSQLiteDLLLoader.LoadDLL(ADLLPath: string): Boolean;
begin
  FSQLiteDLLHandle := LoadLibrary(PChar(ADLLPath));
  Result := FSQLiteDLLHandle <> 0;
  if Result then
  begin
    @FSQLite3_Open:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_open');
    @FSQLite3_Close:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_close');
    @FSQLite3_Exec:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_exec');
    @FSQLite3_Version:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_version');
    @FSQLite3_ErrMsg:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_errmsg');
    @FSQLite3_ErrCode:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_errcode');
    @FSQLite3_Free:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_free');
    @FSQLite3_GetTable:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_gettable');
    @FSQLite3_FreeTable:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_freetable');
    @FSQLite3_Complete:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_complete');
    @FSQLite3_LastInsertRowID:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_lastinsertrowid');
    @FSQLite3_Interrupt:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_interrupt');
    @FSQLite3_BusyHandler:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_busyhandler');
    @FSQLite3_BusyTimeout:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_busytimeout');
    @FSQLite3_Changes:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_changes');
    @FSQLite3_TotalChanges:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_totalchanges');
    @FSQLite3_Prepare:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_prepare');
    @FSQLite3_Prepare_v2:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_prepare_v2');
    @FSQLite3_ColumnCount:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columncount');
    @FSQLite3_ColumnName:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columnname');
    @FSQLite3_ColumnDeclType:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columndecltype');
    @FSQLite3_Step:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_step');
    @FSQLite3_DataCount:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_datacount');
    @FSQLite3_ColumnBlob:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columnblob');
    @FSQLite3_ColumnBytes:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columnbytes');
    @FSQLite3_ColumnDouble:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columndouble');
    @FSQLite3_ColumnInt:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columnint');
    @FSQLite3_ColumnText:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columntext');
    @FSQLite3_ColumnType:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columntype');
    @FSQLite3_ColumnInt64:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_columnint64');
    @FSQLite3_Finalize:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_finalize');
    @FSQLite3_Reset:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_reset');
    @FSQLite3_bind_blob:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_blob');
    @FSQLite3_bind_text:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_text');
    @FSQLite3_bind_double:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_double');
    @FSQLite3_bind_int:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_int');
    @FSQLite3_bind_int64:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_int64');
    @FSQLite3_bind_null:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_null');
    @FSQLite3_bind_parameter_index:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_bind_parameter_index');
    @FSQLite3_create_collation:= GetProcAddress(FSQLiteDLLHandle, 'sqlite3_create_collation');

    Result := Assigned(FSQLite3_Open) and Assigned(FSQLite3_Close) and Assigned(FSQLite3_Exec)
              and Assigned(FSQLite3_Version) and Assigned(FSQLite3_ErrMsg) and Assigned(FSQLite3_ErrCode)
              and Assigned(FSQLite3_Free) and Assigned(FSQLite3_GetTable) and Assigned(FSQLite3_FreeTable)
              and Assigned(FSQLite3_Complete) and Assigned(FSQLite3_LastInsertRowID) and Assigned(FSQLite3_Interrupt)
              and Assigned(FSQLite3_BusyHandler) and Assigned(FSQLite3_BusyTimeout) and Assigned(FSQLite3_Changes)
              and Assigned(FSQLite3_TotalChanges) and Assigned(FSQLite3_Prepare) and Assigned(FSQLite3_Prepare_v2)
              and Assigned(FSQLite3_ColumnCount) and Assigned(FSQLite3_ColumnName) and Assigned(FSQLite3_ColumnDeclType)
              and Assigned(FSQLite3_Step) and Assigned(FSQLite3_DataCount) and Assigned(FSQLite3_ColumnBlob)
              and Assigned(FSQLite3_ColumnBytes) and Assigned(FSQLite3_ColumnDouble) and Assigned(FSQLite3_ColumnInt)
              and Assigned(FSQLite3_ColumnText) and Assigned(FSQLite3_ColumnType) and Assigned(FSQLite3_ColumnInt64)
              and Assigned(FSQLite3_Finalize) and Assigned(FSQLite3_Reset) and Assigned(FSQLite3_bind_blob)
              and Assigned(FSQLite3_bind_text) and Assigned(FSQLite3_bind_double) and Assigned(FSQLite3_bind_int)
              and Assigned(FSQLite3_bind_int64) and Assigned(FSQLite3_bind_null) and Assigned(FSQLite3_bind_parameter_index)
              and Assigned(FSQLite3_create_collation);
  end;
end;


procedure TSQLiteDLLLoader.UnloadDLL;
begin
  if FSQLiteDLLHandle <> 0 then
  begin
    FreeLibrary(FSQLiteDLLHandle);
    FSQLiteDLLHandle := 0;
  end;
end;

function TSQLiteDLLLoader.SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
begin
  if Assigned(FSQLite3_Open) then
    Result := FSQLite3_Open(PAnsiChar(AFilename), db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;

function TSQLiteDLLLoader.SQLite3_Close(db: TSQLiteDB): integer;
begin
  if Assigned(FSQLite3_Close) then
   Result := FSQLite3_Close(db)
  else
   raise EDLLNotLoadedException.Create('SQLite3_Close');
end;

function TSQLiteDLLLoader.SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_Exec) then
   Result := FSQLite3_Exec(db, SQLStatement, CallbackPtr, UserData, ErrMsg)
  else
   raise EDLLNotLoadedException.Create('SQLite3_Exec');
end;

function TSQLiteDLLLoader.SQLite3_Version(): PAnsiChar;
begin
  if Assigned(FSQLite3_Version) then
    Result := FSQLite3_Version()
  else
    raise EDLLNotLoadedException.Create('SQLite3_Version');
end;

function TSQLiteDLLLoader.SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar;
begin
  if Assigned(FSQLite3_ErrMsg) then
    Result := FSQLite3_ErrMsg(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ErrMsg');
end;
function TSQLiteDLLLoader.SQLite3_ErrCode(db: TSQLiteDB): integer;
begin
  if Assigned(FSQLite3_ErrCode) then
    Result := FSQLite3_ErrCode(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ErrCode');
end;

procedure TSQLiteDLLLoader.SQlite3_Free(P: PAnsiChar);
begin
  if Assigned(FSQlite3_Free) then
    FSQlite3_Free(P)
  else
    raise EDLLNotLoadedException.Create('SQlite3_Free');
end;

function TSQLiteDLLLoader.SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_GetTable) then
    Result := FSQLite3_GetTable(db, SQLStatement, ResultPtr, Rowcount, ColCount, ErrMsg)
  else
    raise EDLLNotLoadedException.Create('SQLite3_GetTable');
end;

procedure TSQLiteDLLLoader.SQLite3_FreeTable(Table: TSQLiteResult);
begin
  if Assigned(FSQLite3_FreeTable) then
    FSQLite3_FreeTable(Table)
  else
    raise EDLLNotLoadedException.Create('SQLite3_FreeTable');
end;

function TSQLiteDLLLoader.SQLite3_Complete(P: PAnsiChar): boolean;
begin
  if Assigned(FSQLite3_Complete) then
    Result := FSQLite3_Complete(P)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Complete');
end;

function TSQLiteDLLLoader.SQLite3_LastInsertRowID(db: TSQLiteDB): int64;
begin
 if Assigned(FSQLite3_LastInsertRowID) then
   Result := FSQLite3_LastInsertRowID(db)
 else
   raise EDLLNotLoadedException.Create('SQLite3_LastInsertRowID');
end;

procedure TSQLiteDLLLoader.SQLite3_Interrupt(db: TSQLiteDB);
begin
 if Assigned(FSQLite3_Interrupt) then
   FSQLite3_Interrupt(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Interrupt');
end;

procedure TSQLiteDLLLoader.SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
begin
  if Assigned(FSQLite3_BusyHandler) then
    FSQLite3_BusyHandler(db, CallbackPtr, UserData)
  else
    raise EDLLNotLoadedException.Create('SQLite3_BusyHandler');
end;

procedure TSQLiteDLLLoader.SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer);
begin
  if Assigned(FSQLite3_BusyTimeout) then
    FSQLite3_BusyTimeout(db, TimeOut)
  else
    raise EDLLNotLoadedException.Create('SQLite3_BusyTimeout');
end;

function TSQLiteDLLLoader.SQLite3_Changes(db: TSQLiteDB): integer;
begin
  if Assigned(FSQLite3_Changes) then
    Result := FSQLite3_Changes(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Changes');
end;

function TSQLiteDLLLoader.SQLite3_TotalChanges(db: TSQLiteDB): integer;
 begin
  if Assigned(FSQLite3_TotalChanges) then
    Result := FSQLite3_TotalChanges(db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_TotalChanges');
end;

function TSQLiteDLLLoader.SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_Prepare) then
    Result := FSQLite3_Prepare(db, SQLStatement, nBytes, hStmt, pzTail)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Prepare');
end;

function TSQLiteDLLLoader.SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
begin
  if Assigned(FSQLite3_Prepare_v2) then
    Result := FSQLite3_Prepare_v2(db, SQLStatement, nBytes, hStmt, pzTail)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Prepare_v2');
end;

function TSQLiteDLLLoader.SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_ColumnCount) then
    Result := FSQLite3_ColumnCount(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnCount');
end;

function TSQLiteDLLLoader.SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
begin
  if Assigned(FSQLite3_ColumnName) then
    Result := FSQLite3_ColumnName(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnName');
end;

function TSQLiteDLLLoader.SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
begin
  if Assigned(FSQLite3_ColumnDeclType) then
    Result := FSQLite3_ColumnDeclType(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnDeclType');
end;

function TSQLiteDLLLoader.SQLite3_Step(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_Step) then
    Result := FSQLite3_Step(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Step');
end;

function TSQLiteDLLLoader.SQLite3_DataCount(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_DataCount) then
    Result := FSQLite3_DataCount(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_DataCount');
end;

function TSQLiteDLLLoader.SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
begin
  if Assigned(FSQLite3_ColumnBlob) then
    Result := FSQLite3_ColumnBlob(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnBlob');
end;

function TSQLiteDLLLoader.SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
begin
  if Assigned(FSQLite3_ColumnBytes) then
    Result := FSQLite3_ColumnBytes(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnBytes');
end;

function TSQLiteDLLLoader.SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
 begin
  if Assigned(FSQLite3_ColumnBytes) then
    Result := FSQLite3_ColumnBytes(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnBytes');
end;

function TSQLiteDLLLoader.SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
 begin
  if Assigned(FSQLite3_ColumnInt) then
    Result := FSQLite3_ColumnInt(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnInt');
end;

function TSQLiteDLLLoader.SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
begin
  if Assigned(FSQLite3_ColumnText) then
    Result := FSQLite3_ColumnText(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnText');
end;

function TSQLiteDLLLoader.SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
begin
  if Assigned(FSQLite3_ColumnType) then
    Result := FSQLite3_ColumnType(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnType');
end;

function TSQLiteDLLLoader.SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
begin
  if Assigned(FSQLite3_ColumnInt64) then
    Result := FSQLite3_ColumnInt64(hStmt, ColNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_ColumnInt64');
end;

function TSQLiteDLLLoader.SQLite3_Finalize(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_Finalize) then
    Result := FSQLite3_Finalize(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;

function TSQLiteDLLLoader.SQLite3_Reset(hStmt: TSqliteStmt): integer;
begin
  if Assigned(FSQLite3_Reset) then
    Result := FSQLite3_Reset(hStmt)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;

function TSQLiteDLLLoader.SQLite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
begin
  if Assigned(FSQLite3_bind_blob) then
    Result := FSQLite3_bind_blob(hStmt, ParamNum, ptrData, numBytes, ptrDestructor)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_blob');
end;

function TSQLiteDLLLoader.SQLite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
begin
  if Assigned(FSQLite3_bind_text) then
    Result := FSQLite3_bind_text(hStmt, ParamNum, Text, numBytes, ptrDestructor)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_text');
end;

function TSQLiteDLLLoader.SQLite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
begin
  if Assigned(FSQLite3_bind_double) then
    Result := FSQLite3_bind_double(hStmt, ParamNum, Data)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_double');
end;

function TSQLiteDLLLoader.SQLite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
begin
  if Assigned(FSQLite3_bind_int) then
    Result := FSQLite3_bind_int(hStmt, ParamNum, Data)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_int');
end;

function TSQLiteDLLLoader.SQLite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
begin
  if Assigned(FSQLite3_bind_int64) then
    Result := FSQLite3_bind_int64(hStmt, ParamNum, Data)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_int64');
end;

function TSQLiteDLLLoader.SQLite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
begin
  if Assigned(FSQLite3_bind_null) then
    Result := FSQLite3_bind_null(hStmt, ParamNum)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_null');
end;

function TSQLiteDLLLoader.SQLite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
 begin
  if Assigned(FSQLite3_bind_parameter_index) then
    Result := FSQLite3_bind_parameter_index(hStmt, zName)
  else
    raise EDLLNotLoadedException.Create('SQLite3_bind_parameter_index');
end;

function TSQLiteDLLLoader.SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer;
begin
  if Assigned(FSQLite3_create_collation) then
    Result := FSQLite3_create_collation(db, Name, eTextRep, UserData, xCompare)
  else
    raise EDLLNotLoadedException.Create('SQLite3_create_collation');
end;

end.

Jetzt gibt die Funktion LoadDll false zurück. Unter anderem ist FSQLite3_GetTable nicht Assigned. Doch wenn ich es einfach mal so lasse:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function TSQLiteDLLLoader.LoadDLL(ADLLPath: string): Boolean;
begin
  FSQLiteDLLHandle := LoadLibrary(PChar(ADLLPath));
  Result := FSQLiteDLLHandle <> 0;
  if Result then
  begin
    @FSQLite3_Open := GetProcAddress(FSQLiteDLLHandle, 'sqlite3_open');

    Result := Assigned(FSQLite3_Open);
  end;
end;
Dann dürfte doch nicht schon wieder ""The SQLite library was not loaded before calling SQLite3_Open" kommen, da SQLite3_Open doch in der Funktion drin ist
EDIT: Es heißt ja sqlite_get_table . Werde es gleich korriegieren!







EDIT: ES FUNKTIONIEEEEERRRT!!! War einfach nur zu doof! VIELE, VIELEN, VIELEN DANK Jaenicke! Bist ein Schatz! :D