Commit 6f536647c4ca3db09638aa7ab7d4836c69e70a4a

Authored by totoro
1 parent dd7123b8

create specialized file for:

db_bind which contain many helper for db_bind, like Datetime, DB_Id, etc
db_updatefield which contain a helper for construction of SQL query and his bind for insert or update
database/db_binds.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 17/03/2017
  5 + * Time: 00:14
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 + extended version of bind for SQLite3.
  11 +
  12 +public define SQLite3Bind
  13 + bind_DB_id_or_NULL
  14 + (
  15 + String _name,
  16 + DB_id _value
  17 + )=
  18 + if _value is
  19 + {
  20 + none then bind_NULL(_name)
  21 + db_id(value) then bind_Int(_name, value)
  22 + }
  23 +.
  24 +
  25 +public define SQLite3Bind
  26 + bind_DB_id_or_NULL
  27 + (
  28 + String _name,
  29 + Maybe(DB_id) mb_value
  30 + )=
  31 + if mb_value is
  32 + {
  33 + failure then bind_NULL(_name)
  34 + success(id) then bind_DB_id_or_NULL(_name, id)
  35 + }
  36 +.
  37 +
  38 +public define SQLite3Bind
  39 + bind_Int_or_NULL
  40 + (
  41 + String name,
  42 + Maybe(Int) mb_value
  43 + )=
  44 + if mb_value is
  45 + {
  46 + failure then bind_NULL(name),
  47 + success(value) then bind_Int(name, value)
  48 + }
  49 +.
  50 +
  51 +public define SQLite3Bind
  52 + bind_String_or_NULL
  53 + (
  54 + String name,
  55 + String value
  56 + )=
  57 + if value = "" then
  58 + bind_NULL(name)
  59 + else
  60 + bind_String(name, value).
  61 +
  62 +public define SQLite3Bind
  63 + bind_Datetime
  64 + (
  65 + String name,
  66 + DB_datetime dt
  67 + )=
  68 + bind_String(name, datetime(dt)).
  69 +
  70 +public define SQLite3Bind
  71 + bind_Date
  72 + (
  73 + String name,
  74 + DB_date d
  75 + )=
  76 + bind_String(name, date(d)).
  77 +
  78 +public define SQLite3Bind
  79 + bind_Time
  80 + (
  81 + String name,
  82 + DB_time d
  83 + )=
  84 + bind_String(name, time(d)).
  85 +
  86 +public define SQLite3Bind
  87 + bind_Bool
  88 + (
  89 + String name,
  90 + Bool value
  91 + )=
  92 + bind_Int(name, to_DBInt(value)).
  93 +
  94 +public define SQLite3Bind
  95 + bind_BLOB
  96 + (
  97 + String name,
  98 + $V value
  99 + )=
  100 + bind_ByteArray(name, serialize(value)).
  101 +
