1#!/usr/bin/perl -w 2 3use strict; 4use warnings; 5use File::Basename; 6use DBI; 7 8my $bin_dir = dirname($0); 9my $project = shift; 10my $db_file = shift; 11if (!defined($db_file)) { 12 print "usage: $0 <project> <db_file>\n"; 13 exit(1); 14} 15my $insertions = "$bin_dir/$project.insert.return_states"; 16 17my $db = DBI->connect("dbi:SQLite:$db_file", "", "", {AutoCommit => 0}); 18$db->do("PRAGMA cache_size = 800000"); 19$db->do("PRAGMA journal_mode = OFF"); 20$db->do("PRAGMA count_changes = OFF"); 21$db->do("PRAGMA temp_store = MEMORY"); 22$db->do("PRAGMA locking = EXCLUSIVE"); 23 24sub insert_record($$$$$$$) 25{ 26 my $file = shift; 27 my $func = shift; 28 my $ret = shift; 29 my $type = shift; 30 my $param = shift; 31 my $key = shift; 32 my $value = shift; 33 34# print "file = '$file' func = '$func' ret = $ret\n"; 35# print "type = $type param = $param, key = $key, value = '$value'\n"; 36# print "select file, return_id, return, static from return_states where function = '$func' and return = '$ret' and type = 0;'\n"; 37 38 my $sth; 39 if ($file ne '') { 40 $sth = $db->prepare("select file, return_id, static from return_states where file = ? and function = ? and return = ? and type = 0;"); 41 $sth->execute($file, $func, $ret); 42 } else { 43 $sth = $db->prepare("select file, return_id, static from return_states where function = ? and return = ? and type = 0;"); 44 $sth->execute($func, $ret); 45 } 46 47 my $insert = $db->prepare("insert into return_states values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); 48 while (my @row = $sth->fetchrow_array()) { 49 my $file = $row[0]; 50 my $return_id = $row[1]; 51 my $static = $row[2]; 52 53 $insert->execute($file, $func, 0, $return_id, $ret, $static, $type, $param, $key, $value); 54 } 55} 56 57my ($ret, $insert, $file, $func, $type, $param, $key, $value); 58 59open(FILE, "<$insertions"); 60while (<FILE>) { 61 62 if ($_ =~ /^\s*#/) { 63 next; 64 } 65 66 ($ret, $insert) = split(/\|/, $_); 67 68 if ($ret =~ /(.+),\W*(.+),\W*"(.*)"/) { 69 $file = $1; 70 $func = $2; 71 $ret = $3; 72 } elsif ($ret =~ /(.+),\W*"(.*)"/) { 73 $file = ""; 74 $func = $1; 75 $ret = $2; 76 } else { 77 next; 78 } 79 80 ($type, $param, $key, $value) = split(/,/, $insert); 81 82 $type = int($type); 83 $param = int($param); 84 $key =~ s/^["\s]+|["\s]+$//g; 85 $value =~ s/^["\s]+|["\s]+$//g; 86 chomp($value); 87 88 insert_record($file, $func, $ret, $type, $param, $key, $value); 89} 90close(FILE); 91 92$db->commit(); 93$db->disconnect(); 94