aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v0/db_remove.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v0/db_remove.rb')
-rw-r--r--lib/sisu/v0/db_remove.rb54
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/sisu/v0/db_remove.rb b/lib/sisu/v0/db_remove.rb
index 93680f2c..a869bd24 100644
--- a/lib/sisu/v0/db_remove.rb
+++ b/lib/sisu/v0/db_remove.rb
@@ -67,21 +67,35 @@ module SiSU_DB_remove
@db=SiSU_Env::Info_db.new
end
def remove
- del=@conn.select_one(%{ SELECT tid FROM metadata WHERE filename LIKE '#{@opt.fns}'; })
- if del
- del_id=del.join
- #@conn.execute("BEGIN")
- sql_entry=<<SQL
-DELETE FROM endnotes WHERE metadata_tid = '#{del_id}';
-DELETE FROM endnotes_asterisk WHERE metadata_tid = '#{del_id}';
-DELETE FROM endnotes_plus WHERE metadata_tid = '#{del_id}';
-DELETE FROM documents WHERE metadata_tid = '#{del_id}';
-DELETE FROM urls WHERE metadata_tid = '#{del_id}';
-DELETE FROM metadata WHERE tid = '#{del_id}';
-SQL
+ driver_sqlite3 = true if @conn.inspect.match(/^(.{10})/)[1] == @db.sqlite.conn_sqlite3.inspect.match(/^(.{10})/)[1]
+ del_id=if driver_sqlite3
+ @conn.get_first_value(%{ SELECT tid FROM metadata WHERE filename LIKE '#{@opt.fns}'; }).to_i
+ else
+ x=@conn.select_one(%{ SELECT tid FROM metadata WHERE filename LIKE '#{@opt.fns}'; })
+ del=if x; x.join.to_i else nil
+ end
+ end
+ if del_id
+ sql_entry=[
+ "DELETE FROM endnotes WHERE metadata_tid = '#{del_id}';",
+ "DELETE FROM endnotes_asterisk WHERE metadata_tid = '#{del_id}';",
+ "DELETE FROM endnotes_plus WHERE metadata_tid = '#{del_id}';",
+ "DELETE FROM documents WHERE metadata_tid = '#{del_id}';",
+ "DELETE FROM urls WHERE metadata_tid = '#{del_id}';",
+ "DELETE FROM metadata WHERE tid = '#{del_id}';",
+ ]
+ if driver_sqlite3
+ @conn.transaction
+ sql_entry.each do |s|
+ @conn.execute(s)
+ end
+ @conn.commit if driver_sqlite3
+ else
+ s=sql_entry.join(' ')
+ @conn.execute(s)
+ end
if @opt.cmd =~/M/
@file.puts sql_entry if @opt.cmd =~/M/
- else @conn.execute(%{#{sql_entry}})
end
else
tell=SiSU_Screen::Ansi.new(@opt.cmd,"no such file in database #{@db.psql.db}::#{@opt.fns}")
@@ -91,17 +105,3 @@ SQL
end
end
__END__
-DELETE FROM endnotes WHERE metadata_tid = '#{del_id}';
-DELETE FROM endnotes_asterisk WHERE metadata_tid = '#{del_id}';
-DELETE FROM endnotes_plus WHERE metadata_tid = '#{del_id}';
-DELETE FROM documents WHERE metadata_tid = '#{del_id}';
-DELETE FROM urls WHERE metadata_tid = '#{del_id}';
-DELETE FROM metadata WHERE tid = '#{del_id}';
-/*
-DELETE FROM documents WHERE documents.metadata_tid = '#{del_id}';
-DELETE FROM endnotes WHERE endnotes.metadata_tid = '#{del_id}';
-DELETE FROM endnotes_asterisk WHERE endnotes_asterisk.metadata_tid = '#{del_id}';
-DELETE FROM endnotes_plus WHERE endnotes_plus.metadata_tid = '#{del_id}';
-DELETE FROM urls WHERE urls.metadata_tid = '#{del_id}';
-DELETE FROM metadata WHERE metadata.tid = '#{del_id}';
-*/