database/db_types.anubis
1 /* 1 /*
2 * Created by PyramIDE. 2 * Created by PyramIDE.
3 - * User: Totoro 3 + * User: フランスのトトロ aka (David RENÉ)
4 * Date: 14/11/2011 4 * Date: 14/11/2011
5 * Time: 22:41 5 * Time: 22:41
6 * 6 *
@@ -89,9 +89,7 @@ public define Int @@ -89,9 +89,7 @@ public define Int
89 none then (Int)-1, 89 none then (Int)-1,
90 pk(_idx) then _idx 90 pk(_idx) then _idx
91 }. 91 }.
92 -  
93 92
94 -  
95 public define String 93 public define String
96 to_String 94 to_String
97 ( 95 (
@@ -99,8 +97,6 @@ public define String @@ -99,8 +97,6 @@ public define String
99 )= 97 )=
100 date(d). 98 date(d).
101 99
102 -  
103 -  
104 public define String 100 public define String
105 to_String 101 to_String
106 ( 102 (
@@ -129,8 +125,7 @@ public define Int @@ -129,8 +125,7 @@ public define Int
129 )= 125 )=
130 if value then 1 else 0. 126 if value then 1 else 0.
131 127
132 -public type SQLite3_update_field:  
133 - field(String column, SQLite3Bind bind). 128 +
134 129
135 130
136 * Some Bind helper * 131 * Some Bind helper *
database/db_update_fields.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 17/03/2017
  5 + * Time: 00:11
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 +public type SQLite3_update_field:
  11 + field(String column, SQLite3Bind bind).
  12 +
  13 +public define (List(SQLite3Bind), String)
  14 + make_update_clause_and_binds
  15 + (
  16 + List(SQLite3_update_field) fields,
  17 + List(SQLite3Bind) so_far,
  18 + List(String) clause
  19 + )=
  20 + if fields is
  21 + {
  22 + [] then (so_far, join(", ",clause)),
  23 + [ h . t ] then
  24 + if h is field(column, bind) then
  25 + make_clause_and_binds(t, [bind . so_far], ["\""+column+"\" = :v_"+column . clause])
  26 + }
  27 +.
  28 +
  29 +public define (List(SQLite3Bind), String)
  30 + make_insert_clause_and_binds
  31 + (
  32 + List(SQLite3_update_field) fields,
  33 + List(SQLite3Bind) so_far,
  34 + List(String) clause
  35 + )=
  36 + if fields is
  37 + {
  38 + [] then (so_far, join(", ",clause)),
  39 + [ h . t ] then
  40 + if h is field(column, bind) then
  41 + make_clause_and_binds(t, [bind . so_far], ["\""+column+"\" = :v_"+column . clause])
  42 + }
  43 +.
database/db_utils.anubis
@@ -287,92 +287,10 @@ public define List(Int) @@ -287,92 +287,10 @@ public define List(Int)
287 This is useful when we want to construct a SQL query with only needs fields. 287 This is useful when we want to construct a SQL query with only needs fields.
288 288
289 289
290 -public define (List(SQLite3Bind), String)  
291 - make_clause_and_binds  
292 - (  
293 - List(SQLite3_update_field) fields,  
294 - List(SQLite3Bind) so_far,  
295 - List(String) clause  
296 - )=  
297 - if fields is  
298 - {  
299 - [] then (so_far, join(", ",clause)),  
300 - [ h . t ] then  
301 - if h is field(column, bind) then  
302 - make_clause_and_binds(t, [bind . so_far], ["\""+column+"\" = :v_"+column . clause])  
303 - }.  
304 -  
305 -  
306 - extended version of bind for SQLite3.  
307 -  
308 -public define SQLite3Bind  
309 - bind_DB_id_or_NULL  
310 - (  
311 - String _name,  
312 - DB_id _value  
313 - )=  
314 - if _value is  
315 - {  
316 - none then bind_NULL(_name)  
317 - db_id(value) then bind_Int(_name, value)  
318 - }  
319 -.  
320 -  
321 -  
322 -public define SQLite3Bind  
323 - bind_Int_or_NULL  
324 - (  
325 - String name,  
326 - Int value  
327 - )=  
328 - if value = 0 then  
329 - bind_NULL(name)  
330 - else  
331 - bind_Int(name, value).  
332 290
333 -public define SQLite3Bind  
334 - bind_String_or_NULL  
335 - (  
336 - String name,  
337 - String value  
338 - )=  
339 - if value = "" then  
340 - bind_NULL(name)  
341 - else  
342 - bind_String(name, value).  
343 -  
344 -public define SQLite3Bind  
345 - bind_Datetime  
346 - (  
347 - String name,  
348 - DB_datetime dt  
349 - )=  
350 - bind_String(name, datetime(dt)).  
351 -  
352 -public define SQLite3Bind  
353 - bind_Date  
354 - (  
355 - String name,  
356 - DB_date d  
357 - )=  
358 - bind_String(name, date(d)).  
359 -  
360 -public define SQLite3Bind  
361 - bind_Bool  
362 - (  
363 - String name,  
364 - Bool value  
365 - )=  
366 - bind_Int(name, to_DBInt(value)).  
367 -  
368 -public define SQLite3Bind  
369 - bind_BLOB  
370 - (  
371 - String name,  
372 - $V value  
373 - )=  
374 - bind_ByteArray(name, serialize(value)).  
375 291
  292 +
  293 +
376 // -- Migration HELPERS --------------- 294 // -- Migration HELPERS ---------------
377 295
378 public define DbBind 296 public define DbBind