diff --git a/anubis_dev/library/data_base/sqlite.anubis b/anubis_dev/library/data_base/sqlite.anubis index 9073f7e..5d3295c 100644 --- a/anubis_dev/library/data_base/sqlite.anubis +++ b/anubis_dev/library/data_base/sqlite.anubis @@ -34,7 +34,11 @@ read tools/basis.anubis Row_2_String1 | Row2_String2 | Row2_String3 ... -public define One db_print_table ( List(List(String)) l ) = +public define One + db_print_table + ( + List(List(String)) l + ) = if l is { [ ] then print("\n"), @@ -75,7 +79,18 @@ public define Int32 -> String blob(b) then " ", null then " NULL " }. - + +public define Int32 -> Maybe(Int32) + integer + ( + Int32 -> SQLite3Datum row + ) = + (Int32 i) |-> + if row(i) is integer(n) then + success(n) + else + failure. + public define One db_print_table ( @@ -89,7 +104,36 @@ public define One db_print_row(row,0); db_print_table(cursor) }. - + +define Int32 + count_rows_private + ( + One -> Maybe(Int32 -> SQLite3Datum) cursor, + Int32 so_far + ) = + if cursor(unique) is + { + failure then so_far, + success(row) then count_rows_private(cursor, so_far + 1) + }. + +/** Count the number of rows in the cursor. So this function call + * itself recursively until the cursor become empty. At each call + * it count the row. + * @param cursor, Database cursor, which must be counted + * @param so_far number of recursive call + */ +public define Int32 + count_rows + ( + One -> Maybe(Int32 -> SQLite3Datum) cursor + ) = + if cursor(unique) is + { + failure then 0, + success(row) then count_rows_private(cursor, 1) + }. + *Description* -- libgit2 0.21.4