-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-sql
executable file
·64 lines (56 loc) · 1.45 KB
/
create-sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
#==============================================================================
# create-sql
# File ID: ca78b0ea-9e90-11e6-98f9-e6436a218c69
#
# Convert repos.dat to SQL
#
# Author: Øyvind A. Holm <[email protected]>
# License: GNU General Public License version 2 or later.
#==============================================================================
use strict;
use warnings;
my $progname = "create-sql";
my $VERSION = "0.2.0";
exit(main());
sub main {
print(<<END);
BEGIN TRANSACTION;
CREATE TABLE repos (
date TEXT
CONSTRAINT repos_date_length
CHECK (length(date) = 19)
CONSTRAINT repos_date_valid
CHECK (datetime(date) IS NOT NULL)
UNIQUE,
bazaar INTEGER
NOT NULL,
cvs INTEGER
NOT NULL,
git INTEGER
NOT NULL,
mercurial INTEGER
NOT NULL,
subversion INTEGER
NOT NULL,
UNIQUE (bazaar, cvs, git, mercurial, subversion)
);
END
while (my $line = <>) {
if ($line =~ /^(20.*?)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)/) {
my ($date, $bzr, $cvs, $git, $hg, $svn) =
( $1, $2, $3, $4, $5, $6);
$date =~ s/T/ /;
$date =~ s/Z//;
printf("INSERT INTO repos " .
"(%s, %s, %s, %s, %s, %s) " .
"VALUES ('%s', %s, %s, %s, %s, %s);\n",
"date", "bazaar", "cvs",
"git", "mercurial", "subversion",
$date, $bzr, $cvs, $git, $hg, $svn);
}
}
print("COMMIT;\n");
return 0;
}
# vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :