Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / DBUpgrade2.pm
index dfd5536..a39ef93 100644 (file)
@@ -74,7 +74,7 @@ sub parse_dbupdate_controls {
 
     next if ($control->{ignore});
 
-    $control->{charset} ||= Common::DEFAULT_CHARSET;
+    $control->{charset} = $control->{charset} || $control->{encoding} || Common::DEFAULT_CHARSET;
 
     if (!$control->{"tag"}) {
       _control_error($form, $file_name, $locale->text("Missing 'tag' field.")) ;
@@ -136,7 +136,7 @@ sub process_query {
   my $file_charset = Common::DEFAULT_CHARSET;
   while (<$fh>) {
     last if !/^--/;
-    next if !/^--\s*\@charset:\s*(.+)/;
+    next if !/^--\s*\@(?:charset|encoding):\s*(.+)/;
     $file_charset = $1;
     last;
   }
@@ -162,13 +162,25 @@ sub process_query {
       if (@quote_chars) {
         if ($char eq $quote_chars[-1]) {
           pop(@quote_chars);
+        } elsif (length $quote_chars[-1] > 1
+             &&  substr($_, $i, length $quote_chars[-1]) eq $quote_chars[-1]) {
+          $i   += length $quote_chars[-1] - 1;
+          $char = $quote_chars[-1];
+          pop(@quote_chars);
         }
         $query .= $char;
 
       } else {
+        my ($tag, $tag_end);
         if (($char eq "'") || ($char eq "\"")) {
           push(@quote_chars, $char);
 
+        } elsif ($char eq '$'                                            # start of dollar quoting
+             && ($tag_end  = index($_, '$', $i + 1)) > -1                # ends on same line
+             && (do { $tag = substr($_, $i + 1, $tag_end - $i - 1); 1 }) # extract tag
+             &&  $tag      =~ /^ (?= [A-Za-z_] [A-Za-z0-9_]* | ) $/x) {  # tag is identifier
+          push @quote_chars, $char = '$' . $tag . '$';
+          $i = $tag_end;
         } elsif ($char eq ";") {
 
           # Query is complete. Send it.
@@ -233,7 +245,7 @@ sub process_perl_script {
   } else {
     while (<$fh>) {
       last if !/^--/;
-      next if !/^--\s*\@charset:\s*(.+)/;
+      next if !/^--\s*\@(?:charset|encoding):\s*(.+)/;
       $file_charset = $1;
       last;
     }
@@ -547,8 +559,10 @@ depends on. All other upgrades listed in C<depends> will be applied
 before the current one is applied.
 
 =item charset
+=item encoding
 
-The charset this file uses. Defaults to C<ISO-8859-15> if missing.
+The charset this file uses. Defaults to C<ISO-8859-15> if
+missing. Both terms are recognized.
 
 =item priority