1 #!/usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use File::Basename;
6 use DBI;
7
8 my $bin_dir = dirname($0);
9 my $project = shift;
10 my $db_file = shift;
11 if (!defined($db_file)) {
12 print "usage: $0 <project> <db_file>\n";
13 exit(1);
14 }
15 my $insertions = "$bin_dir/$project.insert.return_states";
16
17 my $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
24 sub 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
57 my ($ret, $insert, $file, $func, $type, $param, $key, $value);
58
59 open(FILE, "<$insertions");
60 while (<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 }
90 close(FILE);
91
92 $db->commit();
93 $db->disconnect();