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
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sqlite3conn, sqldb, FileUtil, Forms, Controls, Graphics,
Dialogs, StdCtrls, db;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog: TOpenDialog;
SQLite3Connection: TSQLite3Connection;
SQLQuery: TSQLQuery;
SQLTransaction: TSQLTransaction;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
procedure StartDataBase;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
{$IFDEF UNIX} // Linux
{$IFNDEF DARWIN}
SQLiteLibraryName := './libsqlite3.so';
{$ENDIF}
{$ENDIF}
{$IFDEF WINDOWS} // Windows
SQLiteLibraryName := 'sqlite3.dll';
{$ENDIF}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
StartDataBase;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog.Execute then
(SQLQuery.FieldByName('image') as TBlobField).LoadFromFile(OpenDialog.FileName); // c'est là qua ça coïnce !
// SQLite3Connection.ExecuteDirect('INSERT INTO tiles (x, y, z, image) VALUES (2, 3, 15, 32)');
end;
procedure TForm1.StartDataBase;
var
CreateTables: boolean;
T: String;
// BlobField: TGraphicField;
begin
// BlobField:= TGraphicField.Create(TComponent(Self));
if FileExists('mydatabase.db') then
DeleteFile('mydatabase.db');
SQLite3Connection.DatabaseName:= 'mydatabase.db';
SQLite3Connection.Open;
SQLTransaction.Active:= True;
SQLite3Connection.ExecuteDirect('CREATE TABLE android_metadata('+
' locale TEXT);');
SQLite3Connection.ExecuteDirect('INSERT INTO android_metadata VALUES (''fr_FR'')');
SQLite3Connection.ExecuteDirect('CREATE TABLE tiles('+
' x int,'+
' y int,'+
' z int,'+
' image BLOB,'+
' PRIMARY KEY (x, y, z));');
SQLite3Connection.ExecuteDirect('CREATE INDEX IND on tiles(x,y,z)');
SQLTransaction.Commit;
end;
end. |
Partager