File: test_stmt.ml

package info (click to toggle)
ocaml-sqlite3 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 452 kB
  • sloc: ansic: 987; ml: 551; sh: 153; makefile: 95
file content (82 lines) | stat: -rw-r--r-- 2,452 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
open Sqlite3

let column_decltype s i =
  match column_decltype s i with
  | None -> "<NONE>"
  | Some str -> str

let stepbystep s =
  while step s = Rc.ROW do
    for i = 0 to data_count s - 1 do
      Printf.printf "%s column[%d] %s = %s\n%!"
        (column_decltype s i) i
        (column_name s i)
        (Data.to_string (column s i))
    done
  done

let stepbystep_wrong s =
  while step s = Rc.ROW do
    for i = 0 to data_count s do
      Printf.printf "%s column[%d] %s = %s\n%!"
        (column_decltype s i) i
        (column_name s i)
        (Data.to_string (column s i))
    done
  done

let () =
  let db = db_open "t" in

  (* Test the finalization... *)
  for i = 0 to 100 do
    (* Printf.printf "Create statement %d\n%!" i; *)
    let sql = Printf.sprintf "SELECT * FROM tbl0" in
    ignore (prepare db sql)
  done;

  for i = 0 to 100 do
    (* Printf.printf "Create statement %d\n%!" i; *)
    let sql = Printf.sprintf "SELECT * FROM tbl0" in
    ignore (finalize (prepare db sql))
  done;

  for i = 0 to 100 do
    (* Printf.printf "Create statement %d\n%!" i; *)
    let sql = Printf.sprintf "SELECT * FROM tbl0; SELECT * FROM tbl1;" in
    ignore (prepare_tail (prepare db sql))
  done;

  for i = 1 to 10 do
    (* Printf.printf "Create statement %d\n%!" i; *)
    let sql = Printf.sprintf "SELECT * FROM tbl0; SELECT * FROM tbl1;" in
    let stmt = prepare db sql in
    ignore (finalize stmt);
    try ignore (prepare_tail stmt)
    with _xcp -> ()
  done;

  let sql = Printf.sprintf "SELECT * FROM tbl0; SELECT * FROM tbl0;" in
  let stmt = prepare db sql in
  print_endline "A-------------------------------------------";
  stepbystep stmt;
  print_endline "B-------------------------------------------";
  (match prepare_tail stmt with
  | Some s -> stepbystep s
  | None -> failwith "Tail not found!");
  ignore (reset stmt);
  print_endline "C-------------------------------------------";
  stepbystep stmt;
  print_endline "D-------------------------------------------";
  (match prepare_tail stmt with
  | Some s -> stepbystep s
  | None -> failwith "Tail not found!");
  (match prepare_tail stmt with
  | Some s -> stepbystep s
  | None -> failwith "Tail not found!");
  print_endline "E-------------------------------------------";
  try
    match prepare_tail stmt with
    | Some s -> stepbystep_wrong s
    | None -> failwith "Tail not found!"
  with xcp -> Printf.printf "Ok: %s\n" (Printexc.to_string xcp)