2019-05-28 18:48:07 +02:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- G N A T C O L L --
|
|
|
|
|
-- --
|
2020-06-09 00:55:25 +02:00
|
|
|
-- Copyright (C) 2005-2020, AdaCore --
|
2019-05-28 18:48:07 +02:00
|
|
|
-- --
|
|
|
|
|
-- This library is free software; you can redistribute it and/or modify it --
|
|
|
|
|
-- under terms of the GNU General Public License as published by the Free --
|
|
|
|
|
-- Software Foundation; either version 3, or (at your option) any later --
|
|
|
|
|
-- version. This library is distributed in the hope that it will be useful, --
|
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
|
|
|
|
|
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
|
|
|
|
|
-- --
|
|
|
|
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
|
|
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
|
|
|
|
-- version 3.1, as published by the Free Software Foundation. --
|
|
|
|
|
-- --
|
|
|
|
|
-- You should have received a copy of the GNU General Public License and --
|
|
|
|
|
-- a copy of the GCC Runtime Library Exception along with this program; --
|
|
|
|
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
|
|
|
-- <http://www.gnu.org/licenses/>. --
|
|
|
|
|
-- --
|
|
|
|
|
------------------------------------------------------------------------------
|
2009-05-23 01:31:57 +00:00
|
|
|
|
|
|
|
|
with GNATCOLL.SQL.Sqlite.Builder;
|
|
|
|
|
|
|
|
|
|
package body GNATCOLL.SQL.Sqlite is
|
|
|
|
|
|
2017-11-23 10:29:32 +06:00
|
|
|
type Sqlite_Engine is new Database_Engine with null record;
|
|
|
|
|
|
|
|
|
|
overriding function Setup
|
|
|
|
|
(Engine : Sqlite_Engine;
|
|
|
|
|
Options : Name_Values.Map;
|
|
|
|
|
Errors : access Error_Reporter'Class) return Database_Description;
|
|
|
|
|
|
2011-08-01 13:05:47 +00:00
|
|
|
-----------
|
|
|
|
|
-- Setup --
|
|
|
|
|
-----------
|
2009-05-23 01:31:57 +00:00
|
|
|
|
2011-08-01 13:05:47 +00:00
|
|
|
function Setup
|
|
|
|
|
(Database : String;
|
2014-03-05 13:41:29 +00:00
|
|
|
Cache_Support : Boolean := False;
|
2017-01-30 16:28:29 +01:00
|
|
|
Errors : access Error_Reporter'Class := null;
|
|
|
|
|
Is_URI : Boolean := False)
|
2011-08-01 13:05:47 +00:00
|
|
|
return Database_Description
|
|
|
|
|
is
|
|
|
|
|
Result : Sqlite_Description_Access;
|
2009-05-23 01:31:57 +00:00
|
|
|
begin
|
2014-03-05 13:41:29 +00:00
|
|
|
Result := new Sqlite_Description
|
|
|
|
|
(Caching => Cache_Support, Errors => Errors);
|
2011-08-01 13:05:47 +00:00
|
|
|
Result.Dbname := new String'(Database);
|
2017-01-30 16:28:29 +01:00
|
|
|
Result.Is_URI := Is_URI;
|
2011-08-01 13:05:47 +00:00
|
|
|
return Database_Description (Result);
|
|
|
|
|
end Setup;
|
|
|
|
|
|
2017-11-23 10:29:32 +06:00
|
|
|
-----------
|
|
|
|
|
-- Setup --
|
|
|
|
|
-----------
|
|
|
|
|
|
|
|
|
|
overriding function Setup
|
|
|
|
|
(Engine : Sqlite_Engine;
|
|
|
|
|
Options : Name_Values.Map;
|
|
|
|
|
Errors : access Error_Reporter'Class) return Database_Description
|
|
|
|
|
is
|
|
|
|
|
pragma Unreferenced (Engine);
|
|
|
|
|
|
|
|
|
|
type Setup_Parameters is (Database, Is_URI, Caching);
|
|
|
|
|
Params : array (Setup_Parameters) of Name_Values.Cursor;
|
|
|
|
|
|
|
|
|
|
function Value (P : Setup_Parameters; Default : String) return String is
|
|
|
|
|
(if Name_Values.Has_Element (Params (P))
|
|
|
|
|
then Name_Values.Element (Params (P)) else Default);
|
|
|
|
|
begin
|
|
|
|
|
for C in Options.Iterate loop
|
|
|
|
|
Params (Setup_Parameters'Value (Name_Values.Key (C))) := C;
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
|
|
return Setup
|
|
|
|
|
(Database => Value (Database, ""),
|
|
|
|
|
Is_URI => Boolean'Value (Value (Is_URI, "False")),
|
|
|
|
|
Cache_Support => Boolean'Value (Value (Caching, "False")),
|
|
|
|
|
Errors => Errors);
|
|
|
|
|
end Setup;
|
|
|
|
|
|
2011-08-01 13:05:47 +00:00
|
|
|
----------------------
|
|
|
|
|
-- Build_Connection --
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
overriding function Build_Connection
|
2011-08-03 10:56:42 +00:00
|
|
|
(Self : access Sqlite_Description) return Database_Connection
|
2011-08-01 13:05:47 +00:00
|
|
|
is
|
2011-08-03 10:56:42 +00:00
|
|
|
DB : Database_Connection;
|
2011-08-01 13:05:47 +00:00
|
|
|
begin
|
2011-08-03 10:56:42 +00:00
|
|
|
DB := GNATCOLL.SQL.Sqlite.Builder.Build_Connection (Self);
|
|
|
|
|
Reset_Connection (DB);
|
|
|
|
|
return DB;
|
2011-08-01 13:05:47 +00:00
|
|
|
end Build_Connection;
|
|
|
|
|
|
2012-04-04 14:46:19 +00:00
|
|
|
---------------
|
|
|
|
|
-- Is_Sqlite --
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
function Is_Sqlite
|
2014-04-04 12:21:21 +00:00
|
|
|
(DB : access Database_Connection_Record'Class) return Boolean
|
2012-04-04 14:46:19 +00:00
|
|
|
is
|
|
|
|
|
begin
|
|
|
|
|
return Get_Description (DB).all in Sqlite_Description;
|
|
|
|
|
end Is_Sqlite;
|
|
|
|
|
|
|
|
|
|
-------------
|
|
|
|
|
-- DB_Name --
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
function DB_Name
|
|
|
|
|
(DB : access Database_Connection_Record'Class) return String is
|
|
|
|
|
begin
|
|
|
|
|
return Sqlite_Description (Get_Description (DB).all).Dbname.all;
|
|
|
|
|
exception
|
|
|
|
|
when Constraint_Error =>
|
|
|
|
|
-- Probably not a Sqlite_Description
|
|
|
|
|
return "";
|
|
|
|
|
end DB_Name;
|
|
|
|
|
|
2011-08-01 13:05:47 +00:00
|
|
|
----------
|
|
|
|
|
-- Free --
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
overriding procedure Free (Self : in out Sqlite_Description) is
|
|
|
|
|
begin
|
|
|
|
|
Free (Self.Dbname);
|
|
|
|
|
end Free;
|
2009-05-23 01:31:57 +00:00
|
|
|
|
2012-03-27 16:04:08 +00:00
|
|
|
------------
|
|
|
|
|
-- Backup --
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
function Backup
|
2014-04-04 12:21:21 +00:00
|
|
|
(DB1 : access Database_Connection_Record'Class;
|
|
|
|
|
DB2 : String;
|
2012-03-30 13:44:14 +00:00
|
|
|
From_DB1_To_DB2 : Boolean := True) return Boolean
|
2012-03-27 16:04:08 +00:00
|
|
|
is
|
|
|
|
|
begin
|
2012-03-30 13:44:14 +00:00
|
|
|
return GNATCOLL.SQL.Sqlite.Builder.Backup (DB1, DB2, From_DB1_To_DB2);
|
2012-03-27 16:04:08 +00:00
|
|
|
end Backup;
|
|
|
|
|
|
2012-04-05 15:37:51 +00:00
|
|
|
------------
|
|
|
|
|
-- Backup --
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
function Backup
|
|
|
|
|
(From : access Database_Connection_Record'Class;
|
|
|
|
|
To : access Database_Connection_Record'Class) return Boolean is
|
|
|
|
|
begin
|
|
|
|
|
return GNATCOLL.SQL.Sqlite.Builder.Backup (From, To);
|
|
|
|
|
end Backup;
|
|
|
|
|
|
2009-05-23 01:31:57 +00:00
|
|
|
end GNATCOLL.SQL.Sqlite;
|