lib/framework/rho/rhoutils.rb in rhodes-1.4.2 vs lib/framework/rho/rhoutils.rb in rhodes-1.5.0

- old
+ new

@@ -39,7 +39,55 @@ Rhom::RhomDbAdapter.commit columns = [] end end + + def self.load_offline_data_ex(tables=[], dir_prefix=nil, commit_count=100000) + columns = [] + tables.each do |filename| + + Rhom::RhomDbAdapter.destroy_table(filename) + Rhom::RhomDbAdapter.start_transaction + + row_index=0 + prefix = dir_prefix.nil? ? "" : dir_prefix + query = "" + + File.open(File.join(Rho::RhoFSConnector.get_base_app_path,'app',prefix,'fixtures',filename+'.txt')).each do |line| + if row_index == 0 + columns = line.chomp.split('|') + quests = "" + columns.each do |col| + quests += ',' if quests.length() > 0 + quests += '?' + end + query = "insert into #{filename} (#{columns.join(',')}) values (#{quests})" + row_index += 1 + next + end + + parts = line.chomp.split('|') + + begin + Rhom::RhomDbAdapter.execute_sql query, parts + rescue Exception => e + #puts "load_offline_data : exception insert data: #{e}; data : #{parts}; line : #{row_index}" + end + + if row_index%commit_count == 0 + puts "commit start" + Rhom::RhomDbAdapter.commit + Rhom::RhomDbAdapter.start_transaction + puts "commit : #{row_index}" + end + + row_index += 1 + end + + Rhom::RhomDbAdapter.commit + puts "commit : #{row_index}" + columns = [] + end + end end end \ No newline at end of file