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,29 +42,38 @@ sub connect_db($$$$$){
42 42
 sub to_mariadb($$){
43 43
     my ($export, $content) = @_;
44 44
     
45
-    connect_db(
45
+    my $dbh = connect_db(
46 46
 	"mysql",
47 47
         "$config->{'export'}->{$export}->{'connexion'}->{'base'}",
48 48
         "$config->{'export'}->{$export}->{'connexion'}->{'user'}",
49 49
         "$config->{'export'}->{$export}->{'connexion'}->{'password'}",
50 50
         "$config->{'export'}->{$export}->{'connexion'}->{'host'}"
51 51
      );
52
-    
52
+    print Dumper $config->{'export'}->{$export}->{'column_default'};
53 53
     my $columns_default = "";
54 54
     my $columns_default_value = "";
55 55
     
56
-    if( !"$config->{'export'}->{$export}->{'column_default'}" ){
56
+    if( exists($config->{'export'}->{$export}->{'column_default'}) ){
57 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 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 79
 sub to_file($$){
@@ -111,7 +120,7 @@ sub visit($$){
111 120
 
112 121
 sub isNew($$$){
113 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 124
     my $sth = $dbh->prepare("SELECT count(signature) AS COUNT FROM visit WHERE signature='$signature' AND url='$url';");
116 125
     #$sth->execute("$signature", "$url");
117 126
     $sth->execute();
@@ -191,11 +200,6 @@ sub main($$){
191 200
 
192 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 203
     open(FH, '<', $import_list) or die $!;
200 204
     while(<FH>){
201 205
 	my($url, $selector, $fromFormat, $toFormat, $export) = split("\t");

Loading…
Cancel
Save