Commit 8c34737c42be8b8fa7ef561305832aada199c0a0
1 parent
49ee3e60
Added db helper functions
Showing
1 changed file
with
32 additions
and
0 deletions
Show diff stats
calexium_lib/database/db_utils.anubis
| @@ -91,3 +91,35 @@ public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) | @@ -91,3 +91,35 @@ public define Maybe(SQLite3HeadersOrRow -> SQLite3Row) | ||
| 91 | error(sql_error) then logError("DB", db_error(sql_error,msg));failure, | 91 | error(sql_error) then logError("DB", db_error(sql_error,msg));failure, |
| 92 | ok(cursor) then success(cursor) | 92 | ok(cursor) then success(cursor) |
| 93 | }. | 93 | }. |
| 94 | + | ||
| 95 | +// -- Extractors HELPERS --------------- | ||
| 96 | + | ||
| 97 | +public define List(String) | ||
| 98 | + db_get_string_list | ||
| 99 | + ( | ||
| 100 | + SQLite3HeadersOrRow -> SQLite3Row table_cursor, | ||
| 101 | + List(String) so_far | ||
| 102 | + ) = | ||
| 103 | + if table_cursor(next_row) is | ||
| 104 | + { | ||
| 105 | + error(sql_error) then logError("DB", db_error(sql_error, "db_get_string_list")); reverse(so_far), | ||
| 106 | + no_more_row then reverse(so_far), //can't find the symbol in the table, because the row is empty | ||
| 107 | + row(explorer) then | ||
| 108 | + with s = text(explorer)(0), | ||
| 109 | + db_get_string_list(table_cursor, [s . so_far]) | ||
| 110 | + }. | ||
| 111 | + | ||
| 112 | +public define List(Int32) | ||
| 113 | + db_get_integer_list | ||
| 114 | + ( | ||
| 115 | + SQLite3HeadersOrRow -> SQLite3Row table_cursor, | ||
| 116 | + List(Int32) so_far | ||
| 117 | + ) = | ||
| 118 | + if table_cursor(next_row) is | ||
| 119 | + { | ||
| 120 | + error(sql_error) then logError("DB", db_error(sql_error, "db_get_integer_list")); reverse(so_far), | ||
| 121 | + no_more_row then reverse(so_far), //can't find the symbol in the table, because the row is empty | ||
| 122 | + row(explorer) then | ||
| 123 | + with s = (Int32)db_integer(explorer)(0), | ||
| 124 | + db_get_integer_list(table_cursor, [s . so_far]) | ||
| 125 | + }. |