Commit 8862f1c8989c8e94553e8186d1a5520ae547787c
1 parent
7aa3b62a
add the count_rows method
Showing
1 changed file
with
47 additions
and
3 deletions
Show diff stats
anubis_dev/library/data_base/sqlite.anubis
| ... | ... | @@ -34,7 +34,11 @@ read tools/basis.anubis |
| 34 | 34 | Row_2_String1 | Row2_String2 | Row2_String3 |
| 35 | 35 | ... |
| 36 | 36 | |
| 37 | -public define One db_print_table ( List(List(String)) l ) = | |
| 37 | +public define One | |
| 38 | + db_print_table | |
| 39 | + ( | |
| 40 | + List(List(String)) l | |
| 41 | + ) = | |
| 38 | 42 | if l is |
| 39 | 43 | { |
| 40 | 44 | [ ] then print("\n"), |
| ... | ... | @@ -75,7 +79,18 @@ public define Int32 -> String |
| 75 | 79 | blob(b) then " <blob "+length(b)+">", |
| 76 | 80 | null then " NULL " |
| 77 | 81 | }. |
| 78 | - | |
| 82 | + | |
| 83 | +public define Int32 -> Maybe(Int32) | |
| 84 | + integer | |
| 85 | + ( | |
| 86 | + Int32 -> SQLite3Datum row | |
| 87 | + ) = | |
| 88 | + (Int32 i) |-> | |
| 89 | + if row(i) is integer(n) then | |
| 90 | + success(n) | |
| 91 | + else | |
| 92 | + failure. | |
| 93 | + | |
| 79 | 94 | public define One |
| 80 | 95 | db_print_table |
| 81 | 96 | ( |
| ... | ... | @@ -89,7 +104,36 @@ public define One |
| 89 | 104 | db_print_row(row,0); |
| 90 | 105 | db_print_table(cursor) |
| 91 | 106 | }. |
| 92 | - | |
| 107 | + | |
| 108 | +define Int32 | |
| 109 | + count_rows_private | |
| 110 | + ( | |
| 111 | + One -> Maybe(Int32 -> SQLite3Datum) cursor, | |
| 112 | + Int32 so_far | |
| 113 | + ) = | |
| 114 | + if cursor(unique) is | |
| 115 | + { | |
| 116 | + failure then so_far, | |
| 117 | + success(row) then count_rows_private(cursor, so_far + 1) | |
| 118 | + }. | |
| 119 | + | |
| 120 | +/** Count the number of rows in the cursor. So this function call | |
| 121 | + * itself recursively until the cursor become empty. At each call | |
| 122 | + * it count the row. | |
| 123 | + * @param cursor, Database cursor, which must be counted | |
| 124 | + * @param so_far number of recursive call | |
| 125 | + */ | |
| 126 | +public define Int32 | |
| 127 | + count_rows | |
| 128 | + ( | |
| 129 | + One -> Maybe(Int32 -> SQLite3Datum) cursor | |
| 130 | + ) = | |
| 131 | + if cursor(unique) is | |
| 132 | + { | |
| 133 | + failure then 0, | |
| 134 | + success(row) then count_rows_private(cursor, 1) | |
| 135 | + }. | |
| 136 | + | |
| 93 | 137 | |
| 94 | 138 | *Description* |
| 95 | 139 | ... | ... |