Initial commit

This commit is contained in:
Folkert Kevelam 2025-07-21 23:33:34 +02:00
parent e3246b605d
commit e6779e4868
3 changed files with 99 additions and 0 deletions

47
Source/Impl/sqlite.adb Normal file
View File

@ -0,0 +1,47 @@
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
package body Sqlite is
procedure Finalize (Db : in out Database) is
function sqlite3_close (Db : in out Database_Int) return Int
with Import, Convention => C;
function sqlite3_close_v2 (Db : in out Database_Int) return Int
with Import, Convention => C;
Error : int := 0;
begin
if Db.Version = v1 then
Error := sqlite3_close (Db.Internal);
else
Error := sqlite3_close_v2 (Db.Internal);
end if;
end Finalize;
procedure Open (Db : in out Database; Filename : String) is
function sqlite3_open (
Filename : Chars_Ptr;
ppDb : out Database_Int) return Int
with Import, Convention => C;
Error : Int;
begin
Error := sqlite3_open (New_String (Filename), Db.Internal);
Db.Version := v1;
end Open;
procedure Close (Db : in out Database) is
begin
Db.Finalize;
end Close;
end Sqlite;

26
Source/Spec/sqlite.ads Normal file
View File

@ -0,0 +1,26 @@
with Ada.Finalization;
package Sqlite is
type Database is tagged private;
procedure Open (Db : in out Database; Filename : String);
procedure Close (Db : in out Database);
private
type Database_Record_Int is null record;
type Database_Int is access all Database_Record_Int;
type Database_Version is (v1, v2);
type Database is new Ada.Finalization.Controlled with
record
Internal : Database_Int;
Version : Database_Version;
end record;
overriding
procedure Finalize (Db : in out Database);
end Sqlite;

26
sqlite.gpr Normal file
View File

@ -0,0 +1,26 @@
library project Sqlite is
for Source_Dirs use ("Source/Spec", "Source/Impl");
for Object_Dir use "obj";
for Library_Name use "sqlite";
for Library_Dir use "lib";
for Library_Kind use "Static";
type Mode_Type is ("debug", "release");
Mode : Mode_Type := external("mode", "debug");
package Compiler is
case Mode is
when "debug" =>
for Default_Switches ("Ada") use ("-g", "-Og");
when "release" =>
for Default_Switches ("Ada") use ("-O2");
end case;
end Compiler;
package Linker is
for Default_Switches ("Ada") use ("-lsqlite3");
end Linker;
end Sqlite;