Commit c4c07f3ed6be1903cd6db2c668fb0f4768022897
Merge
Showing
6 changed files
with
159 additions
and
143 deletions
Show diff stats
database/db_utils.anubis
| @@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
| 10 | read tools/basis.anubis | 10 | read tools/basis.anubis |
| 11 | read system/logger.anubis | 11 | read system/logger.anubis |
| 12 | read system/string.anubis | 12 | read system/string.anubis |
| 13 | -read data_base/db_tools.anubis | 13 | +read data_base/sqlite.anubis |
| 14 | 14 | ||
| 15 | read calexium_lib/net_services_protocols/logger_service.anubis | 15 | read calexium_lib/net_services_protocols/logger_service.anubis |
| 16 | 16 | ||
| @@ -33,10 +33,10 @@ define One | @@ -33,10 +33,10 @@ define One | ||
| 33 | else | 33 | else |
| 34 | unique. | 34 | unique. |
| 35 | 35 | ||
| 36 | -public define Result(DbError, One) | 36 | +public define Result(SQLite3Error, One) |
| 37 | sql_transaction | 37 | sql_transaction |
| 38 | ( | 38 | ( |
| 39 | - Database db, | 39 | + SQLite3DataBase db, |
| 40 | String sql_command, | 40 | String sql_command, |
| 41 | String message | 41 | String message |
| 42 | ) = | 42 | ) = |
| @@ -45,15 +45,14 @@ public define Result(DbError, One) | @@ -45,15 +45,14 @@ public define Result(DbError, One) | ||
| 45 | if db_do_transaction( | 45 | if db_do_transaction( |
| 46 | db, | 46 | db, |
| 47 | (One _) |-> | 47 | (One _) |-> |
| 48 | - if db_query(db, sql_command) is | 48 | + if sql_query(db, sql_command) is |
| 49 | { | 49 | { |
| 50 | error(err) then logError("DB", db_error(err,message));failure //error in the SQL request | 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 | 60000, // max 60s | 54 | 60000, // max 60s |
| 55 | - 100, // retry every 100 ms | ||
| 56 | - (DbError _) |-> false | 55 | + 100 // retry every 100 ms |
| 57 | ) is | 56 | ) is |
| 58 | { | 57 | { |
| 59 | error(err_and_result) then | 58 | error(err_and_result) then |
| @@ -66,19 +65,19 @@ public define Result(DbError, One) | @@ -66,19 +65,19 @@ public define Result(DbError, One) | ||
| 66 | ok(unique) | 65 | ok(unique) |
| 67 | }. | 66 | }. |
| 68 | 67 | ||
| 68 | + | ||
| 69 | 69 | ||
| 70 | - | ||
| 71 | -public define DbQueryResult | 70 | +public define SQLite3QueryResult |
| 72 | sql_query_timeout | 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 | //we try with 30 sec of timeout | 78 | //we try with 30 sec of timeout |
| 80 | with t0 = unow, | 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 | error(sql_error) then logError("DB", db_error(sql_error,msg)); | 82 | error(sql_error) then logError("DB", db_error(sql_error,msg)); |
| 84 | __logLongQueries(t0, sql_query); | 83 | __logLongQueries(t0, sql_query); |
| @@ -89,16 +88,16 @@ public define DbQueryResult | @@ -89,16 +88,16 @@ public define DbQueryResult | ||
| 89 | }. | 88 | }. |
| 90 | 89 | ||
| 91 | // deprecated. Use one of the previous ones. | 90 | // deprecated. Use one of the previous ones. |
| 92 | -public define Maybe(SQLite3HeadersOrRow -> DbRow) | 91 | +public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) |
| 93 | sql_query_timeout | 92 | sql_query_timeout |
| 94 | ( | 93 | ( |
| 95 | - Database db, //database handle | 94 | + SQLite3DataBase db, //database handle |
| 96 | String sql_query, //sql query itself | 95 | String sql_query, //sql query itself |
| 97 | String msg //message to be shown if an error occure | 96 | String msg //message to be shown if an error occure |
| 98 | ) = | 97 | ) = |
| 99 | //we try with 30 sec of timeout | 98 | //we try with 30 sec of timeout |
| 100 | with t0 = unow, | 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 | error(sql_error) then logError("DB", db_error(sql_error,msg)); | 102 | error(sql_error) then logError("DB", db_error(sql_error,msg)); |
| 104 | __logLongQueries(t0, sql_query); | 103 | __logLongQueries(t0, sql_query); |
| @@ -108,7 +107,7 @@ public define Maybe(SQLite3HeadersOrRow -> DbRow) | @@ -108,7 +107,7 @@ public define Maybe(SQLite3HeadersOrRow -> DbRow) | ||
| 108 | success((SQLite3HeadersOrRow h_or_r) |-> if h_or_r is | 107 | success((SQLite3HeadersOrRow h_or_r) |-> if h_or_r is |
| 109 | { | 108 | { |
| 110 | headers then | 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 | row((Int n) |-> force(nth(n, cols), no_such_column)), | 111 | row((Int n) |-> force(nth(n, cols), no_such_column)), |
| 113 | next_row then cursor(unique) | 112 | next_row then cursor(unique) |
| 114 | }) | 113 | }) |
| @@ -119,8 +118,8 @@ public define Maybe(SQLite3HeadersOrRow -> DbRow) | @@ -119,8 +118,8 @@ public define Maybe(SQLite3HeadersOrRow -> DbRow) | ||
| 119 | public define List(String) | 118 | public define List(String) |
| 120 | db_get_string_list | 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 | if table_cursor(unique) is | 124 | if table_cursor(unique) is |
| 126 | { | 125 | { |
| @@ -135,7 +134,7 @@ public define List(String) | @@ -135,7 +134,7 @@ public define List(String) | ||
| 135 | public define List(String) | 134 | public define List(String) |
| 136 | db_get_string_list | 135 | db_get_string_list |
| 137 | ( | 136 | ( |
| 138 | - SQLite3HeadersOrRow -> DbRow table_cursor, | 137 | + SQLite3HeadersOrRow -> SQLite3Row table_cursor, |
| 139 | List(String) so_far | 138 | List(String) so_far |
| 140 | ) = | 139 | ) = |
| 141 | if table_cursor(next_row) is | 140 | if table_cursor(next_row) is |
| @@ -147,11 +146,10 @@ public define List(String) | @@ -147,11 +146,10 @@ public define List(String) | ||
| 147 | db_get_string_list(table_cursor, [s . so_far]) | 146 | db_get_string_list(table_cursor, [s . so_far]) |
| 148 | }. | 147 | }. |
| 149 | 148 | ||
| 150 | -// Old sqlite3 API | ||
| 151 | public define List(Int) | 149 | public define List(Int) |
| 152 | db_get_integer_list | 150 | db_get_integer_list |
| 153 | ( | 151 | ( |
| 154 | - SQLite3HeadersOrRow -> DbRow table_cursor, | 152 | + SQLite3HeadersOrRow -> SQLite3Row table_cursor, |
| 155 | List(Int) so_far | 153 | List(Int) so_far |
| 156 | ) = | 154 | ) = |
| 157 | if table_cursor(next_row) is | 155 | if table_cursor(next_row) is |
| @@ -167,7 +165,7 @@ public define List(Int) | @@ -167,7 +165,7 @@ public define List(Int) | ||
| 167 | public define List(Int) | 165 | public define List(Int) |
| 168 | db_get_integer_list | 166 | db_get_integer_list |
| 169 | ( | 167 | ( |
| 170 | - One -> DbRow table_cursor, | 168 | + One -> SQLite3Row table_cursor, |
| 171 | List(Int) so_far | 169 | List(Int) so_far |
| 172 | ) = | 170 | ) = |
| 173 | if table_cursor(unique) is | 171 | if table_cursor(unique) is |
| @@ -183,37 +181,4 @@ public define List(Int) | @@ -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,15 +10,15 @@ read tools/basis.anubis | ||
| 10 | read system/files.anubis | 10 | read system/files.anubis |
| 11 | read system/logger.anubis | 11 | read system/logger.anubis |
| 12 | read system/string.anubis | 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 | read calexium_lib/database/db_utils.anubis | 16 | read calexium_lib/database/db_utils.anubis |
| 16 | -read calexium_lib/database/alter_table.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 mf_constants.anubis | 19 | read mf_constants.anubis |
| 20 | 20 | ||
| 21 | - read settings.anubis | 21 | +read settings.anubis |
| 22 | read migration_common.anubis | 22 | read migration_common.anubis |
| 23 | 23 | ||
| 24 | read tools/mf_loggers.anubis | 24 | read tools/mf_loggers.anubis |
| @@ -60,27 +60,44 @@ public define Int | @@ -60,27 +60,44 @@ public define Int | ||
| 60 | }, | 60 | }, |
| 61 | compare(split(version1, '.'), split(version2, '.')). | 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 | public define Maybe(One) | 80 | public define Maybe(One) |
| 64 | backup_database | 81 | backup_database |
| 65 | ( | 82 | ( |
| 66 | Logger logger, | 83 | Logger logger, |
| 67 | -// String current_version, | 84 | + String current_version, |
| 68 | String db_path, | 85 | String db_path, |
| 69 | String main_db_name, | 86 | String main_db_name, |
| 70 | List(String) other_db_names, | 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 | with dir_save = db_path + dir_save_database, | 101 | with dir_save = db_path + dir_save_database, |
| 85 | if (Maybe(String))make_directory(dir_save) is | 102 | if (Maybe(String))make_directory(dir_save) is |
| 86 | { | 103 | { |
| @@ -111,7 +128,7 @@ public define Maybe(One) | @@ -111,7 +128,7 @@ public define Maybe(One) | ||
| 111 | }, | 128 | }, |
| 112 | copy_db([main_db_name . other_db_names]) | 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,9 +138,9 @@ public define Maybe(One) | ||
| 121 | 138 | ||
| 122 | public type Migration: | 139 | public type Migration: |
| 123 | migration(String version, | 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,13 +148,12 @@ public type Migration: | ||
| 131 | define Maybe(One) | 148 | define Maybe(One) |
| 132 | do_migration_loop | 149 | do_migration_loop |
| 133 | ( | 150 | ( |
| 134 | - Database db, | 151 | + SQLite3DataBase db, |
| 135 | Logger logger, | 152 | Logger logger, |
| 136 | String current_version, | 153 | String current_version, |
| 137 | String db_ver, | 154 | String db_ver, |
| 138 | List(Migration) migrations, | 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 | if migrations is | 158 | if migrations is |
| 143 | { | 159 | { |
| @@ -145,13 +161,13 @@ define Maybe(One) | @@ -145,13 +161,13 @@ define Maybe(One) | ||
| 145 | if need_to_create_table is | 161 | if need_to_create_table is |
| 146 | { | 162 | { |
| 147 | failure then | 163 | failure then |
| 148 | - update_db_version(db, current_version); | 164 | + update_version_settings(db, current_version); |
| 149 | success(unique), | 165 | success(unique), |
| 150 | success(last) then | 166 | success(last) then |
| 151 | if last is migration(_, _, create_tables, create_indexes) then | 167 | if last is migration(_, _, create_tables, create_indexes) then |
| 152 | if create_tables(db, logger) is success(_) then | 168 | if create_tables(db, logger) is success(_) then |
| 153 | if create_indexes(db, logger) is success(_) then | 169 | if create_indexes(db, logger) is success(_) then |
| 154 | - update_db_version(db, current_version); | 170 | + update_version_settings(db, current_version); |
| 155 | success(unique) | 171 | success(unique) |
| 156 | else | 172 | else |
| 157 | failure | 173 | failure |
| @@ -165,9 +181,9 @@ define Maybe(One) | @@ -165,9 +181,9 @@ define Maybe(One) | ||
| 165 | if migrate_to(db, logger) is failure then | 181 | if migrate_to(db, logger) is failure then |
| 166 | failure | 182 | failure |
| 167 | else | 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 | else | 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,26 +191,24 @@ define Maybe(One) | ||
| 175 | public define Maybe(One) | 191 | public define Maybe(One) |
| 176 | do_migration | 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 | if is_empty_database(db) then // new empty database | 199 | if is_empty_database(db) then // new empty database |
| 186 | logInfo(logger, "No database found. Creating a new one..."); | 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 | else | 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 | public define Maybe(One) | 208 | public define Maybe(One) |
| 195 | do_create_indexes | 209 | do_create_indexes |
| 196 | ( | 210 | ( |
| 197 | - Database db, | 211 | + SQLite3DataBase db, |
| 198 | Logger logger, | 212 | Logger logger, |
| 199 | String current_version, | 213 | String current_version, |
| 200 | List(Migration) all_migrations, | 214 | List(Migration) all_migrations, |
database/migration_common.anubis
| @@ -8,9 +8,9 @@ | @@ -8,9 +8,9 @@ | ||
| 8 | 8 | ||
| 9 | read tools/basis.anubis | 9 | read tools/basis.anubis |
| 10 | read system/logger.anubis | 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 | read calexium_lib/database/db_utils.anubis | 15 | read calexium_lib/database/db_utils.anubis |
| 16 | read calexium_lib/net_services_protocols/logger_service.anubis | 16 | read calexium_lib/net_services_protocols/logger_service.anubis |
| @@ -27,11 +27,11 @@ public type DbTable: | @@ -27,11 +27,11 @@ public type DbTable: | ||
| 27 | public define Bool | 27 | public define Bool |
| 28 | is_table_exists | 28 | is_table_exists |
| 29 | ( | 29 | ( |
| 30 | - Database db, | 30 | + SQLite3DataBase db, |
| 31 | String dbName, | 31 | String dbName, |
| 32 | String table_name | 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 | error(_) then false, //error in the SQL request | 36 | error(_) then false, //error in the SQL request |
| 37 | ok(_, cursor, _) then | 37 | ok(_, cursor, _) then |
| @@ -46,7 +46,7 @@ public define Bool | @@ -46,7 +46,7 @@ public define Bool | ||
| 46 | public define Bool | 46 | public define Bool |
| 47 | is_table_exists | 47 | is_table_exists |
| 48 | ( | 48 | ( |
| 49 | - Database db, | 49 | + SQLite3DataBase db, |
| 50 | String table_name | 50 | String table_name |
| 51 | )= | 51 | )= |
| 52 | is_table_exists(db, "main", table_name). | 52 | is_table_exists(db, "main", table_name). |
| @@ -54,7 +54,7 @@ public define Bool | @@ -54,7 +54,7 @@ public define Bool | ||
| 54 | public define Bool | 54 | public define Bool |
| 55 | is_empty_database | 55 | is_empty_database |
| 56 | ( | 56 | ( |
| 57 | - Database db, | 57 | + SQLite3DataBase db, |
| 58 | String dbName, | 58 | String dbName, |
| 59 | )= | 59 | )= |
| 60 | if sql_query_timeout(db, "SELECT * FROM " + dbName + ".sqlite_master", [], "is_empty_database("+dbName+")") is | 60 | if sql_query_timeout(db, "SELECT * FROM " + dbName + ".sqlite_master", [], "is_empty_database("+dbName+")") is |
| @@ -72,21 +72,21 @@ public define Bool | @@ -72,21 +72,21 @@ public define Bool | ||
| 72 | public define Bool | 72 | public define Bool |
| 73 | is_empty_database | 73 | is_empty_database |
| 74 | ( | 74 | ( |
| 75 | - Database db, | 75 | + SQLite3DataBase db, |
| 76 | )= | 76 | )= |
| 77 | is_empty_database(db, "main"). | 77 | is_empty_database(db, "main"). |
| 78 | 78 | ||
| 79 | public define Maybe(One) | 79 | public define Maybe(One) |
| 80 | drop_all_triggers | 80 | drop_all_triggers |
| 81 | ( | 81 | ( |
| 82 | - Database db, | 82 | + SQLite3DataBase db, |
| 83 | Logger log | 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 | error(err) then logError(log, db_error(err, "drop_all_triggers")); failure, | 87 | error(err) then logError(log, db_error(err, "drop_all_triggers")); failure, |
| 88 | ok(_, cursor, _) then | 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 | error(err2) then logError(log, db_error(err2, "Failed to drop trigger '" + name + "'")), | 91 | error(err2) then logError(log, db_error(err2, "Failed to drop trigger '" + name + "'")), |
| 92 | ok(_, cursor, _) then unique | 92 | ok(_, cursor, _) then unique |
| @@ -98,7 +98,7 @@ public define Maybe(One) | @@ -98,7 +98,7 @@ public define Maybe(One) | ||
| 98 | public define Maybe(One) | 98 | public define Maybe(One) |
| 99 | create_tables | 99 | create_tables |
| 100 | ( | 100 | ( |
| 101 | - Database db, | 101 | + SQLite3DataBase db, |
| 102 | Logger logger, | 102 | Logger logger, |
| 103 | List(DbTable) tables, | 103 | List(DbTable) tables, |
| 104 | String version_string | 104 | String version_string |
| @@ -134,7 +134,7 @@ public define Maybe(One) | @@ -134,7 +134,7 @@ public define Maybe(One) | ||
| 134 | public define Maybe(One) | 134 | public define Maybe(One) |
| 135 | create_indexes | 135 | create_indexes |
| 136 | ( | 136 | ( |
| 137 | - Database db, | 137 | + SQLite3DataBase db, |
| 138 | Logger logger, | 138 | Logger logger, |
| 139 | List(String) indexes, | 139 | List(String) indexes, |
| 140 | String version_string | 140 | String version_string |
| @@ -155,7 +155,7 @@ public define Maybe(One) | @@ -155,7 +155,7 @@ public define Maybe(One) | ||
| 155 | public define One | 155 | public define One |
| 156 | make_foreign_key | 156 | make_foreign_key |
| 157 | ( | 157 | ( |
| 158 | - Database db, | 158 | + SQLite3DataBase db, |
| 159 | String table_name, | 159 | String table_name, |
| 160 | String field_name, | 160 | String field_name, |
| 161 | String foreign_table_name, | 161 | String foreign_table_name, |
| @@ -175,7 +175,7 @@ public define One | @@ -175,7 +175,7 @@ public define One | ||
| 175 | public define Maybe(One) | 175 | public define Maybe(One) |
| 176 | make_foreign_keys | 176 | make_foreign_keys |
| 177 | ( | 177 | ( |
| 178 | - Database db, | 178 | + SQLite3DataBase db, |
| 179 | Logger logger, | 179 | Logger logger, |
| 180 | List((String, String, String, String, FK_Null, FK_Cascade)) relations, | 180 | List((String, String, String, String, FK_Null, FK_Cascade)) relations, |
| 181 | String version_string | 181 | String version_string |
database/settings.anubis
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | 7 | ||
| 8 | read tools/basis.anubis | 8 | read tools/basis.anubis |
| 9 | read data_base/db_tools.anubis | 9 | read data_base/db_tools.anubis |
| 10 | +read data_base/sqlite.anubis | ||
| 10 | 11 | ||
| 11 | read calexium_lib/database/db_utils.anubis | 12 | read calexium_lib/database/db_utils.anubis |
| 12 | 13 | ||
| @@ -14,7 +15,7 @@ read calexium_lib/database/db_utils.anubis | @@ -14,7 +15,7 @@ read calexium_lib/database/db_utils.anubis | ||
| 14 | public define Maybe(String) | 15 | public define Maybe(String) |
| 15 | select_settings | 16 | select_settings |
| 16 | ( | 17 | ( |
| 17 | - Database db, | 18 | + SQLite3DataBase db, |
| 18 | String var, | 19 | String var, |
| 19 | )= | 20 | )= |
| 20 | if sql_query_timeout(db, "SELECT var_value FROM settings WHERE var_name=" + db_make_sql_string(var) + ";", "select_settings") is | 21 | if sql_query_timeout(db, "SELECT var_value FROM settings WHERE var_name=" + db_make_sql_string(var) + ";", "select_settings") is |
| @@ -32,7 +33,7 @@ public define Maybe(String) | @@ -32,7 +33,7 @@ public define Maybe(String) | ||
| 32 | public define String | 33 | public define String |
| 33 | select_settings | 34 | select_settings |
| 34 | ( | 35 | ( |
| 35 | - Database db, | 36 | + SQLite3DataBase db, |
| 36 | String var, | 37 | String var, |
| 37 | String default | 38 | String default |
| 38 | )= | 39 | )= |
| @@ -45,7 +46,7 @@ public define String | @@ -45,7 +46,7 @@ public define String | ||
| 45 | public define Int | 46 | public define Int |
| 46 | select_settings | 47 | select_settings |
| 47 | ( | 48 | ( |
| 48 | - Database db, | 49 | + SQLite3DataBase db, |
| 49 | String var, | 50 | String var, |
| 50 | Int default | 51 | Int default |
| 51 | )= | 52 | )= |
| @@ -63,7 +64,7 @@ public define Int | @@ -63,7 +64,7 @@ public define Int | ||
| 63 | public define Bool | 64 | public define Bool |
| 64 | select_settings | 65 | select_settings |
| 65 | ( | 66 | ( |
| 66 | - Database db, | 67 | + SQLite3DataBase db, |
| 67 | String var, | 68 | String var, |
| 68 | Bool default | 69 | Bool default |
| 69 | )= | 70 | )= |
| @@ -77,17 +78,47 @@ public define Bool | @@ -77,17 +78,47 @@ public define Bool | ||
| 77 | success(v) then v!=0 | 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 | public define One | 96 | public define One |
| 82 | update_settings | 97 | update_settings |
| 83 | ( | 98 | ( |
| 84 | - Database db, | 99 | + SQLite3DataBase db, |
| 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, | ||
| 85 | String var, | 115 | String var, |
| 86 | String value | 116 | String value |
| 87 | )= | 117 | )= |
| 118 | + with binds = (List(SQLite3Bind))[bind_String("@name", var), bind_String("@value", value)], | ||
| 88 | if select_settings(db, var) is success(_) then | 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 | else | 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,9 +406,9 @@ define Maybe(One) | ||
| 406 | { | 406 | { |
| 407 | failure then failure, | 407 | failure then failure, |
| 408 | success(nb_write) then | 408 | success(nb_write) then |
| 409 | - if now - buffer_start_time > 120 then | 409 | + if now - buffer_start_time > 3600 then |
| 410 | // security to avoid queue blocking | 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 | failure | 412 | failure |
| 413 | else | 413 | else |
| 414 | with buffer_size = length(buffer), | 414 | with buffer_size = length(buffer), |
| @@ -427,38 +427,44 @@ define SendContentResult | @@ -427,38 +427,44 @@ define SendContentResult | ||
| 427 | SmtpClientSession session, | 427 | SmtpClientSession session, |
| 428 | Int start_time, | 428 | Int start_time, |
| 429 | Int so_far, | 429 | Int so_far, |
| 430 | - Int last_reply_check, | ||
| 431 | (Int) -> One progress_report, | 430 | (Int) -> One progress_report, |
| 432 | (LogLevel, String) -> One logger | 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 | if sm_flush( buffer, weaken(target), now, logger ) is | 442 | if sm_flush( buffer, weaken(target), now, logger ) is |
| 454 | { | 443 | { |
| 455 | failure then copy_error(so_far), | 444 | failure then copy_error(so_far), |
| 456 | success(_) then | 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 | define SendContentResult | 469 | define SendContentResult |
| 464 | sm_copy_Data_IO_List_to_Stream | 470 | sm_copy_Data_IO_List_to_Stream |
| @@ -476,7 +482,7 @@ define SendContentResult | @@ -476,7 +482,7 @@ define SendContentResult | ||
| 476 | [] then copy_ok(so_far), | 482 | [] then copy_ok(so_far), |
| 477 | [ h . t ] then | 483 | [ h . t ] then |
| 478 | if rewind(h)(unique) then | 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 | if result is copy_ok(written) then | 486 | if result is copy_ok(written) then |
| 481 | sm_copy_Data_IO_List_to_Stream(t, target, session, start_time, so_far + written, progress_report, logger) | 487 | sm_copy_Data_IO_List_to_Stream(t, target, session, start_time, so_far + written, progress_report, logger) |
| 482 | else | 488 | else |
web/CXM_making_a_web_site.anubis
| @@ -2267,7 +2267,7 @@ public define Web_Site | @@ -2267,7 +2267,7 @@ public define Web_Site | ||
| 2267 | // | 2267 | // |
| 2268 | // make required directories (if needed) | 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 | base_directory = (String) make_directory(site_directory), | 2271 | base_directory = (String) make_directory(site_directory), |
| 2272 | // state_directory = make_directory(site_directory+"/states"), | 2272 | // state_directory = make_directory(site_directory+"/states"), |
| 2273 | forget((String)make_directory(site_directory+"/public")); | 2273 | forget((String)make_directory(site_directory+"/public")); |