Browse Source

add default column and value for inserting in mariadb

nas 3 years ago
parent
commit
872f494f94
1 changed files with 20 additions and 16 deletions
  1. 20
    16
      syncWeb.pl

+ 20
- 16
syncWeb.pl View File

42
 sub to_mariadb($$){
42
 sub to_mariadb($$){
43
     my ($export, $content) = @_;
43
     my ($export, $content) = @_;
44
     
44
     
45
-    connect_db(
45
+    my $dbh = connect_db(
46
 	"mysql",
46
 	"mysql",
47
         "$config->{'export'}->{$export}->{'connexion'}->{'base'}",
47
         "$config->{'export'}->{$export}->{'connexion'}->{'base'}",
48
         "$config->{'export'}->{$export}->{'connexion'}->{'user'}",
48
         "$config->{'export'}->{$export}->{'connexion'}->{'user'}",
49
         "$config->{'export'}->{$export}->{'connexion'}->{'password'}",
49
         "$config->{'export'}->{$export}->{'connexion'}->{'password'}",
50
         "$config->{'export'}->{$export}->{'connexion'}->{'host'}"
50
         "$config->{'export'}->{$export}->{'connexion'}->{'host'}"
51
      );
51
      );
52
-    
52
+    print Dumper $config->{'export'}->{$export}->{'column_default'};
53
     my $columns_default = "";
53
     my $columns_default = "";
54
     my $columns_default_value = "";
54
     my $columns_default_value = "";
55
     
55
     
56
-    if( !"$config->{'export'}->{$export}->{'column_default'}" ){
56
+    if( exists($config->{'export'}->{$export}->{'column_default'}) ){
57
 	$columns_default = "";
57
 	$columns_default = "";
58
-	#for each...
58
+
59
+	foreach my $column ( keys %{$config->{'export'}->{$export}->{'column_default'}} ){
60
+
61
+	    $columns_default .= ", $column";
62
+	    print "\n- deal with $column\n";
63
+	    $columns_default_value .= ", \"$config->{'export'}->{$export}->{'column_default'}->{$column}\"";
64
+	}
59
     }
65
     }
60
-    
61
-    print "INSERT INTO $config->{'export'}->{$export}->{'content'}->{'table'} (
62
-        $config->{'export'}->{$export}->{'content'}->{'column'}
63
-        $columns_default
66
+
67
+    my $sql = "INSERT INTO $config->{'export'}->{$export}->{'content'}->{'table'} (
68
+        $config->{'export'}->{$export}->{'content'}->{'column'} $columns_default
64
     )
69
     )
65
     VALUES ('$content' $columns_default_value);";
70
     VALUES ('$content' $columns_default_value);";
66
-
67
-    # close db here
71
+    print $sql;
72
+    exit;
73
+    my $sth = $dbh->prepare( $sql );
74
+    $sth->execute();
75
+    
76
+    $dbh->disconnect();
68
 }
77
 }
69
 
78
 
70
 sub to_file($$){
79
 sub to_file($$){
111
 
120
 
112
 sub isNew($$$){
121
 sub isNew($$$){
113
     my($url, $signature, $dbh) = @_;
122
     my($url, $signature, $dbh) = @_;
114
-    # my $sth = $dbh->prepare("SELECT count(signature) AS COUNT FROM visit WHERE signature=?1 AND url=?2;");
123
+
115
     my $sth = $dbh->prepare("SELECT count(signature) AS COUNT FROM visit WHERE signature='$signature' AND url='$url';");
124
     my $sth = $dbh->prepare("SELECT count(signature) AS COUNT FROM visit WHERE signature='$signature' AND url='$url';");
116
     #$sth->execute("$signature", "$url");
125
     #$sth->execute("$signature", "$url");
117
     $sth->execute();
126
     $sth->execute();
191
 
200
 
192
     $config=do("./$export");
201
     $config=do("./$export");
193
 
202
 
194
-    #$content = print encode 'unicode-escape',;
195
-    my $test = 'la""la';
196
-    print "+";
197
-    print String::Escape::backslash( $test );
198
-    print "\n";
199
     open(FH, '<', $import_list) or die $!;
203
     open(FH, '<', $import_list) or die $!;
200
     while(<FH>){
204
     while(<FH>){
201
 	my($url, $selector, $fromFormat, $toFormat, $export) = split("\t");
205
 	my($url, $selector, $fromFormat, $toFormat, $export) = split("\t");

Loading…
Cancel
Save