Commit ec2139334b77aab040d7617ec5a190820a68cf4c

Authored by David RENE
1 parent 99518bb6

add web_arg_value_not_null into web/CXM_common.anubis

add settings management for sqlite3 database
calexium_lib/database/migration_common_sqlite3.anubis
@@ -16,9 +16,6 @@ read data_base/sqlite_foreign_key.anubis @@ -16,9 +16,6 @@ read data_base/sqlite_foreign_key.anubis
16 read calexium_lib/database/db_utils.anubis 16 read calexium_lib/database/db_utils.anubis
17 read calexium_lib/net_services_protocols/logger_service.anubis 17 read calexium_lib/net_services_protocols/logger_service.anubis
18 18
19 - read ezmailbox_constants.anubis  
20 -  
21 -  
22 public type DbTable: 19 public type DbTable:
23 table(String name, String create_query), 20 table(String name, String create_query),
24 table(String db_name, String name, String create_query), 21 table(String db_name, String name, String create_query),
calexium_lib/database/settings_sqlite3.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Totoro
  4 + * Date: 11/08/2012
  5 + * Time: 17:44
  6 + *
  7 + * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8 + */
  9 +
  10 +read tools/basis.anubis
  11 +read data_base/sqlite.anubis
  12 +read data_base/db_tools.anubis
  13 +read calexium_lib/database/db_utils.anubis
  14 +
  15 +
  16 +public define Maybe(String)
  17 + select_settings
  18 + (
  19 + SQLite3DataBase db,
  20 + String var,
  21 + )=
  22 + if sql_query_timeout(db, "SELECT var_value FROM settings WHERE var_name=" + db_make_sql_string(var) + ";", [], "select_settings") is
  23 + {
  24 + error(_) then failure, //error in the SQL request
  25 + ok(_, cursor, _) then
  26 + if cursor(unique) is
  27 + {
  28 + error(_) then failure,
  29 + no_more_row then failure, //can't find the var_value in the table, because the row is empty
  30 + row(current) then success(text(current)(0))
  31 + }
  32 + }.
  33 +
  34 +public define String
  35 + select_settings
  36 + (
  37 + SQLite3DataBase db,
  38 + String var,
  39 + String default
  40 + )=
  41 + if select_settings(db, var) is
  42 + {
  43 + failure then default, //error in the SQL request
  44 + success(value) then value
  45 + }.
  46 +
  47 +public define Int
  48 + select_settings
  49 + (
  50 + SQLite3DataBase db,
  51 + String var,
  52 + Int default
  53 + )=
  54 + if select_settings(db, var) is
  55 + {
  56 + failure then default, //error in the SQL request
  57 + success(value) then
  58 + if decimal_scan(value) is
  59 + {
  60 + failure then default,
  61 + success(v) then v
  62 + }
  63 + }.
  64 +
  65 +public define Bool
  66 + select_settings
  67 + (
  68 + SQLite3DataBase db,
  69 + String var,
  70 + Bool default
  71 + )=
  72 + if select_settings(db, var) is
  73 + {
  74 + failure then default, //error in the SQL request
  75 + success(value) then
  76 + if value = "true" then true
  77 + else if value = "false" then false
  78 + // old values
  79 + else if value = "1" then true
  80 + else if value = "0" then false
  81 + // failback
  82 + else if decimal_scan(value) is
  83 + {
  84 + failure then default,
  85 + success(v) then v!=0
  86 + }
  87 + }.
  88 +
  89 +public define One
  90 + update_settings
  91 + (
  92 + SQLite3DataBase db,
  93 + String var,
  94 + Bool value
  95 + )=
  96 + with bool_str = if value is true then "true" else "false",
  97 + with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_String(":value", bool_str)],
  98 + if select_settings(db, var) is success(_) then
  99 + forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings"))
  100 + else
  101 + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings"))
  102 + .
  103 +
  104 +public define One
  105 + update_settings
  106 + (
  107 + SQLite3DataBase db,
  108 + String var,
  109 + Int value
  110 + )=
  111 + with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_Int(":value", value)],
  112 + if select_settings(db, var) is success(_) then
  113 + forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings"))
  114 + else
  115 + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings"))
  116 + .
  117 +
  118 +
  119 +public define One
  120 + update_settings
  121 + (
  122 + SQLite3DataBase db,
  123 + String var,
  124 + String value
  125 + )=
  126 + with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_String(":value", value)],
  127 + if select_settings(db, var) is success(_) then
  128 + forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings"))
  129 + else
  130 + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings"))
  131 + .
  132 +
calexium_lib/web/CXM_common.anubis
@@ -105,6 +105,22 @@ public define Web_arg_value @@ -105,6 +105,22 @@ public define Web_arg_value
105 } 105 }
106 }. 106 }.
107 107
  108 +public define Web_arg_value
  109 + web_arg_value_not_null
  110 + (
  111 + List(Web_arg) lwa,
  112 + String name,
  113 + ) =
  114 + if web_arg_value(lwa, name) is
  115 + {
  116 + not_found then not_found
  117 + found(str) then
  118 + if str = "" then
  119 + not_found
  120 + else
  121 + found(str)
  122 + }.
  123 +
108 *Ignore* 124 *Ignore*
109 125
110 public define Maybe((String,String)) 126 public define Maybe((String,String))