Skip to content

Commit cd22a69

Browse files
committed
Fix #8: add a busy handler for SQLite
1 parent 7acbb59 commit cd22a69

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/sqlite/ado-connections-sqlite.adb

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-----------------------------------------------------------------------
22
-- ADO Sqlite Database -- SQLite Database connections
3-
-- Copyright (C) 2009, 2010, 2011, 2012, 2015, 2017, 2018, 2019 Stephane Carrez
3+
-- Copyright (C) 2009, 2010, 2011, 2012, 2015, 2017, 2018, 2019, 2022 Stephane Carrez
44
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
55
--
66
-- Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,6 +15,7 @@
1515
-- See the License for the specific language governing permissions and
1616
-- limitations under the License.
1717
-----------------------------------------------------------------------
18+
with System;
1819
with Interfaces.C.Strings;
1920

2021
with Util.Log;
@@ -163,6 +164,17 @@ package body ADO.Connections.Sqlite is
163164
ADO.Schemas.Sqlite.Load_Schema (Database, Schema);
164165
end Load_Schema;
165166

167+
function Busy_Handler (Arg1 : System.Address;
168+
Count : Interfaces.C.int)
169+
return Interfaces.C.int with Convention => C;
170+
171+
function Busy_Handler (Arg1 : System.Address;
172+
Count : Interfaces.C.int) return Interfaces.C.int is
173+
begin
174+
delay 0.001;
175+
return (if Count > 10_000 then 0 else 1);
176+
end Busy_Handler;
177+
166178
protected body Sqlite_Connections is
167179

168180
procedure Open (Config : in Configuration'Class;
@@ -271,6 +283,9 @@ package body ADO.Connections.Sqlite is
271283
-- temp_store=MEMORY
272284
-- encoding='UTF-8'
273285
Config.Iterate (Process => Configure'Access);
286+
Status := Sqlite3_H.sqlite3_busy_handler (Handle,
287+
Busy_Handler'Access,
288+
Database.all'Address);
274289
end;
275290
end;
276291
end Open;

0 commit comments

Comments
 (0)