Commit a43db55dbaf51ed6566007bbf10ba579521397c4

Authored by Cédric RICARD
1 parent 986b3f3a

Use of new SQLite3 API

Showing 1 changed file with 26 additions and 28 deletions   Show diff stats
calexium_lib/database/db_utils.anubis
... ... @@ -13,32 +13,6 @@ read data_base/sqlite.anubis
13 13  
14 14 read calexium_lib/net_services_protocols/logger_service.anubis
15 15  
16   -
17   -define Result(SQLite3Error, SQLite3HeadersOrRow -> SQLite3Row)
18   - sql_query_timeout
19   - (
20   - SQLite3DataBase db,
21   - String sql_command,
22   - Int timeout
23   - ) =
24   -
25   - if sql_query(db, sql_command) is
26   - {
27   - error(sql_error) then (
28   - if (sql_error.code /= 1 & sql_error.code /= 5 & sql_error.code /= 6) | now > timeout then
29   - error(sql_error)
30   - else
31   - (
32   - if sql_error.code = 5 then
33   - unique
34   - else
35   - print_db_error(sql_error)
36   - );
37   - sleep(100);
38   - sql_query_timeout(db, sql_command, timeout)),
39   - ok(cursor) then ok(cursor)
40   - }.
41   -
42 16 public define Result(SQLite3Error, One)
43 17 sql_transaction
44 18 (
... ... @@ -70,6 +44,23 @@ public define Result(SQLite3Error, One)
70 44 }.
71 45  
72 46  
  47 +
  48 +public define SQLite3QueryResult
  49 + sql_query_timeout
  50 + (
  51 + SQLite3DataBase db, //database handle
  52 + String sql_query, //sql query itself
  53 + List(SQLite3Bind) initial_bindings,
  54 + String msg //message to be shown if an error occure
  55 + ) =
  56 + //we try with 30 sec of timeout
  57 + if sql_query_timeout(db, sql_query, initial_bindings, 60, 100) is
  58 + {
  59 + error(sql_error) then logError("DB", db_error(sql_error,msg)); error(sql_error),
  60 + ok(headers, cursor, reset) then ok(headers, cursor, reset)
  61 + }.
  62 +
  63 +// deprecated. Use one of the previous ones.
73 64 public define Maybe(SQLite3HeadersOrRow -> SQLite3Row)
74 65 sql_query_timeout
75 66 (
... ... @@ -78,10 +69,17 @@ public define Maybe(SQLite3HeadersOrRow -> SQLite3Row)
78 69 String msg //message to be shown if an error occure
79 70 ) =
80 71 //we try with 30 sec of timeout
81   - if sql_query_timeout(db, sql_query, now + 60) is
  72 + if sql_query_timeout(db, sql_query, [], 60, 100) is
82 73 {
83 74 error(sql_error) then logError("DB", db_error(sql_error,msg));failure,
84   - ok(cursor) then success(cursor)
  75 + ok(headers, cursor, reset) then
  76 + success((SQLite3HeadersOrRow h_or_r) |-> if h_or_r is
  77 + {
  78 + headers then
  79 + with cols = map((String c) |-> (SQLite3Datum)text(c), headers(unique)),
  80 + row((Int n) |-> force(nth(n, cols), no_such_column)),
  81 + next_row then cursor(unique)
  82 + })
85 83 }.
86 84  
87 85 // -- Extractors HELPERS ---------------
... ...