diff --git a/Source/Impl/sqlite.adb b/Source/Impl/sqlite.adb new file mode 100644 index 0000000..fd27efe --- /dev/null +++ b/Source/Impl/sqlite.adb @@ -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; diff --git a/Source/Spec/sqlite.ads b/Source/Spec/sqlite.ads new file mode 100644 index 0000000..cb2e684 --- /dev/null +++ b/Source/Spec/sqlite.ads @@ -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; diff --git a/sqlite.gpr b/sqlite.gpr new file mode 100644 index 0000000..bdb2b7e --- /dev/null +++ b/sqlite.gpr @@ -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;