Permalink
Browse files

[37] Implemented option to specify custom table name

Signed-off-by: DoesntMatter <jaed1@gmx.net>
  • Loading branch information...
DoesntMatter committed Jan 23, 2012
1 parent a233c7d commit 9d54862c5609b8d4f02f9cfce5869529345e2ee0
Showing with 12 additions and 4 deletions.
  1. +2 −0 README
  2. +7 −3 libs/SQL.pm
  3. +3 −1 scripts/gitlog_to_sql.pl
View
2 README
@@ -51,5 +51,7 @@ Options:
Default: All commits
--outfile FILE Name and path of generated SQL file
Default: $PWD/log.sql
--table TABLE Preferred table name
Default: gitlog
--prompt Prompt for input and do not use options
--help Show this output
View
@@ -39,6 +39,8 @@ Options:
Default: All commits
--outfile FILE Name and path of generated SQL file
Default: \$PWD/log.sql
--table TABLE Preferred table name
Default: gitlog
--prompt Prompt for input and do not use options
--help Show this output
HELP
@@ -48,10 +50,11 @@ HELP
sub TableStruct {
my $file = shift || return undef;
my $table = shift || "gitlog";
open(FILE, ">$file");
print FILE "-- Create table structure
CREATE TABLE IF NOT EXISTS `gitlog` (
CREATE TABLE IF NOT EXISTS `$table` (
`hash` varchar(40) NOT NULL DEFAULT '' COMMENT 'Unique identifier of commit',
`date` varchar(40) NOT NULL DEFAULT '' COMMENT 'Time of commit',
`author` varchar(30) NOT NULL DEFAULT '' COMMENT 'Author of commit',
@@ -69,9 +72,10 @@ CREATE TABLE IF NOT EXISTS `gitlog` (
sub CreateSQL {
my $gitlog = shift || return undef;
my $file = shift || return undef;
my $table = shift || "gitlog";
my @items = Parser::SplitCommits($gitlog);
TableStruct($file);
TableStruct($file, $table);
open(FILE, ">>$file");
for my $i ( 0 .. $#items ) {
@@ -84,7 +88,7 @@ sub CreateSQL {
# $items[$i][6] Body
print FILE "
INSERT IGNORE INTO `gitlog` VALUES ('$items[$i][1]', '$items[$i][2]', '$items[$i][3]', '$items[$i][4]', '$items[$i][5]', '$items[$i][6]');";
INSERT IGNORE INTO `$table` VALUES ('$items[$i][1]', '$items[$i][2]', '$items[$i][3]', '$items[$i][4]', '$items[$i][5]', '$items[$i][6]');";
}
close(FILE);
View
@@ -41,6 +41,7 @@
"repo=s",
"count=i",
"outfile=s",
"table=s",
"prompt",
"help|?",
);
@@ -72,6 +73,7 @@
}
$options{'count'} = Generic::GetInput("Please enter count of commits: ");
$options{'outfile'} = Generic::GetInput("Please enter outfile path: ");
$options{'table'} = Generic::GetInput("Please enter preferred table name: ");
}
#
@@ -84,6 +86,6 @@
exit;
}
SQL::CreateSQL($gitlog, $options{'outfile'});
SQL::CreateSQL($gitlog, $options{'outfile'}, $options{'table'});
exit;

0 comments on commit 9d54862

Please sign in to comment.