Permalink
Browse files

Removed obsolete file

  • Loading branch information...
1 parent 9854f2e commit 5eaa047fd6530b1bca1df67f992e8f54da15e97f Anastasia Gornostaeva committed Jan 14, 2010
Showing with 0 additions and 116 deletions.
  1. +0 −116 sqlite_util.ml
View
@@ -1,116 +0,0 @@
-(*
- * (c) 2008-2009 Anastasia Gornostaeva. <ermine@ermine.pp.ru>
- *)
-
-open Sqlite3
-
-let string_after s n =
- String.sub s n (String.length s - n)
-
-let escape str =
- let rec aux_escape i acc =
- try
- let q = String.index_from str i '\'' in
- aux_escape (q+1) ("''" :: (String.sub str i (q-i)) :: acc)
- with Not_found ->
- string_after str i :: acc
- in
- "'" ^ (String.concat "" (List.rev (aux_escape 0 []))) ^ "'"
-
-let exit_with_rc file db sql =
- (match errcode db with
- | Rc.NOTADB ->
- Printf.eprintf "File %s is not a Sqlite3 database\n" file;
- | Rc.ERROR ->
- Printf.eprintf "File %s: Bad SQL:\n%s\n" file sql;
- | rc ->
- Printf.eprintf "File %s: %s\n" file (Rc.to_string rc);
- );
- flush Pervasives.stderr;
- Pervasives.exit 127
-
-let simple_exec file db sql =
- try match exec db sql with
- | Rc.OK -> ()
- | _ -> exit_with_rc file db sql
- with Sqlite3.Error _ ->
- exit_with_rc file db sql
-
-
-let create_table file db sql1 sql2 =
- let found =
- try
- let stmt = prepare db sql1 in
- match step stmt with
- | Rc.ROW -> true
- | Rc.DONE -> false
- | _ -> exit_with_rc file db sql1
- with Sqlite3.Error _ -> exit_with_rc file db sql1
- in
- if not found then
- simple_exec file db sql2
-
-let get_one_row file db sql =
- try
- let stmt = prepare db sql in
- let res =
- match step stmt with
- | Rc.ROW -> Some (row_data stmt)
- | Rc.DONE -> None
- | _ -> exit_with_rc file db sql
- in
- if finalize stmt <> Rc.OK then
- exit_with_rc file db sql;
- res
- with Sqlite3.Error _ -> exit_with_rc file db sql
-
-let get_row stmt =
- match step stmt with
- | Rc.ROW -> Some (row_data stmt)
- | Rc.DONE -> None
- | _ -> raise (Sqlite3.Error "")
-
-let insert_or_update file db sql1 sql2 sql3 =
- let found =
- match get_one_row file db sql1 with
- | Some _ -> true
- | None -> false
- in
- simple_exec file db (if found then sql2 else sql3);
- found
-
-(*
-type t =
- | NONE
- | NULL
- | INT of int64
- | FLOAT of float
- | TEXT of string
- | BLOB of string
-*)
-
-open Sqlite3.Data
-
-let int64_of_data = function
- | INT i -> i
- | NULL
- | NONE
- | FLOAT _
- | TEXT _
- | BLOB _ -> raise (Invalid_argument "int64_of_data")
-
-let float_of_data = function
- | FLOAT f -> f
- | NULL
- | NONE
- | INT _
- | TEXT _
- | BLOB _ -> raise (Invalid_argument "float_of_data")
-
-let string_of_data = function
- | TEXT t -> t
- | BLOB t -> t
- | NULL
- | NONE
- | FLOAT _
- | INT _ -> raise (Invalid_argument "string_of_data")

0 comments on commit 5eaa047

Please sign in to comment.