diff options
author | Ralph Amissah <ralph@amissah.com> | 2008-12-22 01:08:06 -0500 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2008-12-24 00:34:18 -0500 |
commit | 71223cf6cd035b3e395f6d4c3e4c41b79ed29510 (patch) | |
tree | 58fe17f8c2340792924b0eb2eeea51a8e9805e53 /lib/sisu/v0/db_drop.rb | |
parent | SiSU's sqlite module still broken for the time being: inconsistent ruby dbi api (diff) |
sqlite3 fix, populate do using rb sqlite3 driver directly (rb dbi problematic
at present)
sqlite fix, change ruby driver used to populate sisu sqlite3 db to rb sqlite3
for the time being. Use rb sqlite3 driver directly rather (than more convenient
when working) rb dbi interface to populate content. Used to bypass problems
with rb dbi sqlite3 interface noted in sisu 0.66.2 (2008-04-25) and 0.66.3
(2008-05-11) that have have persisted (apparently worked at end 2007 (v.0.62.4)
and start of 2008 (v.0.64.0)
* sqlite dropall, fix
* fix to auto-generated sqlite cgi script sample, only works if at least one
existing populated sisu sqlite database is found during the generation process
Diffstat (limited to 'lib/sisu/v0/db_drop.rb')
-rw-r--r-- | lib/sisu/v0/db_drop.rb | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/lib/sisu/v0/db_drop.rb b/lib/sisu/v0/db_drop.rb index f41325b2..93b27e6d 100644 --- a/lib/sisu/v0/db_drop.rb +++ b/lib/sisu/v0/db_drop.rb @@ -60,40 +60,56 @@ =end module SiSU_DB_drop class Drop - def initialize(opt,conn,file,sql_type='') - @opt,@conn,@file,@sql_type=opt,conn,file,sql_type + require "#{SiSU_lib}/response" + def initialize(opt,conn,db_info,sql_type='') + @opt,@conn,@db_info,@sql_type=opt,conn,db_info,sql_type + @ans=SiSU_Response::Response.new + case @sql_type + when /sqlite/ + cascade='' + else + cascade='CASCADE' + end + @drop_table=[ + "DROP TABLE metadata #{cascade};", + "DROP TABLE documents #{cascade};", + "DROP TABLE urls #{cascade};", + "DROP TABLE endnotes #{cascade};", + "DROP TABLE endnotes_asterisk #{cascade};", + "DROP TABLE endnotes_plus #{cascade};", + ] end def drop def tables #% drop all tables begin + msg_sqlite="as not all disk space is recovered after dropping the database << #{@db_info.sqlite.db} >>, you may be better off deleting the file, and recreating it as necessary" case @sql_type when /sqlite/ - cascade='' - commit=@conn.commit + @conn.transaction + @drop_table.each do |d| + @conn.execute(d) + end + @conn.commit + puts msg_sqlite + ans=@ans.response?('remove sql database?') + if ans and File.exist?(@db_info.sqlite.db) + File.unlink(@db_info.sqlite.db) + end else - cascade='CASCADE' - commit='' + @conn.do(@drop_table.join('')) end - @conn.do(%{ - DROP TABLE metadata #{cascade}; - DROP TABLE documents #{cascade}; - DROP TABLE urls #{cascade}; - DROP TABLE endnotes #{cascade}; - DROP TABLE endnotes_asterisk #{cascade}; - DROP TABLE endnotes_plus #{cascade}; - }) - commit rescue - @conn.do(%{ - DROP TABLE endnotes; - DROP TABLE endnotes_asterisk; - DROP TABLE endnotes_plus; - DROP TABLE urls #{cascade}; - DROP TABLE documents #{cascade}; - DROP TABLE metadata #{cascade}; - }) + case @sql_type + when /sqlite/ + #system("rm -vi #{@db_info.sqlite.db}") + ans=@ans.response?('remove sql database?') + if ans and File.exist?(@db_info.sqlite.db); File.unlink(@db_info.sqlite.db) + end + else + @conn.do(@drop_table.join('')) + end ensure - commit + #commit end end def indexes #% drop all indexes |