From 9ed5b738a4a28051e39be8427b5c393b03c56359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Oct 2011 16:49:13 +0200 Subject: [PATCH] Bug #848: Take into account bug #871, avoid table lock --- src/onedb/3.0_to_3.1.0.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/onedb/3.0_to_3.1.0.rb b/src/onedb/3.0_to_3.1.0.rb index 821d8f6b8f..b2700da390 100644 --- a/src/onedb/3.0_to_3.1.0.rb +++ b/src/onedb/3.0_to_3.1.0.rb @@ -49,6 +49,8 @@ module Migrator end def check_names(table, elem) + @db.run "CREATE TABLE migrator_tmp (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT);" + @db.fetch("SELECT * FROM #{table}") do |row| if ( row[:name].length > 128 ) # Element name is bigger than 128 chars @@ -58,14 +60,23 @@ module Migrator doc.root.each_element("NAME") { |e| e.text = new_name - - @db[table].filter(:oid => row[:oid]).update( - :name => new_name, - :body => doc.root.to_s) } + @db[:migrator_tmp].insert( + :oid => row[:oid], + :name => new_name, + :body => doc.root.to_s) + puts " > #{elem} ##{row[:oid]} had a name bigger than 128 chars and has been renamed to #{new_name[0..10]}..." end end + + @db.fetch("SELECT * FROM migrator_tmp") do |row| + @db[table].filter(:oid => row[:oid]).update( + :name => row[:name], + :body => row[:body]) + end + + @db.run "DROP TABLE migrator_tmp" end end