Commit dd039c8079292880fce88f46ef86f3c8a967fc7f
1 parent
d771e057
rename almost all db_xx in hk_xx
add HK_App_Name which use to designate the app in foreign_key
Showing
1 changed file
with
164 additions
and
91 deletions
Show diff stats
database/model/db_model.anubis
| @@ -20,14 +20,18 @@ | @@ -20,14 +20,18 @@ | ||
| 20 | 20 | ||
| 21 | *** (1) Formal description of the database. | 21 | *** (1) Formal description of the database. |
| 22 | 22 | ||
| 23 | - *** (1.1) 'DB_Model_Field' (data types of table columns). | 23 | + *** (1.1) 'HK_Model_Field' (data types of table columns). |
| 24 | +public type HK_App_Name: | ||
| 25 | + this, | ||
| 26 | + app_name(String name), | ||
| 27 | + none. | ||
| 24 | 28 | ||
| 25 | public type DB_Datetime_Field_Attr: | 29 | public type DB_Datetime_Field_Attr: |
| 26 | none, //Nothing special, normal behaviour | 30 | none, //Nothing special, normal behaviour |
| 27 | auto_now, //Always update datetime at SQL update | 31 | auto_now, //Always update datetime at SQL update |
| 28 | auto_now_add. //Set current datetime when row is created and can't be edited anymore | 32 | auto_now_add. //Set current datetime when row is created and can't be edited anymore |
| 29 | 33 | ||
| 30 | -public type DB_Model_Field: | 34 | +public type HK_Model_Field: |
| 31 | //anubis(String _T), // the datum of type _T is serialized and base64 encoded | 35 | //anubis(String _T), // the datum of type _T is serialized and base64 encoded |
| 32 | p_key, | 36 | p_key, |
| 33 | //binary, // contains a byte array | 37 | //binary, // contains a byte array |
| @@ -35,11 +39,18 @@ public type DB_Model_Field: | @@ -35,11 +39,18 @@ public type DB_Model_Field: | ||
| 35 | date_field(DB_Datetime_Field_Attr), // date with the precision of the day | 39 | date_field(DB_Datetime_Field_Attr), // date with the precision of the day |
| 36 | time_field(DB_Datetime_Field_Attr), // time with the precision of the second | 40 | time_field(DB_Datetime_Field_Attr), // time with the precision of the second |
| 37 | datetime_field(DB_Datetime_Field_Attr), // datetime with the precision of the second | 41 | datetime_field(DB_Datetime_Field_Attr), // datetime with the precision of the second |
| 38 | - foreign_key(String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector. | 42 | + foreign_key(HK_App_Name app_name, String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector. |
| 39 | integer_field, // integer of arbitrary size | 43 | integer_field, // integer of arbitrary size |
| 40 | char_field(Int size), // text of maximal size 'size' (number of characters) | 44 | char_field(Int size), // text of maximal size 'size' (number of characters) |
| 41 | text_field. // text of variable size | 45 | text_field. // text of variable size |
| 42 | 46 | ||
| 47 | +public define HK_Model_Field | ||
| 48 | + foreign_key | ||
| 49 | + ( | ||
| 50 | + String table_name | ||
| 51 | + )= | ||
| 52 | + foreign_key(this, table_name). | ||
| 53 | + | ||
| 43 | From the point of view of your Anubis program, these data will be of types: | 54 | From the point of view of your Anubis program, these data will be of types: |
| 44 | 55 | ||
| 45 | Name | Anubis type | Type within the database | 56 | Name | Anubis type | Type within the database |
| @@ -74,17 +85,19 @@ public type MaybeNull($T): | @@ -74,17 +85,19 @@ public type MaybeNull($T): | ||
| 74 | (number of seconds since the epoch) are provided in 'library/tools/ISO-8601.anubis'. | 85 | (number of seconds since the epoch) are provided in 'library/tools/ISO-8601.anubis'. |
| 75 | 86 | ||
| 76 | 87 | ||
| 77 | - *** (1.3) 'DB_Model_Attr' (attributes of columns). | 88 | + *** (1.3) 'HK_Model_Attr' (attributes of columns). |
| 78 | 89 | ||
| 79 | Possible attributes of columns: (each column has a list of such attributes) | 90 | Possible attributes of columns: (each column has a list of such attributes) |
| 80 | 91 | ||
| 81 | -public type DB_Model_Attr: | 92 | +public type HK_Model_Attr: |
| 82 | unique, // by default, the values in a column are not required to be all different | 93 | unique, // by default, the values in a column are not required to be all different |
| 83 | indexed, // by default, a column is not indexed | 94 | indexed, // by default, a column is not indexed |
| 84 | - default(String). // default value (used in case of creation of a NON NULL column | 95 | + default(String), // default value (used in case of creation of a NON NULL column |
| 85 | // in a table which already contains some rows) | 96 | // in a table which already contains some rows) |
| 97 | + not_null. | ||
| 98 | + | ||
| 86 | 99 | ||
| 87 | -public type DB_Help_Text: | 100 | +public type HK_Help_Text: |
| 88 | no_help_text, //no help text available | 101 | no_help_text, //no help text available |
| 89 | help_text_TAG(String), //TAG use with Anubis translation tool /locale/L3.anubis | 102 | help_text_TAG(String), //TAG use with Anubis translation tool /locale/L3.anubis |
| 90 | help_text(String). //pure text to show | 103 | help_text(String). //pure text to show |
| @@ -94,7 +107,7 @@ public define String | @@ -94,7 +107,7 @@ public define String | ||
| 94 | */ | 107 | */ |
| 95 | to_Anubis_source | 108 | to_Anubis_source |
| 96 | ( | 109 | ( |
| 97 | - DB_Help_Text help | 110 | + HK_Help_Text help |
| 98 | )= | 111 | )= |
| 99 | if help is | 112 | if help is |
| 100 | { | 113 | { |
| @@ -103,48 +116,48 @@ public define String | @@ -103,48 +116,48 @@ public define String | ||
| 103 | help_text(str) then "help_text(\""+str+"\")" | 116 | help_text(str) then "help_text(\""+str+"\")" |
| 104 | }. | 117 | }. |
| 105 | 118 | ||
| 106 | - Of course, 'NOT NULL' is not an alternative of 'DB_Model_Attr' because it is already coded into the | ||
| 107 | - database type itself (type 'DB_Model_Field' above). | 119 | + Of course, 'NOT NULL' is not an alternative of 'HK_Model_Attr' because it is already coded into the |
| 120 | + database type itself (type 'HK_Model_Field' above). | ||
| 108 | 121 | ||
| 109 | 122 | ||
| 110 | - *** (1.4) 'DB_Model_Column' (describing a column in a table). | 123 | + *** (1.4) 'HK_Model_Column' (describing a column in a table). |
| 111 | 124 | ||
| 112 | Description of a column: | 125 | Description of a column: |
| 113 | 126 | ||
| 114 | -public type DB_Model_Column: | ||
| 115 | - db_column (String name, // name of ordinary column (i.e. all but 'id') | ||
| 116 | - DB_Model_Field type, | ||
| 117 | - List(DB_Model_Attr) attributes, | ||
| 118 | - DB_Help_Text help | 127 | +public type HK_Model_Column: |
| 128 | + hk_column (String name, // name of ordinary column (i.e. all but 'id') | ||
| 129 | + HK_Model_Field type, | ||
| 130 | + List(HK_Model_Attr) attributes, | ||
| 131 | + HK_Help_Text help | ||
| 119 | ). | 132 | ). |
| 120 | 133 | ||
| 121 | -public define DB_Model_Column | 134 | +public define HK_Model_Column |
| 122 | /* Constructor helper for db_column without help attribute. | 135 | /* Constructor helper for db_column without help attribute. |
| 123 | the real type constructor will be called with the attribute no_help_text | 136 | the real type constructor will be called with the attribute no_help_text |
| 124 | */ | 137 | */ |
| 125 | - db_column | 138 | + hk_column |
| 126 | ( | 139 | ( |
| 127 | String name, | 140 | String name, |
| 128 | - DB_Model_Field type, | ||
| 129 | - List(DB_Model_Attr) attributes, | 141 | + HK_Model_Field type, |
| 142 | + List(HK_Model_Attr) attributes, | ||
| 130 | )= | 143 | )= |
| 131 | - db_column(name, type, attributes, no_help_text). | 144 | + hk_column(name, type, attributes, no_help_text). |
| 132 | 145 | ||
| 133 | -public define DB_Model_Column | ||
| 134 | - db_column | 146 | +public define HK_Model_Column |
| 147 | + hk_column | ||
| 135 | ( | 148 | ( |
| 136 | String name, | 149 | String name, |
| 137 | - DB_Model_Field type | 150 | + HK_Model_Field type |
| 138 | )= | 151 | )= |
| 139 | - db_column(name, type, [], no_help_text). | 152 | + hk_column(name, type, [], no_help_text). |
| 140 | 153 | ||
| 141 | 154 | ||
| 142 | *** (3.7) 'DB_Model_Table' (describing a table). | 155 | *** (3.7) 'DB_Model_Table' (describing a table). |
| 143 | 156 | ||
| 144 | Description of a table: | 157 | Description of a table: |
| 145 | 158 | ||
| 146 | -public type DB_Model: | ||
| 147 | - db_model( List(DB_Model_Column) columns, // columns other than the primary key column (if any) | 159 | +public type HK_Model: |
| 160 | + hk_model( List(HK_Model_Column) columns, // columns other than the primary key column (if any) | ||
| 148 | String show_string). | 161 | String show_string). |
| 149 | 162 | ||
| 150 | public type HK_List_View: | 163 | public type HK_List_View: |
| @@ -155,23 +168,29 @@ public type HK_Edit_View: | @@ -155,23 +168,29 @@ public type HK_Edit_View: | ||
| 155 | edit_view_all, | 168 | edit_view_all, |
| 156 | edit_view(String view_name, List(String) columns). | 169 | edit_view(String view_name, List(String) columns). |
| 157 | 170 | ||
| 158 | -public type DB_Display: | 171 | +public type HK_Display: |
| 159 | db_display(List(HK_List_View) list_views, | 172 | db_display(List(HK_List_View) list_views, |
| 160 | //List(HK_Edit_View) edit_views | 173 | //List(HK_Edit_View) edit_views |
| 161 | List(String)). | 174 | List(String)). |
| 162 | 175 | ||
| 163 | -public type DB_Table: | ||
| 164 | - db_table ( String name, // name of the table | ||
| 165 | - DB_Model model, | ||
| 166 | - DB_Display display). | 176 | +public type HK_Table: |
| 177 | + hk_table ( String name, // name of the table | ||
| 178 | + HK_Model model, | ||
| 179 | + HK_Display display). | ||
| 167 | 180 | ||
| 168 | *** (3.8) 'DB_Database' (describing a whole database). | 181 | *** (3.8) 'DB_Database' (describing a whole database). |
| 169 | 182 | ||
| 170 | Description of a whole database: | 183 | Description of a whole database: |
| 171 | 184 | ||
| 172 | -public type DB_Database: | ||
| 173 | - db_database (String name, // name of the database | ||
| 174 | - List(DB_Table) tables). | 185 | +public type HK_App: |
| 186 | + hk_app( String app_name, | ||
| 187 | + List(HK_Table) hk_tables | ||
| 188 | + ). | ||
| 189 | + | ||
| 190 | +public type HK_Database: | ||
| 191 | + hk_database (String name, // name of the database | ||
| 192 | + List(HK_App) apps //list of applications | ||
| 193 | + ). | ||
| 175 | // list of all tables in the database | 194 | // list of all tables in the database |
| 176 | 195 | ||
| 177 | 196 | ||
| @@ -249,7 +268,27 @@ define macro Maybe(String) | @@ -249,7 +268,27 @@ define macro Maybe(String) | ||
| 249 | } | 268 | } |
| 250 | }. | 269 | }. |
| 251 | 270 | ||
| 252 | - | 271 | +define Int |
| 272 | + _max | ||
| 273 | + ( | ||
| 274 | + List(HK_Model_Column) columns, | ||
| 275 | + Int current_max | ||
| 276 | + )= | ||
| 277 | + if columns is | ||
| 278 | + { | ||
| 279 | + [] then current_max, | ||
| 280 | + [h . t] then | ||
| 281 | + since h is hk_column(name, _, _, _), | ||
| 282 | + _max(t, max(current_max, length(name))) | ||
| 283 | + } | ||
| 284 | + . | ||
| 285 | + | ||
| 286 | +public define Int | ||
| 287 | + max | ||
| 288 | + ( | ||
| 289 | + List(HK_Model_Column) columns | ||
| 290 | + )= | ||
| 291 | + _max(columns, 0). | ||
| 253 | 292 | ||
| 254 | *** [2] Verifications concerning the description of the database and queries. | 293 | *** [2] Verifications concerning the description of the database and queries. |
| 255 | 294 | ||
| @@ -260,8 +299,8 @@ define macro Maybe(String) | @@ -260,8 +299,8 @@ define macro Maybe(String) | ||
| 260 | ( | 299 | ( |
| 261 | String table_name, // the first 3 arguments concern the current table. | 300 | String table_name, // the first 3 arguments concern the current table. |
| 262 | MetaSQL_PrimKey pk, | 301 | MetaSQL_PrimKey pk, |
| 263 | - List(DB_Model_Column) columns, | ||
| 264 | - List(DB_Model_Column) forwards, // subsequent tables | 302 | + List(HK_Model_Column) columns, |
| 303 | + List(HK_Model_Column) forwards, // subsequent tables | ||
| 265 | List(String) backwards // list of backwards table names | 304 | List(String) backwards // list of backwards table names |
| 266 | ) = | 305 | ) = |
| 267 | if columns is | 306 | if columns is |
| @@ -277,7 +316,7 @@ define macro Maybe(String) | @@ -277,7 +316,7 @@ define macro Maybe(String) | ||
| 277 | has_forbidden_cycles | 316 | has_forbidden_cycles |
| 278 | ( | 317 | ( |
| 279 | String db_name, | 318 | String db_name, |
| 280 | - List(DB_Model_Column) tables, | 319 | + List(HK_Model_Column) tables, |
| 281 | List(String) backwards // names of 'backwards' tables | 320 | List(String) backwards // names of 'backwards' tables |
| 282 | ) = | 321 | ) = |
| 283 | if tables is | 322 | if tables is |
| @@ -299,10 +338,10 @@ define macro Maybe(String) | @@ -299,10 +338,10 @@ define macro Maybe(String) | ||
| 299 | define Bool | 338 | define Bool |
| 300 | has_forbidden_column_names | 339 | has_forbidden_column_names |
| 301 | ( | 340 | ( |
| 302 | - DB_Model_Column tab | 341 | + HK_Model_Column tab |
| 303 | ) = | 342 | ) = |
| 304 | if tab is table(_,_,cols) then | 343 | if tab is table(_,_,cols) then |
| 305 | - mapor((DB_Model_Column cs) |-> | 344 | + mapor((HK_Model_Column cs) |-> |
| 306 | if cs is col(name,_,_) then is_forbidden_column_name(name), | 345 | if cs is col(name,_,_) then is_forbidden_column_name(name), |
| 307 | cols). | 346 | cols). |
| 308 | 347 | ||
| @@ -323,7 +362,7 @@ define macro Maybe(String) | @@ -323,7 +362,7 @@ define macro Maybe(String) | ||
| 323 | public define String | 362 | public define String |
| 324 | to_Anubis_type | 363 | to_Anubis_type |
| 325 | ( | 364 | ( |
| 326 | - DB_Model_Field t | 365 | + HK_Model_Field t |
| 327 | ) = | 366 | ) = |
| 328 | if t is | 367 | if t is |
| 329 | { | 368 | { |
| @@ -334,17 +373,51 @@ public define String | @@ -334,17 +373,51 @@ public define String | ||
| 334 | date_field(_) then "DB_date", | 373 | date_field(_) then "DB_date", |
| 335 | time_field(_) then "DB_time", | 374 | time_field(_) then "DB_time", |
| 336 | datetime_field(_) then "DB_datetime", | 375 | datetime_field(_) then "DB_datetime", |
| 337 | - foreign_key(_) then "Int", | 376 | + foreign_key(_,_) then "Int", |
| 338 | integer_field then "Int", | 377 | integer_field then "Int", |
| 339 | char_field(Int size) then "String", | 378 | char_field(Int size) then "String", |
| 340 | text_field then "String" | 379 | text_field then "String" |
| 341 | }. | 380 | }. |
| 342 | 381 | ||
| 343 | - | 382 | +define String |
| 383 | + format_attributes | ||
| 384 | + ( | ||
| 385 | + List(HK_Model_Attr) attributes | ||
| 386 | + )= | ||
| 387 | + join(" ",map((HK_Model_Attr attr) |-> | ||
| 388 | + if attr is | ||
| 389 | + { | ||
| 390 | + unique then "UNIQUE", | ||
| 391 | + indexed then "INDEXED", // by default, a column is not indexed | ||
| 392 | + default(str) then "DEFAULT "+str, // default value (used in case of creation of a NON NULL column | ||
| 393 | + // in a table which already contains some rows) | ||
| 394 | + not_null then "NOT NULL" | ||
| 395 | + }, attributes)). | ||
| 396 | + | ||
| 397 | +public define String | ||
| 398 | + to_SQL_CREATE | ||
| 399 | + ( | ||
| 400 | + HK_Model_Field t, | ||
| 401 | + List(HK_Model_Attr) attributes, | ||
| 402 | + ) = | ||
| 403 | + if t is | ||
| 404 | + { | ||
| 405 | + //anubis(_T) then "ByteArray", | ||
| 406 | + p_key then fill("INTEGER", 15) +" PRIMARY KEY", | ||
| 407 | + boolean_field then fill("BOOL", 15) +format_attributes(attributes), | ||
| 408 | + date_field(_) then fill("DATE", 15) +format_attributes(attributes), | ||
| 409 | + time_field(_) then fill("TIME", 15) +format_attributes(attributes), | ||
| 410 | + datetime_field(_) then fill("DATETIME", 15)+format_attributes(attributes), | ||
| 411 | + foreign_key(app,fk) then fill("INTEGER", 15) +" NOT NULL REFERENCES "+fk+" (id)", | ||
| 412 | + integer_field then fill("INTEGER", 15) +format_attributes(attributes), | ||
| 413 | + char_field(Int size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes), | ||
| 414 | + text_field then fill("TEXT", 15) +format_attributes(attributes), | ||
| 415 | + }. | ||
| 416 | + | ||
| 344 | public define String | 417 | public define String |
| 345 | to_Anubis_default | 418 | to_Anubis_default |
| 346 | ( | 419 | ( |
| 347 | - DB_Model_Field t | 420 | + HK_Model_Field t |
| 348 | ) = | 421 | ) = |
| 349 | if t is | 422 | if t is |
| 350 | { | 423 | { |
| @@ -355,7 +428,7 @@ public define String | @@ -355,7 +428,7 @@ public define String | ||
| 355 | date_field(_) then "db_date(\"\")", | 428 | date_field(_) then "db_date(\"\")", |
| 356 | time_field(_) then "db_time(\"\")", | 429 | time_field(_) then "db_time(\"\")", |
| 357 | datetime_field(_) then "db_datetime(\"\")", | 430 | datetime_field(_) then "db_datetime(\"\")", |
| 358 | - foreign_key(_) then "(Int)0", | 431 | + foreign_key(_,_) then "(Int)0", |
| 359 | integer_field then "(Int)0", | 432 | integer_field then "(Int)0", |
| 360 | char_field(Int size) then "\"\"", | 433 | char_field(Int size) then "\"\"", |
| 361 | text_field then "\"\"" | 434 | text_field then "\"\"" |
| @@ -364,7 +437,7 @@ public define String | @@ -364,7 +437,7 @@ public define String | ||
| 364 | public define String | 437 | public define String |
| 365 | from_DB_cursor | 438 | from_DB_cursor |
| 366 | ( | 439 | ( |
| 367 | - DB_Model_Field t, | 440 | + HK_Model_Field t, |
| 368 | String cursor, | 441 | String cursor, |
| 369 | Int index | 442 | Int index |
| 370 | ) = | 443 | ) = |
| @@ -378,7 +451,7 @@ public define String | @@ -378,7 +451,7 @@ public define String | ||
| 378 | date_field(_) then "db_date(text"+cursor_index+")", | 451 | date_field(_) then "db_date(text"+cursor_index+")", |
| 379 | time_field(_) then "db_time(text"+cursor_index+")", | 452 | time_field(_) then "db_time(text"+cursor_index+")", |
| 380 | datetime_field(_) then "db_datetime(text"+cursor_index+")", | 453 | datetime_field(_) then "db_datetime(text"+cursor_index+")", |
| 381 | - foreign_key(_) then "(Int)db_integer"+cursor_index, | 454 | + foreign_key(_,_) then "(Int)db_integer"+cursor_index, |
| 382 | integer_field then "(Int)db_integer"+cursor_index, | 455 | integer_field then "(Int)db_integer"+cursor_index, |
| 383 | char_field(Int size) then "text"+cursor_index, | 456 | char_field(Int size) then "text"+cursor_index, |
| 384 | text_field then "text"+cursor_index | 457 | text_field then "text"+cursor_index |
| @@ -389,7 +462,7 @@ define List(String) | @@ -389,7 +462,7 @@ define List(String) | ||
| 389 | */ | 462 | */ |
| 390 | components | 463 | components |
| 391 | ( | 464 | ( |
| 392 | - List(DB_Model_Column) columns, | 465 | + List(HK_Model_Column) columns, |
| 393 | String cursor_name, | 466 | String cursor_name, |
| 394 | List(String) so_far, | 467 | List(String) so_far, |
| 395 | Int idx | 468 | Int idx |
| @@ -398,7 +471,7 @@ define List(String) | @@ -398,7 +471,7 @@ define List(String) | ||
| 398 | { | 471 | { |
| 399 | [] then reverse(so_far), | 472 | [] then reverse(so_far), |
| 400 | [h . t ] then | 473 | [h . t ] then |
| 401 | - since h is db_column(name, col_type, _, _), | 474 | + since h is hk_column(name, col_type, _, _), |
| 402 | with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */", | 475 | with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */", |
| 403 | components(t, cursor_name, [line . so_far], idx + 1 ) | 476 | components(t, cursor_name, [line . so_far], idx + 1 ) |
| 404 | }. | 477 | }. |
| @@ -408,7 +481,7 @@ public define String | @@ -408,7 +481,7 @@ public define String | ||
| 408 | ( | 481 | ( |
| 409 | String constructor_name, | 482 | String constructor_name, |
| 410 | String cursor_name, | 483 | String cursor_name, |
| 411 | - List(DB_Model_Column) columns, | 484 | + List(HK_Model_Column) columns, |
| 412 | String indent | 485 | String indent |
| 413 | )= | 486 | )= |
| 414 | indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")". | 487 | indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")". |
| @@ -417,7 +490,7 @@ public define String | @@ -417,7 +490,7 @@ public define String | ||
| 417 | public define String | 490 | public define String |
| 418 | from_web_arg | 491 | from_web_arg |
| 419 | ( | 492 | ( |
| 420 | - DB_Model_Field t, | 493 | + HK_Model_Field t, |
| 421 | String name | 494 | String name |
| 422 | ) = | 495 | ) = |
| 423 | if t is | 496 | if t is |
| @@ -429,7 +502,7 @@ public define String | @@ -429,7 +502,7 @@ public define String | ||
| 429 | date_field(attrs) then if attrs = none then "get_DB_date(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_date,", | 502 | date_field(attrs) then if attrs = none then "get_DB_date(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_date,", |
| 430 | time_field(attrs) then if attrs = none then "get_DB_time(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_time,", | 503 | time_field(attrs) then if attrs = none then "get_DB_time(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_time,", |
| 431 | datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", | 504 | datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", |
| 432 | - foreign_key(String table) then "get_Int(lwa, \""+name+"\")", | 505 | + foreign_key(_,_) then "get_Int(lwa, \""+name+"\")", |
| 433 | integer_field then "get_Int(lwa, \""+name+"\")", | 506 | integer_field then "get_Int(lwa, \""+name+"\")", |
| 434 | char_field(Int size) then "get_String(lwa, \""+name+"\")", | 507 | char_field(Int size) then "get_String(lwa, \""+name+"\")", |
| 435 | text_field then "get_String(lwa, \""+name+"\")" | 508 | text_field then "get_String(lwa, \""+name+"\")" |
| @@ -440,7 +513,7 @@ define List(String) | @@ -440,7 +513,7 @@ define List(String) | ||
| 440 | */ | 513 | */ |
| 441 | _to_List_String | 514 | _to_List_String |
| 442 | ( | 515 | ( |
| 443 | - List(DB_Model_Column) columns, | 516 | + List(HK_Model_Column) columns, |
| 444 | Bool with_pk, | 517 | Bool with_pk, |
| 445 | List(String) so_far | 518 | List(String) so_far |
| 446 | )= | 519 | )= |
| @@ -448,7 +521,7 @@ define List(String) | @@ -448,7 +521,7 @@ define List(String) | ||
| 448 | { | 521 | { |
| 449 | [] then reverse(so_far), | 522 | [] then reverse(so_far), |
| 450 | [h . t ] then | 523 | [h . t ] then |
| 451 | - since h is db_column(name, _, _, _), | 524 | + since h is hk_column(name, _, _, _), |
| 452 | if name = "id" & with_pk = false then | 525 | if name = "id" & with_pk = false then |
| 453 | _to_List_String(t, with_pk, so_far) | 526 | _to_List_String(t, with_pk, so_far) |
| 454 | else | 527 | else |
| @@ -460,7 +533,7 @@ public define List(String) | @@ -460,7 +533,7 @@ public define List(String) | ||
| 460 | */ | 533 | */ |
| 461 | to_List_String | 534 | to_List_String |
| 462 | ( | 535 | ( |
| 463 | - List(DB_Model_Column) columns, | 536 | + List(HK_Model_Column) columns, |
| 464 | Bool with_pk | 537 | Bool with_pk |
| 465 | )= | 538 | )= |
| 466 | _to_List_String(columns, with_pk, []). | 539 | _to_List_String(columns, with_pk, []). |
| @@ -470,7 +543,7 @@ public define String | @@ -470,7 +543,7 @@ public define String | ||
| 470 | generate_constructor | 543 | generate_constructor |
| 471 | ( | 544 | ( |
| 472 | String constructor_name, | 545 | String constructor_name, |
| 473 | - List(DB_Model_Column) columns, | 546 | + List(HK_Model_Column) columns, |
| 474 | String indent | 547 | String indent |
| 475 | )= | 548 | )= |
| 476 | indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")". | 549 | indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")". |
| @@ -478,7 +551,7 @@ public define String | @@ -478,7 +551,7 @@ public define String | ||
| 478 | public define String | 551 | public define String |
| 479 | to_Bind | 552 | to_Bind |
| 480 | ( | 553 | ( |
| 481 | - DB_Model_Field t, | 554 | + HK_Model_Field t, |
| 482 | String type_name, //name of the type | 555 | String type_name, //name of the type |
| 483 | String name, //name of component into the type | 556 | String name, //name of component into the type |
| 484 | Bool insert //true if insert time else false for update | 557 | Bool insert //true if insert time else false for update |
| @@ -501,7 +574,7 @@ public define String | @@ -501,7 +574,7 @@ public define String | ||
| 501 | else | 574 | else |
| 502 | "" | 575 | "" |
| 503 | }, | 576 | }, |
| 504 | - foreign_key(_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", | 577 | + foreign_key(_,_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", |
| 505 | integer_field then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", | 578 | integer_field then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", |
| 506 | char_field(Int size) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")", | 579 | char_field(Int size) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")", |
| 507 | text_field then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")" | 580 | text_field then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")" |
| @@ -512,7 +585,7 @@ public define List(String) | @@ -512,7 +585,7 @@ public define List(String) | ||
| 512 | */ | 585 | */ |
| 513 | to_Bind_list | 586 | to_Bind_list |
| 514 | ( | 587 | ( |
| 515 | - List(DB_Model_Column) columns, | 588 | + List(HK_Model_Column) columns, |
| 516 | String type_name, //name of the type | 589 | String type_name, //name of the type |
| 517 | List(String) so_far, | 590 | List(String) so_far, |
| 518 | Bool insert | 591 | Bool insert |
| @@ -521,7 +594,7 @@ public define List(String) | @@ -521,7 +594,7 @@ public define List(String) | ||
| 521 | { | 594 | { |
| 522 | [] then reverse(so_far), | 595 | [] then reverse(so_far), |
| 523 | [h . t ] then | 596 | [h . t ] then |
| 524 | - since h is db_column(name, col_type, _, _), | 597 | + since h is hk_column(name, col_type, _, _), |
| 525 | with result = to_Bind(col_type, type_name, name, insert), | 598 | with result = to_Bind(col_type, type_name, name, insert), |
| 526 | //we eliminate the empty string because during the join it will have an empty line | 599 | //we eliminate the empty string because during the join it will have an empty line |
| 527 | if result = "" then | 600 | if result = "" then |
| @@ -533,7 +606,7 @@ public define List(String) | @@ -533,7 +606,7 @@ public define List(String) | ||
| 533 | public define String | 606 | public define String |
| 534 | generate_Bind_list | 607 | generate_Bind_list |
| 535 | ( | 608 | ( |
| 536 | - List(DB_Model_Column) columns, | 609 | + List(HK_Model_Column) columns, |
| 537 | String type_name, | 610 | String type_name, |
| 538 | String indent, | 611 | String indent, |
| 539 | Bool insert | 612 | Bool insert |
| @@ -544,10 +617,10 @@ public define String | @@ -544,10 +617,10 @@ public define String | ||
| 544 | public define Maybe(String) | 617 | public define Maybe(String) |
| 545 | get_column_name | 618 | get_column_name |
| 546 | ( | 619 | ( |
| 547 | - DB_Model_Column col, | 620 | + HK_Model_Column col, |
| 548 | Bool insert //true if insert time else false for update | 621 | Bool insert //true if insert time else false for update |
| 549 | ) = | 622 | ) = |
| 550 | - since col is db_column(name, col_type, _, _), | 623 | + since col is hk_column(name, col_type, _, _), |
| 551 | if col_type is | 624 | if col_type is |
| 552 | { | 625 | { |
| 553 | //anubis(_T) then "constant_byte_array(0,0)", | 626 | //anubis(_T) then "constant_byte_array(0,0)", |
| @@ -563,7 +636,7 @@ public define Maybe(String) | @@ -563,7 +636,7 @@ public define Maybe(String) | ||
| 563 | auto_now_add then | 636 | auto_now_add then |
| 564 | if insert then success(name) else failure | 637 | if insert then success(name) else failure |
| 565 | }, | 638 | }, |
| 566 | - foreign_key(_) then success(name), | 639 | + foreign_key(_,_) then success(name), |
| 567 | integer_field then success(name), | 640 | integer_field then success(name), |
| 568 | char_field(Int size) then success(name), | 641 | char_field(Int size) then success(name), |
| 569 | text_field then success(name) | 642 | text_field then success(name) |
| @@ -572,7 +645,7 @@ public define Maybe(String) | @@ -572,7 +645,7 @@ public define Maybe(String) | ||
| 572 | public define List(String) | 645 | public define List(String) |
| 573 | columns_name | 646 | columns_name |
| 574 | ( | 647 | ( |
| 575 | - List(DB_Model_Column) columns, | 648 | + List(HK_Model_Column) columns, |
| 576 | Bool insert, //true if insert time else false for update | 649 | Bool insert, //true if insert time else false for update |
| 577 | List(String) so_far | 650 | List(String) so_far |
| 578 | ) = | 651 | ) = |
| @@ -598,7 +671,7 @@ public define String | @@ -598,7 +671,7 @@ public define String | ||
| 598 | */ | 671 | */ |
| 599 | insert_values | 672 | insert_values |
| 600 | ( | 673 | ( |
| 601 | - List(DB_Model_Column) columns, | 674 | + List(HK_Model_Column) columns, |
| 602 | String indent | 675 | String indent |
| 603 | )= | 676 | )= |
| 604 | with columns_list = columns_name(columns, true, []), | 677 | with columns_list = columns_name(columns, true, []), |
| @@ -612,7 +685,7 @@ public define String | @@ -612,7 +685,7 @@ public define String | ||
| 612 | */ | 685 | */ |
| 613 | update_values | 686 | update_values |
| 614 | ( | 687 | ( |
| 615 | - List(DB_Model_Column) columns, | 688 | + List(HK_Model_Column) columns, |
| 616 | String indent | 689 | String indent |
| 617 | )= | 690 | )= |
| 618 | with columns_list = columns_name(columns, false, []), | 691 | with columns_list = columns_name(columns, false, []), |
| @@ -622,10 +695,10 @@ public define String | @@ -622,10 +695,10 @@ public define String | ||
| 622 | public define Maybe(String) | 695 | public define Maybe(String) |
| 623 | get_VT_edit_entry | 696 | get_VT_edit_entry |
| 624 | ( | 697 | ( |
| 625 | - DB_Model_Column col, | 698 | + HK_Model_Column col, |
| 626 | String type_name | 699 | String type_name |
| 627 | ) = | 700 | ) = |
| 628 | - since col is db_column(name, col_type, _, help), | 701 | + since col is hk_column(name, col_type, _, help), |
| 629 | if col_type is | 702 | if col_type is |
| 630 | { | 703 | { |
| 631 | //anubis(_T) then "constant_byte_array(0,0)", | 704 | //anubis(_T) then "constant_byte_array(0,0)", |
| @@ -650,7 +723,7 @@ public define Maybe(String) | @@ -650,7 +723,7 @@ public define Maybe(String) | ||
| 650 | auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), | 723 | auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), |
| 651 | auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")") | 724 | auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")") |
| 652 | }, | 725 | }, |
| 653 | - foreign_key(foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"), | 726 | + foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"), |
| 654 | integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), | 727 | integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), |
| 655 | char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), | 728 | char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), |
| 656 | text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")") | 729 | text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")") |
| @@ -659,7 +732,7 @@ public define Maybe(String) | @@ -659,7 +732,7 @@ public define Maybe(String) | ||
| 659 | public define String | 732 | public define String |
| 660 | edit_entries | 733 | edit_entries |
| 661 | ( | 734 | ( |
| 662 | - List(DB_Model_Column) columns, | 735 | + List(HK_Model_Column) columns, |
| 663 | String type_name, | 736 | String type_name, |
| 664 | String indent, | 737 | String indent, |
| 665 | List(String) so_far | 738 | List(String) so_far |
| @@ -683,17 +756,17 @@ public define String | @@ -683,17 +756,17 @@ public define String | ||
| 683 | )= | 756 | )= |
| 684 | indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)). | 757 | indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)). |
| 685 | 758 | ||
| 686 | -public define Maybe(DB_Model_Column) | 759 | +public define Maybe(HK_Model_Column) |
| 687 | get_column_type | 760 | get_column_type |
| 688 | ( | 761 | ( |
| 689 | - List(DB_Model_Column) columns, //columns in wich we search | 762 | + List(HK_Model_Column) columns, //columns in wich we search |
| 690 | String name_to_find //Column name to find in previous list | 763 | String name_to_find //Column name to find in previous list |
| 691 | )= | 764 | )= |
| 692 | if columns is | 765 | if columns is |
| 693 | { | 766 | { |
| 694 | [] then failure, | 767 | [] then failure, |
| 695 | [h . t] then | 768 | [h . t] then |
| 696 | - since h is db_column(name, _, _, _), | 769 | + since h is hk_column(name, _, _, _), |
| 697 | if name_to_find = name then | 770 | if name_to_find = name then |
| 698 | success(h) | 771 | success(h) |
| 699 | else | 772 | else |
| @@ -705,11 +778,11 @@ public define String | @@ -705,11 +778,11 @@ public define String | ||
| 705 | */ | 778 | */ |
| 706 | to_String | 779 | to_String |
| 707 | ( | 780 | ( |
| 708 | - DB_Model_Column col, | 781 | + HK_Model_Column col, |
| 709 | String current_type_name, | 782 | String current_type_name, |
| 710 | String general_type_name | 783 | String general_type_name |
| 711 | ) = | 784 | ) = |
| 712 | - since col is db_column(name, col_type, _, _), | 785 | + since col is hk_column(name, col_type, _, _), |
| 713 | if col_type is | 786 | if col_type is |
| 714 | { | 787 | { |
| 715 | //anubis(_T) then "constant_byte_array(0,0)", | 788 | //anubis(_T) then "constant_byte_array(0,0)", |
| @@ -719,7 +792,7 @@ public define String | @@ -719,7 +792,7 @@ public define String | ||
| 719 | date_field(attrs) then "to_String("+current_type_name+"."+name+")", | 792 | date_field(attrs) then "to_String("+current_type_name+"."+name+")", |
| 720 | time_field(attrs) then "to_String("+current_type_name+"."+name+")", | 793 | time_field(attrs) then "to_String("+current_type_name+"."+name+")", |
| 721 | datetime_field(attrs) then "to_String("+current_type_name+"."+name+")" | 794 | datetime_field(attrs) then "to_String("+current_type_name+"."+name+")" |
| 722 | - foreign_key(foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")", | 795 | + foreign_key(app,foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")", |
| 723 | integer_field then "to_String("+current_type_name+"."+name+")", | 796 | integer_field then "to_String("+current_type_name+"."+name+")", |
| 724 | char_field(Int size) then current_type_name+"."+name, | 797 | char_field(Int size) then current_type_name+"."+name, |
| 725 | text_field then current_type_name+"."+name | 798 | text_field then current_type_name+"."+name |
| @@ -730,11 +803,11 @@ public define String | @@ -730,11 +803,11 @@ public define String | ||
| 730 | */ | 803 | */ |
| 731 | to_Icon | 804 | to_Icon |
| 732 | ( | 805 | ( |
| 733 | - DB_Model_Column col, | 806 | + HK_Model_Column col, |
| 734 | String current_type_name, | 807 | String current_type_name, |
| 735 | String general_type_name | 808 | String general_type_name |
| 736 | ) = | 809 | ) = |
| 737 | - since col is db_column(name, col_type, _, _), | 810 | + since col is hk_column(name, col_type, _, _), |
| 738 | if col_type is | 811 | if col_type is |
| 739 | { | 812 | { |
| 740 | p_key then icn16_key, | 813 | p_key then icn16_key, |
| @@ -742,7 +815,7 @@ public define String | @@ -742,7 +815,7 @@ public define String | ||
| 742 | date_field(attrs) then icn16_clock, | 815 | date_field(attrs) then icn16_clock, |
| 743 | time_field(attrs) then icn16_clock, | 816 | time_field(attrs) then icn16_clock, |
| 744 | datetime_field(attrs) then icn16_clock, | 817 | datetime_field(attrs) then icn16_clock, |
| 745 | - foreign_key(foreign_table) then icn16_question, | 818 | + foreign_key(app,foreign_table) then icn16_question, |
| 746 | integer_field then icn16_question, | 819 | integer_field then icn16_question, |
| 747 | char_field(Int size) then icn16_question, | 820 | char_field(Int size) then icn16_question, |
| 748 | text_field then icn16_question | 821 | text_field then icn16_question |
| @@ -751,7 +824,7 @@ public define String | @@ -751,7 +824,7 @@ public define String | ||
| 751 | public define String | 824 | public define String |
| 752 | to_HTML_cell_text | 825 | to_HTML_cell_text |
| 753 | ( | 826 | ( |
| 754 | - DB_Model_Column column, | 827 | + HK_Model_Column column, |
| 755 | String data_name, | 828 | String data_name, |
| 756 | String general_type_name | 829 | String general_type_name |
| 757 | )= | 830 | )= |
| @@ -760,7 +833,7 @@ public define String | @@ -760,7 +833,7 @@ public define String | ||
| 760 | public define String | 833 | public define String |
| 761 | to_HTML_cell_link | 834 | to_HTML_cell_link |
| 762 | ( | 835 | ( |
| 763 | - DB_Model_Column column, | 836 | + HK_Model_Column column, |
| 764 | String data_name, | 837 | String data_name, |
| 765 | String general_type_name | 838 | String general_type_name |
| 766 | )= | 839 | )= |
| @@ -769,7 +842,7 @@ public define String | @@ -769,7 +842,7 @@ public define String | ||
| 769 | public define String | 842 | public define String |
| 770 | to_HTML_cell_link | 843 | to_HTML_cell_link |
| 771 | ( | 844 | ( |
| 772 | - List(DB_Model_Column) columns, | 845 | + List(HK_Model_Column) columns, |
| 773 | String column_name, | 846 | String column_name, |
| 774 | String data_name, | 847 | String data_name, |
| 775 | String general_type_name | 848 | String general_type_name |
| @@ -783,7 +856,7 @@ public define String | @@ -783,7 +856,7 @@ public define String | ||
| 783 | public define String | 856 | public define String |
| 784 | to_HTML_cell_icon | 857 | to_HTML_cell_icon |
| 785 | ( | 858 | ( |
| 786 | - DB_Model_Column column, | 859 | + HK_Model_Column column, |
| 787 | String data_name, | 860 | String data_name, |
| 788 | String general_type_name | 861 | String general_type_name |
| 789 | )= | 862 | )= |
| @@ -793,7 +866,7 @@ public define String | @@ -793,7 +866,7 @@ public define String | ||
| 793 | public define String | 866 | public define String |
| 794 | to_HTML_cell | 867 | to_HTML_cell |
| 795 | ( | 868 | ( |
| 796 | - List(DB_Model_Column) columns, | 869 | + List(HK_Model_Column) columns, |
| 797 | String column_name, | 870 | String column_name, |
| 798 | String data_name, | 871 | String data_name, |
| 799 | String general_type_name | 872 | String general_type_name |
| @@ -802,7 +875,7 @@ public define String | @@ -802,7 +875,7 @@ public define String | ||
| 802 | { | 875 | { |
| 803 | failure then "column name "+column_name+"doesn't exist", | 876 | failure then "column name "+column_name+"doesn't exist", |
| 804 | success(column) then | 877 | success(column) then |
| 805 | - since column is db_column(name, col_type, _, _), | 878 | + since column is hk_column(name, col_type, _, _), |
| 806 | if col_type is | 879 | if col_type is |
| 807 | { | 880 | { |
| 808 | //anubis(_T) then "constant_byte_array(0,0)", | 881 | //anubis(_T) then "constant_byte_array(0,0)", |
| @@ -812,7 +885,7 @@ public define String | @@ -812,7 +885,7 @@ public define String | ||
| 812 | date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), | 885 | date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), |
| 813 | time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), | 886 | time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), |
| 814 | datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), | 887 | datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), |
| 815 | - foreign_key(foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), | 888 | + foreign_key(app,foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), |
| 816 | integer_field then to_HTML_cell_text(column, data_name, general_type_name), | 889 | integer_field then to_HTML_cell_text(column, data_name, general_type_name), |
| 817 | char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name), | 890 | char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name), |
| 818 | text_field then to_HTML_cell_text(column, data_name, general_type_name), | 891 | text_field then to_HTML_cell_text(column, data_name, general_type_name), |
| @@ -822,13 +895,13 @@ public define String | @@ -822,13 +895,13 @@ public define String | ||
| 822 | public define String | 895 | public define String |
| 823 | make_list_view_row | 896 | make_list_view_row |
| 824 | ( | 897 | ( |
| 825 | - DB_Table table, //table to format | 898 | + HK_Table table, //table to format |
| 826 | String data_name, //name of data | 899 | String data_name, //name of data |
| 827 | String indent, //indentation string to use | 900 | String indent, //indentation string to use |
| 828 | HK_List_View list_view //list view to generate | 901 | HK_List_View list_view //list view to generate |
| 829 | )= | 902 | )= |
| 830 | - since table is db_table(table_name, model, _), //get name and model of the table | ||
| 831 | - since model is db_model( columns, _), //get all columns of table | 903 | + since table is hk_table(table_name, model, _), //get name and model of the table |
| 904 | + since model is hk_model( columns, _), //get all columns of table | ||
| 832 | // since display is db_display(views, _), // | 905 | // since display is db_display(views, _), // |
| 833 | with current_list_column = if list_view is | 906 | with current_list_column = if list_view is |
| 834 | { | 907 | { |