db/create_db.sh: don't complain when -p=<project> is left blank
[smatch.git] / smatch_data / db / init_constraints_required.pl
blob15ce19b2c24b5e6daf4a4181cfe0247186498f5a
1 #!/usr/bin/perl -w
3 use strict;
4 use warnings;
5 use bigint;
6 use DBI;
7 use Data::Dumper;
8 use File::Basename;
10 my $project = shift;
11 $project =~ s/.*=(.*)/$1/;
12 my $warns = shift;
13 my $db_file = shift;
15 my $db;
17 sub connect_to_db($)
19 my $name = shift;
21 $db = DBI->connect("dbi:SQLite:$name", "", "", {AutoCommit => 0});
23 $db->do("PRAGMA cache_size = 800000");
24 $db->do("PRAGMA journal_mode = OFF");
25 $db->do("PRAGMA count_changes = OFF");
26 $db->do("PRAGMA temp_store = MEMORY");
27 $db->do("PRAGMA locking = EXCLUSIVE");
30 sub load_manual_constraints($$)
32 my $full_path = shift;
33 my $project = shift;
34 my $dir = dirname($full_path);
35 my ($data, $op, $limit);
37 if ($project =~ /^$/) {
38 return;
41 open(FILE, "$dir/$project.constraints_required");
42 while (<FILE>) {
43 ($data, $op, $limit) = split(/,/);
44 $op =~ s/ //g;
45 $limit =~ s/^ +//;
46 $limit =~ s/\n//;
47 $db->do("insert into constraints_required values (?, ?, ?);", undef, $data, $op, $limit);
49 close(FILE);
51 $db->commit();
54 connect_to_db($db_file);
55 load_manual_constraints($0, $project);
57 $db->commit();
58 $db->disconnect();