module Roma::Storage::SQLite3_Ext

Public Instance Methods

create_table() click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
46 def create_table
47   sql = "create table t_roma ( " + 
48     "key TEXT PRIMARY KEY," +
49     "val BLOB);"
50   self.execute( sql )
51 end
each() { |r,r| ... } click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
40 def each
41   self.execute("select * from t_roma"){ |r|
42     yield r[0],r[1]
43   }
44 end
get(k) click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
19 def get(k)
20   if RUBY_VERSION >= "1.9.1"
21     k = k.encode("ascii-8bit") if k.encoding != Encoding::ASCII_8BIT
22   end
23   r = self.execute("select * from t_roma where key=?",k)
24   return nil if r.length==0
25   r[0][1]
26 end
out(k) click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
28 def out(k)
29   if RUBY_VERSION >= "1.9.1"
30     k = k.encode("ascii-8bit") if k.encoding != Encoding::ASCII_8BIT
31   end
32   return nil if get(k) == nil
33   self.execute("delete from t_roma where key=?",k)
34 end
put(k,v) click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
 8 def put(k,v)
 9   if RUBY_VERSION >= "1.9.1"
10     k = k.encode("ascii-8bit") if k.encoding != Encoding::ASCII_8BIT
11   end
12   if self.execute("select count(*) from t_roma where key=?",k)[0][0].to_i==0
13     self.execute("insert into t_roma values (?,?)",k,SQLite3::Blob.new(v))
14   else
15     self.execute("update t_roma set val=? where key=?",SQLite3::Blob.new(v),k)
16   end
17 end
rnum() click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
36 def rnum
37   self.execute("select count(*) from t_roma")[0][0].to_i
38 end
sync() click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
60 def sync
61   true
62 end
tables() click to toggle source
   # File lib/roma/storage/sqlite3_storage.rb
53 def tables
54   sql = "SELECT name FROM " +
55     "sqlite_master WHERE type='table' UNION ALL SELECT name FROM sqlite_temp_master " +
56     "WHERE type='table' ORDER BY name;"
57   self.execute( sql ).flatten
58 end