1

将文件中的数据加载到数据库时出现此错误。请帮我解决这个问题。

这是方法:

clusters.each do |cluster|
        cluster_path = cluster.path
        root = current_root + cluster.name+'/'
        Log.info "<br/> --------- Starting data popuation for #{cluster_path} ---------------"

         population_time[:bp_data] = populate_bp_data(root+fileName[:bp_data], cluster_path, @dataset.id)
         population_time[:m_lint] = populate_m_lint(root+fileName[:m_lint], cluster_path, @dataset.id)
         population_time[:single_use] = populate_single_use(root+fileName[:single_use], cluster_path, @dataset.id)
         population_time[:test_points] = populate_test_points(root+fileName[:test_points], cluster_path, @dataset.id)
         population_time[:users] = populate_user(root+fileName[:users], cluster_path, @dataset.id)
         population_time[:test_times] = populate_test_times(root+fileName[:test_times], cluster_path, @dataset.id)
         population_time[:qeinbat] = populate_qeinbat_data(root+fileName[:qeinbat], cluster_path, @dataset.id)
         population_time[:clearall] = populate_clearall_data(root+fileName[:clearall], cluster_path, @dataset.id)
         population_time[:closeall] = populate_closeall_data(root+fileName[:closeall], cluster_path, @dataset.id)
         population_time[:clearclass] = populate_clearclass_data(root+fileName[:clearclass], cluster_path, @dataset.id)
         population_time[:clearmax] = populate_clearmax_data(root+fileName[:clearmax], cluster_path, @dataset.id)
         population_time[:pause] = populate_pause_data(root+fileName[:pause], cluster_path, @dataset.id)
         population_time[:num_of_test] = populate_num_of_test_data(root+fileName[:num_of_test], cluster_path, @dataset.id)
         population_time[:test_description] = populate_test_description(root+fileName[:test_description], cluster_path, @dataset.id)
         population_time[:component] = populate_components(root+fileName[:component], cluster.id, cluster_path, @dataset.id)


         population_time.each do |key, value|
         total_time += value
        end
     end

此处调用的每个填充方法都会获取文件并遍历其内容,并使用以下步骤将数据输入数据库:

CSV.foreach(fileName) do |line|
    completePath = line[0]                                                
    num_of_bps = line[1]

    completePath = cluster_path+ '/' + completePath
    inode = FileOrFolder.find_by_fullpath(completePath, :select=>"id") 

    metric_instance = MetricInstance.find(:first, :conditions=>["file_or_folder_id = ? AND dataset_id = ?", inode.id, dataset_id])
    add_entry(metric_instance.id, num_of_bps, num_of_bp_tests) 
end



def self.add_entry(metaid, num_of_bps, num_of_bp_tests)
    entry = Bp.new
    entry.metric_instance_id = metaid
    entry.num_of_bps = num_of_bps
    entry.num_of_bp_tests = num_of_bp_tests
    entry.save
    return entry
end
4

0 回答 0