Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added generated sqlite3 interfaces for plugins

  • Loading branch information...
commit 9854f2ecc63e7a34d78760fa885ce29cb486a553 1 parent c1c3dcf
Anastasia Gornostaeva authored
Showing with 1,137 additions and 0 deletions.
  1. +165 −0 markov_sql.ml
  2. +37 −0 muc_sql.ml
  3. +299 −0 seen_sql.ml
  4. +215 −0 talkers_sql.ml
  5. +421 −0 wtf_sql.ml
View
165 markov_sql.ml
@@ -0,0 +1,165 @@
+(* DO NOT EDIT MANUALLY *)
+(* *)
+(* generated by sqlgg 0.2.3-49-g30df037 on 2010-01-14T17:45Z *)
+
+module Make (T : Sqlgg_traits.M) = struct
+
+ let create_words db =
+ T.execute db "CREATE TABLE IF NOT EXISTS words (word1 varchar(256), word2 varchar(256), counter int)" T.no_params
+
+ let create_index_word1word2 db =
+ T.execute db "CREATE INDEX IF NOT EXISTS word1word2 ON words (word1, word2)" T.no_params
+
+ let check_pair db ~word1 ~word2 =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 word1;
+ T.set_param_Text p 1 word2;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM words WHERE word1=@word1 AND word2=@word2 LIMIT 1" set_params get_row
+
+ let add_pair db ~word1 ~word2 ~counter =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 word1;
+ T.set_param_Text p 1 word2;
+ T.set_param_Int p 2 counter;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO words (word1, word2, counter) VALUES (@word1,@word2,@counter)" set_params
+
+ let update_pair db ~word1 ~word2 =
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 word1;
+ T.set_param_Text p 1 word2;
+ T.finish_params p
+ in
+ T.execute db "UPDATE words SET counter=counter+1 WHERE word1=@word1 AND word2=@word2" set_params
+
+ let get_sum db ~word1 =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 word1;
+ T.finish_params p
+ in
+ T.select1 db "SELECT coalesce(sum(counter),0) FROM words WHERE word1=@word1 LIMIT 1" set_params get_row
+
+ let get_pair db ~word1 callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Int stmt 1)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 word1;
+ T.finish_params p
+ in
+ T.select db "SELECT word2, counter FROM words WHERE word1=@word1" set_params invoke_callback
+
+ let count db =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ T.select1 db "SELECT COUNT(*) FROM words" T.no_params get_row
+
+ let get_top db callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Int stmt 2)
+ in
+ T.select db "SELECT word1, word2, counter FROM words WHERE word1!='' AND word2!='' ORDER BY counter DESC LIMIT 10" T.no_params invoke_callback
+
+ module Fold = struct
+ let create_words db =
+ T.execute db "CREATE TABLE IF NOT EXISTS words (word1 varchar(256), word2 varchar(256), counter int)" T.no_params
+
+ let create_index_word1word2 db =
+ T.execute db "CREATE INDEX IF NOT EXISTS word1word2 ON words (word1, word2)" T.no_params
+
+ let check_pair db ~word1 ~word2 =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 word1;
+ T.set_param_Text p 1 word2;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM words WHERE word1=@word1 AND word2=@word2 LIMIT 1" set_params get_row
+
+ let add_pair db ~word1 ~word2 ~counter =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 word1;
+ T.set_param_Text p 1 word2;
+ T.set_param_Int p 2 counter;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO words (word1, word2, counter) VALUES (@word1,@word2,@counter)" set_params
+
+ let update_pair db ~word1 ~word2 =
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 word1;
+ T.set_param_Text p 1 word2;
+ T.finish_params p
+ in
+ T.execute db "UPDATE words SET counter=counter+1 WHERE word1=@word1 AND word2=@word2" set_params
+
+ let get_sum db ~word1 =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 word1;
+ T.finish_params p
+ in
+ T.select1 db "SELECT coalesce(sum(counter),0) FROM words WHERE word1=@word1 LIMIT 1" set_params get_row
+
+ let get_pair db ~word1 callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Int stmt 1)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 word1;
+ T.finish_params p
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT word2, counter FROM words WHERE word1=@word1" set_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ let count db =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ T.select1 db "SELECT COUNT(*) FROM words" T.no_params get_row
+
+ let get_top db callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Int stmt 2)
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT word1, word2, counter FROM words WHERE word1!='' AND word2!='' ORDER BY counter DESC LIMIT 10" T.no_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ end (* module Fold *)
+end (* module Make *)
View
37 muc_sql.ml
@@ -0,0 +1,37 @@
+(* DO NOT EDIT MANUALLY *)
+(* *)
+(* generated by sqlgg 0.2.3-49-g30df037 on 2010-01-14T17:45Z *)
+
+module Make (T : Sqlgg_traits.M) = struct
+
+ let create_muc db =
+ T.execute db "CREATE TABLE IF NOT EXISTS muc (room text, nick text, lang text, chatlog char(1))" T.no_params
+
+ let select_rooms db callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Text stmt 2)
+ (T.get_column_Text stmt 3)
+ in
+ T.select db "SELECT room, nick, lang, chatlog FROM muc" T.no_params invoke_callback
+
+ module Fold = struct
+ let create_muc db =
+ T.execute db "CREATE TABLE IF NOT EXISTS muc (room text, nick text, lang text, chatlog char(1))" T.no_params
+
+ let select_rooms db callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Text stmt 2)
+ (T.get_column_Text stmt 3)
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT room, nick, lang, chatlog FROM muc" T.no_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ end (* module Fold *)
+end (* module Make *)
View
299 seen_sql.ml
@@ -0,0 +1,299 @@
+(* DO NOT EDIT MANUALLY *)
+(* *)
+(* generated by sqlgg 0.2.3-49-g30df037 on 2010-01-14T17:45Z *)
+
+module Make (T : Sqlgg_traits.M) = struct
+
+ let create_greeting db =
+ T.execute db "CREATE TABLE IF NOT EXISTS greeting (jid varchar, room varchar, msg varchar)" T.no_params
+
+ let create_index_gr_index db =
+ T.execute db "CREATE INDEX IF NOT EXISTS gr_index ON greeting (jid, room)" T.no_params
+
+ let check_greet db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
+
+ let add_greet db ~jid ~room ~msg =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.set_param_Text p 2 msg;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO greeting (jid, room, msg) VALUES (@jid,@room,@msg)" set_params
+
+ let update_greet db ~msg ~jid ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 msg;
+ T.set_param_Text p 1 jid;
+ T.set_param_Text p 2 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE greeting SET msg=@msg WHERE jid=@jid AND room=@room" set_params
+
+ let get_greet db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Text stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT msg FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
+
+ let create_users db =
+ T.execute db "CREATE TABLE IF NOT EXISTS users (jid varchar, room varchar, nick varchar, last integer, action varchar, reason varchar)" T.no_params
+
+ let create_index_users_index db =
+ T.execute db "CREATE INDEX IF NOT EXISTS users_index ON users (jid, room)" T.no_params
+
+ let create_index_users_nicks db =
+ T.execute db "CREATE INDEX IF NOT EXISTS users_nicks ON users (nick, room)" T.no_params
+
+ let check_user_by_nick db ~nick ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 nick;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM users WHERE nick=@nick AND room=@room LIMIT 1" set_params get_row
+
+ let update_user_by_nick db ~last ~action ~reason ~nick ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 last;
+ T.set_param_Text p 1 action;
+ T.set_param_Text p 2 reason;
+ T.set_param_Text p 3 nick;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE nick=@nick AND room=@room" set_params
+
+ let add_user_by_nick db ~jid ~room ~nick ~last ~action ~reason =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.set_param_Text p 2 nick;
+ T.set_param_Int p 3 last;
+ T.set_param_Text p 4 action;
+ T.set_param_Text p 5 reason;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
+
+ let check_user_by_jid db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM users WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
+
+ let update_user_by_jid db ~last ~action ~reason ~jid ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 last;
+ T.set_param_Text p 1 action;
+ T.set_param_Text p 2 reason;
+ T.set_param_Text p 3 jid;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE jid=@jid AND room=@room" set_params
+
+ let add_user_by_jid db ~jid ~room ~nick ~last ~action ~reason =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.set_param_Text p 2 nick;
+ T.set_param_Int p 3 last;
+ T.set_param_Text p 4 action;
+ T.set_param_Text p 5 reason;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
+
+ let seen_by_nick db ~nick ~room =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Int stmt 1), (T.get_column_Text stmt 2), (T.get_column_Text stmt 3)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 nick;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT jid, last, action, reason FROM users WHERE nick=@nick AND room=@room ORDER BY last DESC LIMIT 1" set_params get_row
+
+ module Fold = struct
+ let create_greeting db =
+ T.execute db "CREATE TABLE IF NOT EXISTS greeting (jid varchar, room varchar, msg varchar)" T.no_params
+
+ let create_index_gr_index db =
+ T.execute db "CREATE INDEX IF NOT EXISTS gr_index ON greeting (jid, room)" T.no_params
+
+ let check_greet db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
+
+ let add_greet db ~jid ~room ~msg =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.set_param_Text p 2 msg;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO greeting (jid, room, msg) VALUES (@jid,@room,@msg)" set_params
+
+ let update_greet db ~msg ~jid ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 msg;
+ T.set_param_Text p 1 jid;
+ T.set_param_Text p 2 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE greeting SET msg=@msg WHERE jid=@jid AND room=@room" set_params
+
+ let get_greet db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Text stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT msg FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
+
+ let create_users db =
+ T.execute db "CREATE TABLE IF NOT EXISTS users (jid varchar, room varchar, nick varchar, last integer, action varchar, reason varchar)" T.no_params
+
+ let create_index_users_index db =
+ T.execute db "CREATE INDEX IF NOT EXISTS users_index ON users (jid, room)" T.no_params
+
+ let create_index_users_nicks db =
+ T.execute db "CREATE INDEX IF NOT EXISTS users_nicks ON users (nick, room)" T.no_params
+
+ let check_user_by_nick db ~nick ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 nick;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM users WHERE nick=@nick AND room=@room LIMIT 1" set_params get_row
+
+ let update_user_by_nick db ~last ~action ~reason ~nick ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 last;
+ T.set_param_Text p 1 action;
+ T.set_param_Text p 2 reason;
+ T.set_param_Text p 3 nick;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE nick=@nick AND room=@room" set_params
+
+ let add_user_by_nick db ~jid ~room ~nick ~last ~action ~reason =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.set_param_Text p 2 nick;
+ T.set_param_Int p 3 last;
+ T.set_param_Text p 4 action;
+ T.set_param_Text p 5 reason;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
+
+ let check_user_by_jid db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM users WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
+
+ let update_user_by_jid db ~last ~action ~reason ~jid ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 last;
+ T.set_param_Text p 1 action;
+ T.set_param_Text p 2 reason;
+ T.set_param_Text p 3 jid;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE jid=@jid AND room=@room" set_params
+
+ let add_user_by_jid db ~jid ~room ~nick ~last ~action ~reason =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.set_param_Text p 2 nick;
+ T.set_param_Int p 3 last;
+ T.set_param_Text p 4 action;
+ T.set_param_Text p 5 reason;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
+
+ let seen_by_nick db ~nick ~room =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Int stmt 1), (T.get_column_Text stmt 2), (T.get_column_Text stmt 3)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 nick;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT jid, last, action, reason FROM users WHERE nick=@nick AND room=@room ORDER BY last DESC LIMIT 1" set_params get_row
+
+ end (* module Fold *)
+end (* module Make *)
View
215 talkers_sql.ml
@@ -0,0 +1,215 @@
+(* DO NOT EDIT MANUALLY *)
+(* *)
+(* generated by sqlgg 0.2.3-49-g30df037 on 2010-01-14T17:45Z *)
+
+module Make (T : Sqlgg_traits.M) = struct
+
+ let create_talkers db =
+ T.execute db "CREATE TABLE IF NOT EXISTS talkers (jid varchar, nick varchar, room varchar, words int, me int, sentences int)" T.no_params
+
+ let create_index_talkers_idx db =
+ T.execute db "CREATE INDEX IF NOT EXISTS talkers_idx ON talkers (jid, room)" T.no_params
+
+ let create_index_words_idx db =
+ T.execute db "CREATE INDEX IF NOT EXISTS words_idx ON talkers (words)" T.no_params
+
+ let test_nick db ~nick ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 nick;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM talkers WHERE nick=@nick AND room=@room LIMIT 1" set_params get_row
+
+ let test_jid db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM talkers WHERE jid=@jid AND room=@room limit 1" set_params get_row
+
+ let update_by_nick db ~words ~sentences ~me ~nick ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 words;
+ T.set_param_Int p 1 sentences;
+ T.set_param_Int p 2 me;
+ T.set_param_Text p 3 nick;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE talkers SET words=words+@words, sentences=sentences+@sentences, me=me+@me WHERE nick=@nick AND room=@room" set_params
+
+ let update_by_jid db ~words ~sentences ~me ~jid ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 words;
+ T.set_param_Int p 1 sentences;
+ T.set_param_Int p 2 me;
+ T.set_param_Text p 3 jid;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE talkers SET words=words+@words, sentences=sentences+@sentences, me=me+@me WHERE jid=@jid AND room=@room" set_params
+
+ let insert_new db ~jid ~nick ~room ~words ~me ~sentences =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 room;
+ T.set_param_Int p 3 words;
+ T.set_param_Int p 4 me;
+ T.set_param_Int p 5 sentences;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO talkers (jid, nick, room, words, me, sentences) VALUES (@jid,@nick,@room,@words,@me,@sentences)" set_params
+
+ let select_talkers_by_nick db ~room ~nick callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Int stmt 1)
+ (T.get_column_Int stmt 2)
+ (T.get_column_Int stmt 3)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 room;
+ T.set_param_Text p 1 nick;
+ T.finish_params p
+ in
+ T.select db "SELECT nick, words, me, sentences FROM talkers WHERE room=@room AND nick LIKE @nick ORDER BY words DESC, sentences ASC" set_params invoke_callback
+
+ let select_talkers_limit db ~room callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Int stmt 1)
+ (T.get_column_Int stmt 2)
+ (T.get_column_Int stmt 3)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 room;
+ T.finish_params p
+ in
+ T.select db "SELECT nick, words, me, sentences FROM talkers WHERE room=@room ORDER BY words DESC, sentences ASC LIMIT 10" set_params invoke_callback
+
+ module Fold = struct
+ let create_talkers db =
+ T.execute db "CREATE TABLE IF NOT EXISTS talkers (jid varchar, nick varchar, room varchar, words int, me int, sentences int)" T.no_params
+
+ let create_index_talkers_idx db =
+ T.execute db "CREATE INDEX IF NOT EXISTS talkers_idx ON talkers (jid, room)" T.no_params
+
+ let create_index_words_idx db =
+ T.execute db "CREATE INDEX IF NOT EXISTS words_idx ON talkers (words)" T.no_params
+
+ let test_nick db ~nick ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 nick;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM talkers WHERE nick=@nick AND room=@room LIMIT 1" set_params get_row
+
+ let test_jid db ~jid ~room =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 room;
+ T.finish_params p
+ in
+ T.select1 db "SELECT 1 FROM talkers WHERE jid=@jid AND room=@room limit 1" set_params get_row
+
+ let update_by_nick db ~words ~sentences ~me ~nick ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 words;
+ T.set_param_Int p 1 sentences;
+ T.set_param_Int p 2 me;
+ T.set_param_Text p 3 nick;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE talkers SET words=words+@words, sentences=sentences+@sentences, me=me+@me WHERE nick=@nick AND room=@room" set_params
+
+ let update_by_jid db ~words ~sentences ~me ~jid ~room =
+ let set_params stmt =
+ let p = T.start_params stmt 5 in
+ T.set_param_Int p 0 words;
+ T.set_param_Int p 1 sentences;
+ T.set_param_Int p 2 me;
+ T.set_param_Text p 3 jid;
+ T.set_param_Text p 4 room;
+ T.finish_params p
+ in
+ T.execute db "UPDATE talkers SET words=words+@words, sentences=sentences+@sentences, me=me+@me WHERE jid=@jid AND room=@room" set_params
+
+ let insert_new db ~jid ~nick ~room ~words ~me ~sentences =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Text p 0 jid;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 room;
+ T.set_param_Int p 3 words;
+ T.set_param_Int p 4 me;
+ T.set_param_Int p 5 sentences;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO talkers (jid, nick, room, words, me, sentences) VALUES (@jid,@nick,@room,@words,@me,@sentences)" set_params
+
+ let select_talkers_by_nick db ~room ~nick callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Int stmt 1)
+ (T.get_column_Int stmt 2)
+ (T.get_column_Int stmt 3)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 room;
+ T.set_param_Text p 1 nick;
+ T.finish_params p
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT nick, words, me, sentences FROM talkers WHERE room=@room AND nick LIKE @nick ORDER BY words DESC, sentences ASC" set_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ let select_talkers_limit db ~room callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Int stmt 1)
+ (T.get_column_Int stmt 2)
+ (T.get_column_Int stmt 3)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 room;
+ T.finish_params p
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT nick, words, me, sentences FROM talkers WHERE room=@room ORDER BY words DESC, sentences ASC LIMIT 10" set_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ end (* module Fold *)
+end (* module Make *)
View
421 wtf_sql.ml
@@ -0,0 +1,421 @@
+(* DO NOT EDIT MANUALLY *)
+(* *)
+(* generated by sqlgg 0.2.3-49-g30df037 on 2010-01-14T17:45Z *)
+
+module Make (T : Sqlgg_traits.M) = struct
+
+ let create_wtf db =
+ T.execute db "CREATE TABLE IF NOT EXISTS wtf (stamp int, nick varchar, luser varchar, lserver varchar, \"key\" varchar, \"value\" varchar)" T.no_params
+
+ let create_index_dfnidx db =
+ T.execute db "CREATE INDEX IF NOT EXISTS dfnidx ON wtf (\"key\")" T.no_params
+
+ let create_index_dfncheck db =
+ T.execute db "CREATE INDEX IF NOT EXISTS dfncheck ON wtf (\"key\", luser, lserver)" T.no_params
+
+ let total db =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ T.select1 db "SELECT COUNT(*) FROM wtf" T.no_params get_row
+
+ let dfn_new db ~stamp ~nick ~luser ~lserver ~key ~value =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Int p 0 stamp;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 luser;
+ T.set_param_Text p 3 lserver;
+ T.set_param_Text p 4 key;
+ T.set_param_Text p 5 value;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO wtf (stamp, nick, luser, lserver, \"key\", \"value\") VALUES (@stamp,@nick,@luser,@lserver,@key,@value)" set_params
+
+ let dfn_check_by_jid db ~key ~luser ~lserver =
+ let get_row stmt =
+ (T.get_column_Text stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 luser;
+ T.set_param_Text p 2 lserver;
+ T.finish_params p
+ in
+ T.select1 db "SELECT \"value\" FROM wtf WHERE \"key\"=@key AND luser=@luser AND lserver=@lserver LIMIT 1" set_params get_row
+
+ let dfn_delete_by_jid db ~key ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 luser;
+ T.set_param_Text p 2 lserver;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key AND luser=@luser AND lserver=@lserver" set_params
+
+ let dfn_update_by_jid db ~stamp ~nick ~value ~key ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Int p 0 stamp;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 value;
+ T.set_param_Text p 3 key;
+ T.set_param_Text p 4 luser;
+ T.set_param_Text p 5 lserver;
+ T.finish_params p
+ in
+ T.execute db "UPDATE wtf SET stamp=@stamp, nick=@nick, \"value\"=@value WHERE \"key\"=@key AND luser=@luser AND lserver=@lserver" set_params
+
+ let dfn_check_by_occupant db ~key ~nick ~luser ~lserver =
+ let get_row stmt =
+ (T.get_column_Text stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 4 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 luser;
+ T.set_param_Text p 3 lserver;
+ T.finish_params p
+ in
+ T.select1 db "SELECT \"value\" FROM wtf WHERE \"key\"=@key AND nick=@nick AND luser=@luser AND lserver=@lserver LIMIT 1" set_params get_row
+
+ let dfn_delete_by_occupant db ~key ~nick ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 4 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 luser;
+ T.set_param_Text p 3 lserver;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key AND nick=@nick AND luser=@luser AND lserver=@lserver" set_params
+
+ let dfn_update_by_occupant db ~stamp ~value ~key ~nick ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Int p 0 stamp;
+ T.set_param_Text p 1 value;
+ T.set_param_Text p 2 key;
+ T.set_param_Text p 3 nick;
+ T.set_param_Text p 4 luser;
+ T.set_param_Text p 5 lserver;
+ T.finish_params p
+ in
+ T.execute db "UPDATE wtf SET stamp=@stamp, \"value\"=@value WHERE \"key\"=@key AND nick=@nick AND luser=@luser AND lserver=@lserver" set_params
+
+ let get_wtf_one db ~key =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Text stmt 1)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select1 db "SELECT nick, \"value\" FROM wtf WHERE \"key\"=@key ORDER BY stamp DESC LIMIT 1" set_params get_row
+
+ let get_wtf_all db ~key callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Text stmt 2)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select db "SELECT nick, \"key\", \"value\" FROM wtf WHERE \"key\"=@key ORDER BY stamp" set_params invoke_callback
+
+ let wtf_count db ~key =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select1 db "SELECT count(*) FROM wtf WHERE \"key\"=@key" set_params get_row
+
+ let wtffind db ~key ~value callback =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Text stmt 2)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 value;
+ T.finish_params p
+ in
+ T.select db "SELECT nick, \"key\", \"value\" FROM wtf WHERE \"key\" LIKE @key OR \"value\" LIKE @value" set_params invoke_callback
+
+ let get_rand db ~rand =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Text stmt 1), (T.get_column_Text stmt 2)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Int p 0 rand;
+ T.finish_params p
+ in
+ T.select1 db "SELECT nick, \"key\", \"value\" FROM wtf LIMIT @rand,1" set_params get_row
+
+ let get_key_total db ~key =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select1 db "SELECT count(*) FROM wtf WHERE \"key\"=@key" set_params get_row
+
+ let get_rand_key db ~key ~rand =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Text stmt 1)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 key;
+ T.set_param_Int p 1 rand;
+ T.finish_params p
+ in
+ T.select1 db "SELECT nick, \"value\" FROM wtf WHERE \"key\"=@key LIMIT @rand,1" set_params get_row
+
+ let delete_key db ~key =
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key" set_params
+
+ let delete_key_value db ~key ~value =
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 value;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key AND \"value\"=@value" set_params
+
+ module Fold = struct
+ let create_wtf db =
+ T.execute db "CREATE TABLE IF NOT EXISTS wtf (stamp int, nick varchar, luser varchar, lserver varchar, \"key\" varchar, \"value\" varchar)" T.no_params
+
+ let create_index_dfnidx db =
+ T.execute db "CREATE INDEX IF NOT EXISTS dfnidx ON wtf (\"key\")" T.no_params
+
+ let create_index_dfncheck db =
+ T.execute db "CREATE INDEX IF NOT EXISTS dfncheck ON wtf (\"key\", luser, lserver)" T.no_params
+
+ let total db =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ T.select1 db "SELECT COUNT(*) FROM wtf" T.no_params get_row
+
+ let dfn_new db ~stamp ~nick ~luser ~lserver ~key ~value =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Int p 0 stamp;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 luser;
+ T.set_param_Text p 3 lserver;
+ T.set_param_Text p 4 key;
+ T.set_param_Text p 5 value;
+ T.finish_params p
+ in
+ T.execute db "INSERT INTO wtf (stamp, nick, luser, lserver, \"key\", \"value\") VALUES (@stamp,@nick,@luser,@lserver,@key,@value)" set_params
+
+ let dfn_check_by_jid db ~key ~luser ~lserver =
+ let get_row stmt =
+ (T.get_column_Text stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 luser;
+ T.set_param_Text p 2 lserver;
+ T.finish_params p
+ in
+ T.select1 db "SELECT \"value\" FROM wtf WHERE \"key\"=@key AND luser=@luser AND lserver=@lserver LIMIT 1" set_params get_row
+
+ let dfn_delete_by_jid db ~key ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 3 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 luser;
+ T.set_param_Text p 2 lserver;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key AND luser=@luser AND lserver=@lserver" set_params
+
+ let dfn_update_by_jid db ~stamp ~nick ~value ~key ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Int p 0 stamp;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 value;
+ T.set_param_Text p 3 key;
+ T.set_param_Text p 4 luser;
+ T.set_param_Text p 5 lserver;
+ T.finish_params p
+ in
+ T.execute db "UPDATE wtf SET stamp=@stamp, nick=@nick, \"value\"=@value WHERE \"key\"=@key AND luser=@luser AND lserver=@lserver" set_params
+
+ let dfn_check_by_occupant db ~key ~nick ~luser ~lserver =
+ let get_row stmt =
+ (T.get_column_Text stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 4 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 luser;
+ T.set_param_Text p 3 lserver;
+ T.finish_params p
+ in
+ T.select1 db "SELECT \"value\" FROM wtf WHERE \"key\"=@key AND nick=@nick AND luser=@luser AND lserver=@lserver LIMIT 1" set_params get_row
+
+ let dfn_delete_by_occupant db ~key ~nick ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 4 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 nick;
+ T.set_param_Text p 2 luser;
+ T.set_param_Text p 3 lserver;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key AND nick=@nick AND luser=@luser AND lserver=@lserver" set_params
+
+ let dfn_update_by_occupant db ~stamp ~value ~key ~nick ~luser ~lserver =
+ let set_params stmt =
+ let p = T.start_params stmt 6 in
+ T.set_param_Int p 0 stamp;
+ T.set_param_Text p 1 value;
+ T.set_param_Text p 2 key;
+ T.set_param_Text p 3 nick;
+ T.set_param_Text p 4 luser;
+ T.set_param_Text p 5 lserver;
+ T.finish_params p
+ in
+ T.execute db "UPDATE wtf SET stamp=@stamp, \"value\"=@value WHERE \"key\"=@key AND nick=@nick AND luser=@luser AND lserver=@lserver" set_params
+
+ let get_wtf_one db ~key =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Text stmt 1)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select1 db "SELECT nick, \"value\" FROM wtf WHERE \"key\"=@key ORDER BY stamp DESC LIMIT 1" set_params get_row
+
+ let get_wtf_all db ~key callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Text stmt 2)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT nick, \"key\", \"value\" FROM wtf WHERE \"key\"=@key ORDER BY stamp" set_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ let wtf_count db ~key =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select1 db "SELECT count(*) FROM wtf WHERE \"key\"=@key" set_params get_row
+
+ let wtffind db ~key ~value callback acc =
+ let invoke_callback stmt =
+ callback
+ (T.get_column_Text stmt 0)
+ (T.get_column_Text stmt 1)
+ (T.get_column_Text stmt 2)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 value;
+ T.finish_params p
+ in
+ let r_acc = ref acc in
+ T.select db "SELECT nick, \"key\", \"value\" FROM wtf WHERE \"key\" LIKE @key OR \"value\" LIKE @value" set_params (fun x -> r_acc := invoke_callback x !r_acc);
+ !r_acc
+
+ let get_rand db ~rand =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Text stmt 1), (T.get_column_Text stmt 2)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Int p 0 rand;
+ T.finish_params p
+ in
+ T.select1 db "SELECT nick, \"key\", \"value\" FROM wtf LIMIT @rand,1" set_params get_row
+
+ let get_key_total db ~key =
+ let get_row stmt =
+ (T.get_column_Int stmt 0)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.select1 db "SELECT count(*) FROM wtf WHERE \"key\"=@key" set_params get_row
+
+ let get_rand_key db ~key ~rand =
+ let get_row stmt =
+ (T.get_column_Text stmt 0), (T.get_column_Text stmt 1)
+ in
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 key;
+ T.set_param_Int p 1 rand;
+ T.finish_params p
+ in
+ T.select1 db "SELECT nick, \"value\" FROM wtf WHERE \"key\"=@key LIMIT @rand,1" set_params get_row
+
+ let delete_key db ~key =
+ let set_params stmt =
+ let p = T.start_params stmt 1 in
+ T.set_param_Text p 0 key;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key" set_params
+
+ let delete_key_value db ~key ~value =
+ let set_params stmt =
+ let p = T.start_params stmt 2 in
+ T.set_param_Text p 0 key;
+ T.set_param_Text p 1 value;
+ T.finish_params p
+ in
+ T.execute db "DELETE FROM wtf WHERE \"key\"=@key AND \"value\"=@value" set_params
+
+ end (* module Fold *)
+end (* module Make *)
Please sign in to comment.
Something went wrong with that request. Please try again.