module ManqodCommon
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)
Constants
- CRITICAL
- DEBUG
- ERROR
- INFO
- NORMAL
- WARNING
Public Instance Methods
add_where(sql,where)
click to toggle source
# File lib/ManqodCommon.rb, line 191 def add_where(sql,where) begin ret=ManqodDB.instance.manqod_db.add_where(sql,where) tell_exception("Database Error","Duplicate entry","sql","error") if ret == -1 ret rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
admin()
click to toggle source
# File lib/ManqodCommon.rb, line 172 def admin begin ManqodDB.instance.manqod_db.admin rescue =>err retry if warn("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
admin_cache()
click to toggle source
# File lib/ManqodCommon.rb, line 123 def admin_cache ManqodDB.instance.acache end
admin_qrow(sql,with_table=false)
click to toggle source
# File lib/ManqodCommon.rb, line 226 def admin_qrow(sql,with_table=false) begin ManqodDB.instance.manqod_db.admin.qrow(sql,with_table) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
admin_rows(sql,with_table=false) { |row| ... }
click to toggle source
# File lib/ManqodCommon.rb, line 217 def admin_rows(sql,with_table=false) # ecode("#{sql}") begin ManqodDB.instance.manqod_db.admin.rows(sql,with_table).each{|row| yield row} rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
backtrace_to_debug(c)
click to toggle source
# File lib/ManqodCommon.rb, line 16 def backtrace_to_debug(c) r="#{c}\n" c.backtrace.each{|i| r=r+"\t#{i}\n"} r end
cache()
click to toggle source
# File lib/ManqodCommon.rb, line 120 def cache ManqodDB.instance.cache end
changed_ids_of_base(base,ids)
click to toggle source
# File lib/ManqodCommon.rb, line 272 def changed_ids_of_base(base,ids) begin ManqodDB.instance.manqod_db.changed_ids_of_base(base,ids,nick) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
client()
click to toggle source
def prep_sql(isql)
ManqodDB.instance.manqod_db.client.escape_string(isql)
end
# File lib/ManqodCommon.rb, line 131 def client begin ManqodDB.instance.manqod_db.client rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
client_fields(sql) { |row| ... }
click to toggle source
# File lib/ManqodCommon.rb, line 148 def client_fields(sql) begin ManqodDB.instance.manqod_db.client.fields(sql).each{|row| yield row} rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
client_image_of_id(image_id=nil,resize=nil)
click to toggle source
# File lib/ManqodCommon.rb, line 263 def client_image_of_id(image_id=nil,resize=nil) begin DrbImages.instance.image_of_id(image_id,resize,true) rescue =>err ewarn(backtrace_to_debug(err)) end end
client_qrow(sql)
click to toggle source
# File lib/ManqodCommon.rb, line 156 def client_qrow(sql) begin ManqodDB.instance.manqod_db.client.qrow(sql) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
client_query(sql)
click to toggle source
# File lib/ManqodCommon.rb, line 139 def client_query(sql) begin einfo("Client query: #{sql}","sql") ManqodDB.instance.manqod_db.client.query(sql) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
client_rows(sql) { |row| ... }
click to toggle source
# File lib/ManqodCommon.rb, line 164 def client_rows(sql) begin ManqodDB.instance.manqod_db.client.rows(sql).each{|row| yield row} rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
eeval(command,context=self)
click to toggle source
# File lib/ManqodCommon.rb, line 61 def eeval(command,context=self) ret=nil begin edebug("Running: #{command}","eval","debug") if context and b=context.getBinding then ret=eval(command, b) else ret=eval(command) end rescue SyntaxError, NameError => err tell_exception("Syntax error: #{command}",backtrace_to_debug(err),"eval","error",true,false) rescue => err # edebug("String doesn't run: #{command}\n"+backtrace_to_debug(b),"eval","error") tell_exception("String doesn't run: #{command}",backtrace_to_debug(err),"eval","error",true,false) end ret end
escape_string(sql)
click to toggle source
# File lib/ManqodCommon.rb, line 248 def escape_string(sql) begin ManqodDB.instance.manqod_db.escape_string(sql) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
getBinding()
click to toggle source
# File lib/ManqodCommon.rb, line 79 def getBinding binding end
guess_base(sql)
click to toggle source
# File lib/ManqodCommon.rb, line 241 def guess_base(sql) begin ManqodDB.instance.manqod_db.guess_base(sql) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
guess_table(sql,field)
click to toggle source
# File lib/ManqodCommon.rb, line 234 def guess_table(sql,field) begin ManqodDB.instance.manqod_db.guess_table(sql,field) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
image_of_id(image_id=nil,resize=nil)
click to toggle source
# File lib/ManqodCommon.rb, line 256 def image_of_id(image_id=nil,resize=nil) begin DrbImages.instance.image_of_id(image_id,resize) rescue =>err ewarn(backtrace_to_debug(err)) end end
lzero(s,n)
click to toggle source
# File lib/ManqodCommon.rb, line 38 def lzero(s,n) while s.to_s.length<n s="0#{s}" end s end
manqod_db()
click to toggle source
# File lib/ManqodCommon.rb, line 113 def manqod_db begin ManqodDB.instance.manqod_db rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
measure(d="",color="default") { || ... }
click to toggle source
# File lib/ManqodCommon.rb, line 22 def measure(d="",color="default") c=case color when "red" then 31 when "blue" then 34 when "green" then 32 when "yellow" then 33 when "magenta" then 35 when "cyan" then 36 when "white" then 37 when "default" then 39 end before_=Time.now yield time_diff=Time.now.to_f-before_.to_f;edebug("\e[#{c}m#{self} #{d} measured: "+sprintf("%.2fs",time_diff)+"\e[0m","time","normal") end
myexec(filename,filedata)
click to toggle source
# File lib/ManqodCommon.rb, line 89 def myexec(filename,filedata) Myexec.instance.myexec(filename,filedata) end
nick()
click to toggle source
# File lib/ManqodCommon.rb, line 93 def nick Nick.instance.get_nick end
nick_id()
click to toggle source
# File lib/ManqodCommon.rb, line 97 def nick_id Nick.instance.nick_id end
number_format(f,d)
click to toggle source
# File lib/ManqodCommon.rb, line 45 def number_format(f,d) s=f.to_s if i=s.index(".") p1=s[0 .. i-1] p2=(s+"0000")[i .. i+d] else p1=s p2=".0000" end if d==0 p1.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") else p1.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") + p2 end end
qrow(sql,with_table=false)
click to toggle source
# File lib/ManqodCommon.rb, line 201 def qrow(sql,with_table=false) begin ManqodDB.instance.manqod_db.qrow(sql,with_table) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
query(sql)
click to toggle source
# File lib/ManqodCommon.rb, line 180 def query(sql) begin einfo("query: #{sql}","sql") ret=ManqodDB.instance.manqod_db.query(sql) tell_exception("Database Error","Duplicate entry","sql","error") if ret == -1 ret rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
reconnect_manqod_db()
click to toggle source
# File lib/ManqodCommon.rb, line 109 def reconnect_manqod_db ManqodDB.instance.connect_to_server end
rows(sql,with_table=false) { |row| ... }
click to toggle source
# File lib/ManqodCommon.rb, line 209 def rows(sql,with_table=false) begin i=ManqodDB.instance.manqod_db.rows(sql,with_table).each{|row| yield row} rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
run_events(gtkobjectid,event_name)
click to toggle source
# File lib/ManqodCommon.rb, line 83 def run_events(gtkobjectid,event_name) edebug("Running events #{event_name} for #{gtkobjectid}","events","debug") EventCache.instance.gtkobject_events(gtkobjectid,event_name){|event_command| eeval(event_command,self)} # edebug("Running events #{event_name} for #{gtkobjectid} finished.","events","debug") end
send_message(*args)
click to toggle source
# File lib/ManqodCommon.rb, line 287 def send_message(*args) begin ManqodDB.instance.manqod_db.send_message(*args) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
sendmail(*args)
click to toggle source
# File lib/ManqodCommon.rb, line 280 def sendmail(*args) begin ManqodDB.instance.manqod_db.sendmail(*args) rescue =>err retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s) end end
set_manqod_db_uri(uri)
click to toggle source
# File lib/ManqodCommon.rb, line 105 def set_manqod_db_uri(uri) ManqodDB.instance.set_manqod_db_uri(uri) end
set_nick(new_nick)
click to toggle source
# File lib/ManqodCommon.rb, line 101 def set_nick(new_nick) Nick.instance.set_nick(new_nick) end