/
c3mc-base-db-ins
executable file
·46 lines (35 loc) · 1.06 KB
/
c3mc-base-db-ins
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
#!/data/Software/mydan/perl/bin/perl -I/data/Software/mydan/Connector/lib
use strict;
use warnings;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
$|++;
use MYDB;
use MYDan::Util::OptConf;
use YAML::XS;
use Encode;
=head1 SYNOPSIS
$0 --table foo k1 v1 k2 v2 .. kn vn
=cut
my $option = MYDan::Util::OptConf->load();
my %o = $option->get( qw( table=s ) )->dump();
$option->assert('table');
$option->assert() unless @ARGV;
my %col = @ARGV;
my @col = sort keys %col;
my $module = ( split /_/, $o{table} )[1];
my %table = (
ci => 'CI',
job => 'JOB',
jobx => 'JOBX',
agent => 'AGENT',
connector => 'Connector',
monitor => 'AGENT',
device => 'AGENT',
tt => 'Connector',
);
die "table $o{table} undef" unless $module && $table{$module};
my $db = MYDB->new( "/data/Software/mydan/$table{$module}/conf/conn" );
eval{ $db->execute( sprintf "replace into $o{table} ( %s ) values( %s )", join( ',', map{"`$_`"}@col), join( ',', map{"'$col{$_}'"}@col ) );};
die "replace database fail: $@" if $@;