Commit b2882af8a0cef378fc65d5f41b891fb3724871c1
1 parent
22453804
Creating MF_1_6 branch
Showing
6 changed files
with
154 additions
and
138 deletions
Show diff stats
database/db_utils.anubis
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | read tools/basis.anubis |
| 11 | 11 | read system/logger.anubis |
| 12 | 12 | read system/string.anubis |
| 13 | -read data_base/db_tools.anubis | |
| 13 | +read data_base/sqlite.anubis | |
| 14 | 14 | |
| 15 | 15 | read calexium_lib/net_services_protocols/logger_service.anubis |
| 16 | 16 | |
| ... | ... | @@ -33,10 +33,10 @@ define One |
| 33 | 33 | else |
| 34 | 34 | unique. |
| 35 | 35 | |
| 36 | -public define Result(DbError, One) | |
| 36 | +public define Result(SQLite3Error, One) | |
| 37 | 37 | sql_transaction |
| 38 | 38 | ( |
| 39 | - Database db, | |
| 39 | + SQLite3DataBase db, | |
| 40 | 40 | String sql_command, |
| 41 | 41 | String message |
| 42 | 42 | ) = |
| ... | ... | @@ -45,15 +45,14 @@ public define Result(DbError, One) |
| 45 | 45 | if db_do_transaction( |
| 46 | 46 | db, |
| 47 | 47 | (One _) |-> |
| 48 | - if db_query(db, sql_command) is | |
| 48 | + if sql_query(db, sql_command) is | |
| 49 | 49 | { |
| 50 | 50 | error(err) then logError("DB", db_error(err,message));failure //error in the SQL request |
| 51 | - ok(_,cursor,_) then success(unique) | |
| 51 | + ok(cursor) then success(unique) | |
| 52 | 52 | }, |
| 53 | - success( (DbError err) |-> logError("DB", db_error(err,message))), | |
| 53 | + success( (SQLite3Error err) |-> logError("DB", db_error(err,message))), | |
| 54 | 54 | 60000, // max 60s |
| 55 | - 100, // retry every 100 ms | |
| 56 | - (DbError _) |-> false | |
| 55 | + 100 // retry every 100 ms | |
| 57 | 56 | ) is |
| 58 | 57 | { |
| 59 | 58 | error(err_and_result) then |
| ... | ... | @@ -66,19 +65,19 @@ public define Result(DbError, One) |
| 66 | 65 | ok(unique) |
| 67 | 66 | }. |
| 68 | 67 | |
| 68 | + | |
| 69 | 69 | |
| 70 | - | |
| 71 | -public define DbQueryResult | |
| 70 | +public define SQLite3QueryResult | |
| 72 | 71 | sql_query_timeout |
| 73 | 72 | ( |
| 74 | - Database db, //database handle | |
| 75 | - String sql_query, //sql query itself | |
| 76 | - List(DbBind) initial_bindings, | |
| 77 | - String msg //message to be shown if an error occure | |
| 73 | + SQLite3DataBase db, //database handle | |
| 74 | + String sql_query, //sql query itself | |
| 75 | + List(SQLite3Bind) initial_bindings, | |
| 76 | + String msg //message to be shown if an error occure | |
| 78 | 77 | ) = |
| 79 | 78 | //we try with 30 sec of timeout |
| 80 | 79 | with t0 = unow, |
| 81 | - if sql_query_timeout(db, sql_query, initial_bindings, 60, 100, (DbError _) |-> false) is | |
| 80 | + if sql_query_timeout(db, sql_query, initial_bindings, 60, 100) is | |
| 82 | 81 | { |
| 83 | 82 | error(sql_error) then logError("DB", db_error(sql_error,msg)); |
| 84 | 83 | __logLongQueries(t0, sql_query); |
| ... | ... | @@ -89,16 +88,16 @@ public define DbQueryResult |
| 89 | 88 | }. |
| 90 | 89 | |
| 91 | 90 | // deprecated. Use one of the previous ones. |
| 92 | -public define Maybe(SQLite3HeadersOrRow -> DbRow) | |
| 91 | +public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) | |
| 93 | 92 | sql_query_timeout |
| 94 | 93 | ( |
| 95 | - Database db, //database handle | |
| 94 | + SQLite3DataBase db, //database handle | |
| 96 | 95 | String sql_query, //sql query itself |
| 97 | 96 | String msg //message to be shown if an error occure |
| 98 | 97 | ) = |
| 99 | 98 | //we try with 30 sec of timeout |
| 100 | 99 | with t0 = unow, |
| 101 | - if sql_query_timeout(db, sql_query, [], 60, 100, (DbError _) |-> false) is | |
| 100 | + if sql_query_timeout(db, sql_query, [], 60, 100) is | |
| 102 | 101 | { |
| 103 | 102 | error(sql_error) then logError("DB", db_error(sql_error,msg)); |
| 104 | 103 | __logLongQueries(t0, sql_query); |
| ... | ... | @@ -108,7 +107,7 @@ public define Maybe(SQLite3HeadersOrRow -> DbRow) |
| 108 | 107 | success((SQLite3HeadersOrRow h_or_r) |-> if h_or_r is |
| 109 | 108 | { |
| 110 | 109 | headers then |
| 111 | - with cols = map((String c) |-> (DbDatum)db_text(c), headers(unique)), | |
| 110 | + with cols = map((String c) |-> (SQLite3Datum)text(c), headers(unique)), | |
| 112 | 111 | row((Int n) |-> force(nth(n, cols), no_such_column)), |
| 113 | 112 | next_row then cursor(unique) |
| 114 | 113 | }) |
| ... | ... | @@ -119,8 +118,8 @@ public define Maybe(SQLite3HeadersOrRow -> DbRow) |
| 119 | 118 | public define List(String) |
| 120 | 119 | db_get_string_list |
| 121 | 120 | ( |
| 122 | - One -> DbRow table_cursor, | |
| 123 | - List(String) so_far | |
| 121 | + One -> SQLite3Row table_cursor, | |
| 122 | + List(String) so_far | |
| 124 | 123 | ) = |
| 125 | 124 | if table_cursor(unique) is |
| 126 | 125 | { |
| ... | ... | @@ -135,7 +134,7 @@ public define List(String) |
| 135 | 134 | public define List(String) |
| 136 | 135 | db_get_string_list |
| 137 | 136 | ( |
| 138 | - SQLite3HeadersOrRow -> DbRow table_cursor, | |
| 137 | + SQLite3HeadersOrRow -> SQLite3Row table_cursor, | |
| 139 | 138 | List(String) so_far |
| 140 | 139 | ) = |
| 141 | 140 | if table_cursor(next_row) is |
| ... | ... | @@ -147,11 +146,10 @@ public define List(String) |
| 147 | 146 | db_get_string_list(table_cursor, [s . so_far]) |
| 148 | 147 | }. |
| 149 | 148 | |
| 150 | -// Old sqlite3 API | |
| 151 | 149 | public define List(Int) |
| 152 | 150 | db_get_integer_list |
| 153 | 151 | ( |
| 154 | - SQLite3HeadersOrRow -> DbRow table_cursor, | |
| 152 | + SQLite3HeadersOrRow -> SQLite3Row table_cursor, | |
| 155 | 153 | List(Int) so_far |
| 156 | 154 | ) = |
| 157 | 155 | if table_cursor(next_row) is |
| ... | ... | @@ -167,7 +165,7 @@ public define List(Int) |
| 167 | 165 | public define List(Int) |
| 168 | 166 | db_get_integer_list |
| 169 | 167 | ( |
| 170 | - One -> DbRow table_cursor, | |
| 168 | + One -> SQLite3Row table_cursor, | |
| 171 | 169 | List(Int) so_far |
| 172 | 170 | ) = |
| 173 | 171 | if table_cursor(unique) is |
| ... | ... | @@ -183,37 +181,4 @@ public define List(Int) |
| 183 | 181 | |
| 184 | 182 | |
| 185 | 183 | |
| 186 | -// -- Migration HELPERS --------------- | |
| 187 | - | |
| 188 | - public define DbBind | |
| 189 | - bind_String | |
| 190 | - ( | |
| 191 | - String name, | |
| 192 | - String value | |
| 193 | - ) = | |
| 194 | - db_bind(force(sub_string(name, 1, length(name) - 1), name), db_text(value)). | |
| 195 | - | |
| 196 | - public define DbBind | |
| 197 | - bind_ByteArray | |
| 198 | - ( | |
| 199 | - String name, | |
| 200 | - ByteArray value | |
| 201 | - ) = | |
| 202 | - db_bind(force(sub_string(name, 1, length(name) - 1), name), db_blob(value)). | |
| 203 | - | |
| 204 | - public define DbBind | |
| 205 | - bind_Int | |
| 206 | - ( | |
| 207 | - String name, | |
| 208 | - Int value | |
| 209 | - ) = | |
| 210 | - db_bind(force(sub_string(name, 1, length(name) - 1), name), db_integer(value)). | |
| 211 | - | |
| 212 | - public define DbBind | |
| 213 | - bind_NULL | |
| 214 | - ( | |
| 215 | - String name, | |
| 216 | - ) = | |
| 217 | - db_bind(force(sub_string(name, 1, length(name) - 1), name), null). | |
| 218 | - | |
| 219 | - | |
| 184 | + | ... | ... |
database/migration.anubis
| ... | ... | @@ -10,15 +10,15 @@ read tools/basis.anubis |
| 10 | 10 | read system/files.anubis |
| 11 | 11 | read system/logger.anubis |
| 12 | 12 | read system/string.anubis |
| 13 | -read data_base/db_tools.anubis | |
| 13 | +read data_base/alter_table.anubis | |
| 14 | +read data_base/sqlite.anubis | |
| 14 | 15 | |
| 15 | 16 | read calexium_lib/database/db_utils.anubis |
| 16 | -read calexium_lib/database/alter_table.anubis | |
| 17 | 17 | read calexium_lib/net_services_protocols/logger_service.anubis |
| 18 | 18 | |
| 19 | 19 | read mf_constants.anubis |
| 20 | 20 | |
| 21 | - read settings.anubis | |
| 21 | +read settings.anubis | |
| 22 | 22 | read migration_common.anubis |
| 23 | 23 | |
| 24 | 24 | read tools/mf_loggers.anubis |
| ... | ... | @@ -60,27 +60,44 @@ public define Int |
| 60 | 60 | }, |
| 61 | 61 | compare(split(version1, '.'), split(version2, '.')). |
| 62 | 62 | |
| 63 | +define String | |
| 64 | + get_version_settings | |
| 65 | + ( | |
| 66 | + SQLite3DataBase db | |
| 67 | + )= | |
| 68 | + if is_table_exists(db, "settings") then | |
| 69 | + select_settings(db, "MF_version", "0.0.0.0") | |
| 70 | + else "0.0.0.0". | |
| 71 | + | |
| 72 | +public define One | |
| 73 | + update_version_settings | |
| 74 | + ( | |
| 75 | + SQLite3DataBase db, | |
| 76 | + String version | |
| 77 | + )= | |
| 78 | + update_settings(db, "MF_version", version). | |
| 79 | + | |
| 63 | 80 | public define Maybe(One) |
| 64 | 81 | backup_database |
| 65 | 82 | ( |
| 66 | 83 | Logger logger, |
| 67 | -// String current_version, | |
| 84 | + String current_version, | |
| 68 | 85 | String db_path, |
| 69 | 86 | String main_db_name, |
| 70 | 87 | List(String) other_db_names, |
| 71 | 88 | ) |
| 72 | 89 | = |
| 73 | -// with should_copy = if file_exists(db_path + main_db_name) then | |
| 74 | -// if sqlite3_open(db_path + main_db_name) is | |
| 75 | -// { | |
| 76 | -// error(sql_error) then false, // maybe not created yet | |
| 77 | -// ok(Database db) then | |
| 78 | -// with ver = get_version_settings(db), | |
| 79 | -// ver != current_version | |
| 80 | -// } | |
| 81 | -// else false, | |
| 90 | + with should_copy = if file_exists(db_path + main_db_name) then | |
| 91 | + if sqlite3_open(db_path + main_db_name) is | |
| 92 | + { | |
| 93 | + error(sql_error) then false, // maybe not created yet | |
| 94 | + ok(SQLite3DataBase db) then | |
| 95 | + with ver = get_version_settings(db), | |
| 96 | + ver != current_version | |
| 97 | + } | |
| 98 | + else false, | |
| 82 | 99 | |
| 83 | - //if should_copy then | |
| 100 | + if should_copy then | |
| 84 | 101 | with dir_save = db_path + dir_save_database, |
| 85 | 102 | if (Maybe(String))make_directory(dir_save) is |
| 86 | 103 | { |
| ... | ... | @@ -111,7 +128,7 @@ public define Maybe(One) |
| 111 | 128 | }, |
| 112 | 129 | copy_db([main_db_name . other_db_names]) |
| 113 | 130 | } |
| 114 | - //else success(unique) | |
| 131 | + else success(unique) | |
| 115 | 132 | . |
| 116 | 133 | |
| 117 | 134 | |
| ... | ... | @@ -121,9 +138,9 @@ public define Maybe(One) |
| 121 | 138 | |
| 122 | 139 | public type Migration: |
| 123 | 140 | migration(String version, |
| 124 | - (Database, Logger) -> Maybe(One) migrate_to, | |
| 125 | - (Database, Logger) -> Maybe(One) create_tables, | |
| 126 | - (Database, Logger) -> Maybe(One) create_indexes, | |
| 141 | + (SQLite3DataBase, Logger) -> Maybe(One) migrate_to, | |
| 142 | + (SQLite3DataBase, Logger) -> Maybe(One) create_tables, | |
| 143 | + (SQLite3DataBase, Logger) -> Maybe(One) create_indexes, | |
| 127 | 144 | ). |
| 128 | 145 | |
| 129 | 146 | |
| ... | ... | @@ -131,13 +148,12 @@ public type Migration: |
| 131 | 148 | define Maybe(One) |
| 132 | 149 | do_migration_loop |
| 133 | 150 | ( |
| 134 | - Database db, | |
| 151 | + SQLite3DataBase db, | |
| 135 | 152 | Logger logger, |
| 136 | 153 | String current_version, |
| 137 | 154 | String db_ver, |
| 138 | 155 | List(Migration) migrations, |
| 139 | - Maybe(Migration) need_to_create_table, // success in case of new DB or when no migration have been done | |
| 140 | - (Database, String) -> One update_db_version, | |
| 156 | + Maybe(Migration) need_to_create_table // success in case of new DB or when no migration have been done | |
| 141 | 157 | ) = |
| 142 | 158 | if migrations is |
| 143 | 159 | { |
| ... | ... | @@ -145,13 +161,13 @@ define Maybe(One) |
| 145 | 161 | if need_to_create_table is |
| 146 | 162 | { |
| 147 | 163 | failure then |
| 148 | - update_db_version(db, current_version); | |
| 164 | + update_version_settings(db, current_version); | |
| 149 | 165 | success(unique), |
| 150 | 166 | success(last) then |
| 151 | 167 | if last is migration(_, _, create_tables, create_indexes) then |
| 152 | 168 | if create_tables(db, logger) is success(_) then |
| 153 | 169 | if create_indexes(db, logger) is success(_) then |
| 154 | - update_db_version(db, current_version); | |
| 170 | + update_version_settings(db, current_version); | |
| 155 | 171 | success(unique) |
| 156 | 172 | else |
| 157 | 173 | failure |
| ... | ... | @@ -165,9 +181,9 @@ define Maybe(One) |
| 165 | 181 | if migrate_to(db, logger) is failure then |
| 166 | 182 | failure |
| 167 | 183 | else |
| 168 | - do_migration_loop(db, logger, current_version, version, t, failure, update_db_version) | |
| 184 | + do_migration_loop(db, logger, current_version, version, t, failure) | |
| 169 | 185 | else |
| 170 | - do_migration_loop(db, logger, current_version, db_ver, t, success(h), update_db_version), | |
| 186 | + do_migration_loop(db, logger, current_version, db_ver, t, success(h)), | |
| 171 | 187 | }. |
| 172 | 188 | |
| 173 | 189 | |
| ... | ... | @@ -175,26 +191,24 @@ define Maybe(One) |
| 175 | 191 | public define Maybe(One) |
| 176 | 192 | do_migration |
| 177 | 193 | ( |
| 178 | - Database db, | |
| 179 | - Logger logger, | |
| 180 | - String current_version, | |
| 181 | - (Database) -> String get_db_version, | |
| 182 | - (Database, String) -> One update_db_version, | |
| 183 | - List(Migration) all_migrations, | |
| 194 | + SQLite3DataBase db, | |
| 195 | + Logger logger, | |
| 196 | + String current_version, | |
| 197 | + List(Migration) all_migrations, | |
| 184 | 198 | )= |
| 185 | 199 | if is_empty_database(db) then // new empty database |
| 186 | 200 | logInfo(logger, "No database found. Creating a new one..."); |
| 187 | - do_migration_loop(db, logger, current_version, "", [], last(all_migrations), update_db_version) | |
| 201 | + do_migration_loop(db, logger, current_version, "", [], last(all_migrations)) | |
| 188 | 202 | else |
| 189 | 203 | ( |
| 190 | - with db_version = get_db_version(db), | |
| 191 | - do_migration_loop(db, logger, current_version, db_version, all_migrations, failure, update_db_version) | |
| 204 | + with db_version = get_version_settings(db), | |
| 205 | + do_migration_loop(db, logger, current_version, db_version, all_migrations, failure) | |
| 192 | 206 | ). |
| 193 | 207 | |
| 194 | 208 | public define Maybe(One) |
| 195 | 209 | do_create_indexes |
| 196 | 210 | ( |
| 197 | - Database db, | |
| 211 | + SQLite3DataBase db, | |
| 198 | 212 | Logger logger, |
| 199 | 213 | String current_version, |
| 200 | 214 | List(Migration) all_migrations, | ... | ... |
database/migration_common.anubis
| ... | ... | @@ -8,9 +8,9 @@ |
| 8 | 8 | |
| 9 | 9 | read tools/basis.anubis |
| 10 | 10 | read system/logger.anubis |
| 11 | -read data_base/db_tools.anubis | |
| 12 | -read alter_table.anubis | |
| 13 | -read sqlite_foreign_key.anubis | |
| 11 | +read data_base/sqlite.anubis | |
| 12 | +read data_base/alter_table.anubis | |
| 13 | +read data_base/sqlite_foreign_key.anubis | |
| 14 | 14 | |
| 15 | 15 | read calexium_lib/database/db_utils.anubis |
| 16 | 16 | read calexium_lib/net_services_protocols/logger_service.anubis |
| ... | ... | @@ -27,11 +27,11 @@ public type DbTable: |
| 27 | 27 | public define Bool |
| 28 | 28 | is_table_exists |
| 29 | 29 | ( |
| 30 | - Database db, | |
| 30 | + SQLite3DataBase db, | |
| 31 | 31 | String dbName, |
| 32 | 32 | String table_name |
| 33 | 33 | )= |
| 34 | - if sql_query_timeout(db, "SELECT * FROM " + dbName + ".sqlite_master WHERE type ='table' AND name = :table_name", [db_bind("table_name", db_text(table_name))], "is_table_exists("+table_name+")") is | |
| 34 | + if sql_query_timeout(db, "SELECT * FROM " + dbName + ".sqlite_master WHERE type ='table' AND name = @table_name", [bind_String("@table_name", table_name)], "is_table_exists("+table_name+")") is | |
| 35 | 35 | { |
| 36 | 36 | error(_) then false, //error in the SQL request |
| 37 | 37 | ok(_, cursor, _) then |
| ... | ... | @@ -46,7 +46,7 @@ public define Bool |
| 46 | 46 | public define Bool |
| 47 | 47 | is_table_exists |
| 48 | 48 | ( |
| 49 | - Database db, | |
| 49 | + SQLite3DataBase db, | |
| 50 | 50 | String table_name |
| 51 | 51 | )= |
| 52 | 52 | is_table_exists(db, "main", table_name). |
| ... | ... | @@ -54,7 +54,7 @@ public define Bool |
| 54 | 54 | public define Bool |
| 55 | 55 | is_empty_database |
| 56 | 56 | ( |
| 57 | - Database db, | |
| 57 | + SQLite3DataBase db, | |
| 58 | 58 | String dbName, |
| 59 | 59 | )= |
| 60 | 60 | if sql_query_timeout(db, "SELECT * FROM " + dbName + ".sqlite_master", [], "is_empty_database("+dbName+")") is |
| ... | ... | @@ -72,21 +72,21 @@ public define Bool |
| 72 | 72 | public define Bool |
| 73 | 73 | is_empty_database |
| 74 | 74 | ( |
| 75 | - Database db, | |
| 75 | + SQLite3DataBase db, | |
| 76 | 76 | )= |
| 77 | 77 | is_empty_database(db, "main"). |
| 78 | 78 | |
| 79 | 79 | public define Maybe(One) |
| 80 | 80 | drop_all_triggers |
| 81 | 81 | ( |
| 82 | - Database db, | |
| 82 | + SQLite3DataBase db, | |
| 83 | 83 | Logger log |
| 84 | 84 | ) = |
| 85 | - if db_query(db, "SELECT name FROM sqlite_master WHERE type = 'trigger'", []) is | |
| 85 | + if sqlite3_query(db, "SELECT name FROM sqlite_master WHERE type = 'trigger'", []) is | |
| 86 | 86 | { |
| 87 | 87 | error(err) then logError(log, db_error(err, "drop_all_triggers")); failure, |
| 88 | 88 | ok(_, cursor, _) then |
| 89 | - with drop_trigger = (String name) |-> if db_query(db, "DROP TRIGGER " + name, []) is | |
| 89 | + with drop_trigger = (String name) |-> if sqlite3_query(db, "DROP TRIGGER " + name, []) is | |
| 90 | 90 | { |
| 91 | 91 | error(err2) then logError(log, db_error(err2, "Failed to drop trigger '" + name + "'")), |
| 92 | 92 | ok(_, cursor, _) then unique |
| ... | ... | @@ -98,7 +98,7 @@ public define Maybe(One) |
| 98 | 98 | public define Maybe(One) |
| 99 | 99 | create_tables |
| 100 | 100 | ( |
| 101 | - Database db, | |
| 101 | + SQLite3DataBase db, | |
| 102 | 102 | Logger logger, |
| 103 | 103 | List(DbTable) tables, |
| 104 | 104 | String version_string |
| ... | ... | @@ -134,7 +134,7 @@ public define Maybe(One) |
| 134 | 134 | public define Maybe(One) |
| 135 | 135 | create_indexes |
| 136 | 136 | ( |
| 137 | - Database db, | |
| 137 | + SQLite3DataBase db, | |
| 138 | 138 | Logger logger, |
| 139 | 139 | List(String) indexes, |
| 140 | 140 | String version_string |
| ... | ... | @@ -155,7 +155,7 @@ public define Maybe(One) |
| 155 | 155 | public define One |
| 156 | 156 | make_foreign_key |
| 157 | 157 | ( |
| 158 | - Database db, | |
| 158 | + SQLite3DataBase db, | |
| 159 | 159 | String table_name, |
| 160 | 160 | String field_name, |
| 161 | 161 | String foreign_table_name, |
| ... | ... | @@ -175,7 +175,7 @@ public define One |
| 175 | 175 | public define Maybe(One) |
| 176 | 176 | make_foreign_keys |
| 177 | 177 | ( |
| 178 | - Database db, | |
| 178 | + SQLite3DataBase db, | |
| 179 | 179 | Logger logger, |
| 180 | 180 | List((String, String, String, String, FK_Null, FK_Cascade)) relations, |
| 181 | 181 | String version_string | ... | ... |
database/settings.anubis
| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | |
| 8 | 8 | read tools/basis.anubis |
| 9 | 9 | read data_base/db_tools.anubis |
| 10 | +read data_base/sqlite.anubis | |
| 10 | 11 | |
| 11 | 12 | read calexium_lib/database/db_utils.anubis |
| 12 | 13 | |
| ... | ... | @@ -77,17 +78,47 @@ public define Bool |
| 77 | 78 | success(v) then v!=0 |
| 78 | 79 | } |
| 79 | 80 | }. |
| 81 | + | |
| 82 | +public define One | |
| 83 | + update_settings | |
| 84 | + ( | |
| 85 | + SQLite3DataBase db, | |
| 86 | + String var, | |
| 87 | + Bool value | |
| 88 | + )= | |
| 89 | + with binds = (List(SQLite3Bind))[bind_String("@name", var), bind_Int("@value", if value then 1 else 0)], | |
| 90 | + if select_settings(db, var) is success(_) then | |
| 91 | + forget(sql_query_timeout(db, "UPDATE settings SET var_value = @value WHERE var_name = @name;", binds, "update_settings")) | |
| 92 | + else | |
| 93 | + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (@name, @value)", binds, "update_settings")) | |
| 94 | + . | |
| 80 | 95 | |
| 81 | 96 | public define One |
| 82 | 97 | update_settings |
| 83 | 98 | ( |
| 84 | 99 | Database db, |
| 85 | 100 | String var, |
| 101 | + Int value | |
| 102 | + )= | |
| 103 | + with binds = (List(SQLite3Bind))[bind_String("@name", var), bind_Int("@value", value)], | |
| 104 | + if select_settings(db, var) is success(_) then | |
| 105 | + forget(sql_query_timeout(db, "UPDATE settings SET var_value = @value WHERE var_name = @name;", binds, "update_settings")) | |
| 106 | + else | |
| 107 | + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (@name, @value)", binds, "update_settings")) | |
| 108 | + . | |
| 109 | + | |
| 110 | + | |
| 111 | +public define One | |
| 112 | + update_settings | |
| 113 | + ( | |
| 114 | + SQLite3DataBase db, | |
| 115 | + String var, | |
| 86 | 116 | String value |
| 87 | 117 | )= |
| 118 | + with binds = (List(SQLite3Bind))[bind_String("@name", var), bind_String("@value", value)], | |
| 88 | 119 | if select_settings(db, var) is success(_) then |
| 89 | - forget(sql_query_timeout(db, "UPDATE settings SET var_value = @value WHERE var_name = @name;", [bind_String("@name", var), bind_String("@value", value)], "update_settings")) | |
| 120 | + forget(sql_query_timeout(db, "UPDATE settings SET var_value = @value WHERE var_name = @name;", binds, "update_settings")) | |
| 90 | 121 | else |
| 91 | - forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (@name, @value)", [bind_String("@name", var), bind_String("@value", value)], "update_settings")) | |
| 122 | + forget(sql_query_timeout(db, "INSERT INTO settings (var_name, var_value) VALUES (@name, @value)", binds, "update_settings")) | |
| 92 | 123 | . |
| 93 | 124 | ... | ... |
mail/smtp_client.anubis
| ... | ... | @@ -406,9 +406,9 @@ define Maybe(One) |
| 406 | 406 | { |
| 407 | 407 | failure then failure, |
| 408 | 408 | success(nb_write) then |
| 409 | - if now - buffer_start_time > 120 then | |
| 409 | + if now - buffer_start_time > 3600 then | |
| 410 | 410 | // security to avoid queue blocking |
| 411 | - logger(logError, "sm_flush: TIMEOUT sending a " + length(buffer) + " byte-length buffer (taking more than 2 minutes). SendMail canceled."); | |
| 411 | + logger(logError, "sm_flush: TIMEOUT sending a 64kb buffer (taking more than 1 hour). SendMail canceled."); | |
| 412 | 412 | failure |
| 413 | 413 | else |
| 414 | 414 | with buffer_size = length(buffer), |
| ... | ... | @@ -427,38 +427,44 @@ define SendContentResult |
| 427 | 427 | SmtpClientSession session, |
| 428 | 428 | Int start_time, |
| 429 | 429 | Int so_far, |
| 430 | - Int last_reply_check, | |
| 431 | 430 | (Int) -> One progress_report, |
| 432 | 431 | (LogLevel, String) -> One logger |
| 433 | 432 | ) = |
| 434 | - if last_reply_check + 60 < now then | |
| 435 | - if receive_reply(weaken(target), [], session.enhanced_status, 0, logger) is | |
| 436 | - { | |
| 437 | - error then copy_error(so_far), | |
| 438 | - timeout then | |
| 439 | - sm_copy_Data_IO_to_Stream(source, target, session, start_time, so_far, now, progress_report, logger) | |
| 440 | - no_auth_method then copy_error(so_far), // impossible | |
| 441 | - bad_reply then copy_error(so_far), | |
| 442 | - reply(code, status, lines) then | |
| 443 | - smtp_reply(reply(code, status, lines)) | |
| 444 | - } | |
| 445 | - else | |
| 446 | - if read_line(source, 1024) is | |
| 433 | + if receive_reply(weaken(target), [], session.enhanced_status, 0, logger) is | |
| 434 | + { | |
| 435 | + error then copy_error(so_far), | |
| 436 | + timeout then | |
| 437 | + if read_bytes(source, 65536) is | |
| 447 | 438 | { |
| 448 | - error then logger(logError, "send_content: failed to read input data_io"); copy_error(so_far), | |
| 449 | - timeout then logger(logError, "send_content: timeout reading input data_io"); copy_error(so_far), | |
| 450 | - eof then copy_ok(so_far), | |
| 451 | - ok(line) then | |
| 452 | - with buffer = to_byte_array((if nth(0, line) is success(char) then if char = '.' then "." + line else line else line)), | |
| 439 | + failure then logger(logError, "send_content: failed to read input data_io"); copy_error(so_far), | |
| 440 | + time_out then logger(logError, "send_content: timeout reading input data_io"); copy_error(so_far), | |
| 441 | + success(buffer) then | |
| 453 | 442 | if sm_flush( buffer, weaken(target), now, logger ) is |
| 454 | 443 | { |
| 455 | 444 | failure then copy_error(so_far), |
| 456 | 445 | success(_) then |
| 457 | - with len = length(line) + 2, // 2 is for the CRLF | |
| 458 | - progress_report(so_far + len); | |
| 459 | - sm_copy_Data_IO_to_Stream(source, target, session, start_time, so_far + len, last_reply_check, progress_report, logger) | |
| 446 | + progress_report(so_far + 65536); | |
| 447 | + sm_copy_Data_IO_to_Stream(source, target, session, start_time, so_far + 65536, progress_report, logger) | |
| 460 | 448 | }, |
| 461 | - }. | |
| 449 | + | |
| 450 | + truncated(buffer) then | |
| 451 | + with len = length(buffer), | |
| 452 | + if len = 0 then | |
| 453 | + copy_ok(so_far) | |
| 454 | + else | |
| 455 | + if sm_flush( buffer, weaken(target), now, logger ) is | |
| 456 | + { | |
| 457 | + failure then copy_error(so_far), | |
| 458 | + success(_) then | |
| 459 | + progress_report(so_far + len); | |
| 460 | + copy_ok(so_far + len) | |
| 461 | + } | |
| 462 | + }, | |
| 463 | + no_auth_method then copy_error(so_far), // impossible | |
| 464 | + bad_reply then copy_error(so_far), | |
| 465 | + reply(code, status, lines) then | |
| 466 | + smtp_reply(reply(code, status, lines)) | |
| 467 | + }. | |
| 462 | 468 | |
| 463 | 469 | define SendContentResult |
| 464 | 470 | sm_copy_Data_IO_List_to_Stream |
| ... | ... | @@ -476,7 +482,7 @@ define SendContentResult |
| 476 | 482 | [] then copy_ok(so_far), |
| 477 | 483 | [ h . t ] then |
| 478 | 484 | if rewind(h)(unique) then |
| 479 | - with result = sm_copy_Data_IO_to_Stream(h, target, session, start_time, 0, now, progress_report, logger), | |
| 485 | + with result = sm_copy_Data_IO_to_Stream(h, target, session, start_time, 0, progress_report, logger), | |
| 480 | 486 | if result is copy_ok(written) then |
| 481 | 487 | sm_copy_Data_IO_List_to_Stream(t, target, session, start_time, so_far + written, progress_report, logger) |
| 482 | 488 | else | ... | ... |
web/CXM_making_a_web_site.anubis
| ... | ... | @@ -2267,7 +2267,7 @@ public define Web_Site |
| 2267 | 2267 | // |
| 2268 | 2268 | // make required directories (if needed) |
| 2269 | 2269 | // |
| 2270 | - with //web_sites_directory = (String) make_directory(my_anubis_directory+"/web_sites"), | |
| 2270 | + with web_sites_directory = (String) make_directory(my_anubis_directory+"/web_sites"), | |
| 2271 | 2271 | base_directory = (String) make_directory(site_directory), |
| 2272 | 2272 | // state_directory = make_directory(site_directory+"/states"), |
| 2273 | 2273 | forget((String)make_directory(site_directory+"/public")); | ... | ... |