diff --git a/calexium_lib/database/migration_common_sqlite3.anubis b/calexium_lib/database/migration_common_sqlite3.anubis index a89db40..91ace4b 100644 --- a/calexium_lib/database/migration_common_sqlite3.anubis +++ b/calexium_lib/database/migration_common_sqlite3.anubis @@ -16,9 +16,6 @@ read data_base/sqlite_foreign_key.anubis read calexium_lib/database/db_utils.anubis read calexium_lib/net_services_protocols/logger_service.anubis - read ezmailbox_constants.anubis - - public type DbTable: table(String name, String create_query), table(String db_name, String name, String create_query), diff --git a/calexium_lib/database/settings_sqlite3.anubis b/calexium_lib/database/settings_sqlite3.anubis new file mode 100644 index 0000000..89b2096 --- /dev/null +++ b/calexium_lib/database/settings_sqlite3.anubis @@ -0,0 +1,132 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 11/08/2012 + * Time: 17:44 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +read tools/basis.anubis +read data_base/sqlite.anubis +read data_base/db_tools.anubis +read calexium_lib/database/db_utils.anubis + + +public define Maybe(String) + select_settings + ( + SQLite3DataBase db, + String var, + )= + if sql_query_timeout(db, "SELECT var_value FROM settings WHERE var_name=" + db_make_sql_string(var) + ";", [], "select_settings") is + { + error(_) then failure, //error in the SQL request + ok(_, cursor, _) then + if cursor(unique) is + { + error(_) then failure, + no_more_row then failure, //can't find the var_value in the table, because the row is empty + row(current) then success(text(current)(0)) + } + }. + +public define String + select_settings + ( + SQLite3DataBase db, + String var, + String default + )= + if select_settings(db, var) is + { + failure then default, //error in the SQL request + success(value) then value + }. + +public define Int + select_settings + ( + SQLite3DataBase db, + String var, + Int default + )= + if select_settings(db, var) is + { + failure then default, //error in the SQL request + success(value) then + if decimal_scan(value) is + { + failure then default, + success(v) then v + } + }. + +public define Bool + select_settings + ( + SQLite3DataBase db, + String var, + Bool default + )= + if select_settings(db, var) is + { + failure then default, //error in the SQL request + success(value) then + if value = "true" then true + else if value = "false" then false + // old values + else if value = "1" then true + else if value = "0" then false + // failback + else if decimal_scan(value) is + { + failure then default, + success(v) then v!=0 + } + }. + +public define One + update_settings + ( + SQLite3DataBase db, + String var, + Bool value + )= + with bool_str = if value is true then "true" else "false", + with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_String(":value", bool_str)], + if select_settings(db, var) is success(_) then + forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings")) + else + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings")) + . + +public define One + update_settings + ( + SQLite3DataBase db, + String var, + Int value + )= + with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_Int(":value", value)], + if select_settings(db, var) is success(_) then + forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings")) + else + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings")) + . + + +public define One + update_settings + ( + SQLite3DataBase db, + String var, + String value + )= + with binds = (List(SQLite3Bind))[bind_String(":name", var), bind_String(":value", value)], + if select_settings(db, var) is success(_) then + forget(sql_query_timeout(db, "UPDATE settings SET var_value = :value WHERE var_name = :name;", binds, "update_settings")) + else + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (:name, :value)", binds, "update_settings")) + . + diff --git a/calexium_lib/web/CXM_common.anubis b/calexium_lib/web/CXM_common.anubis index 40e4846..aa627bb 100644 --- a/calexium_lib/web/CXM_common.anubis +++ b/calexium_lib/web/CXM_common.anubis @@ -105,6 +105,22 @@ public define Web_arg_value } }. +public define Web_arg_value + web_arg_value_not_null + ( + List(Web_arg) lwa, + String name, + ) = + if web_arg_value(lwa, name) is + { + not_found then not_found + found(str) then + if str = "" then + not_found + else + found(str) + }. + *Ignore* public define Maybe((String,String)) -- libgit2 0.21.4