[Bast-commits] r6632 - DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Thu Jun 11 18:02:06 GMT 2009


Author: jnapiorkowski
Date: 2009-06-11 18:02:06 +0000 (Thu, 11 Jun 2009)
New Revision: 6632

Modified:
   DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm
Log:
break out the code that splits a line into statements, and minor additional cleanup


Modified: DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm	2009-06-11 17:40:11 UTC (rev 6631)
+++ DBIx-Class/0.08/branches/run_file_against_storage/lib/DBIx/Class/Storage/DBI.pm	2009-06-11 18:02:06 UTC (rev 6632)
@@ -2055,10 +2055,6 @@
 
 sub _normalize_lines {
   my $self = shift @_;
-  my $deliminator=qr{;|.$};
-  my $quote=qr{['"]};
-  my $quoted=qr{$quote.+?$quote};
-  my $block=qr{$quoted|.};
   my $comment = qr{--};
   my @lines;
   foreach my $line (@_) {
@@ -2068,14 +2064,14 @@
       next;
     } else {
       ## a line may contain several commands
-      my @parts = ($line=~m/$block*?$deliminator/xg);
+      my @parts = $self->_split_line_into_statements($line);      
       ## clean empty or comment only lines
       @parts = grep { $_ && $_ !~m/^\s* $comment/x } @parts;
       ## We are going to wrap it all in a transaction anyway
       @parts = grep { $_ !~ /^(BEGIN|BEGIN TRANSACTION|COMMIT)/m } @parts;
       ## Some cleanup
       @parts = map {
-        $_=~s/$deliminator \s*?$comment.*?$//x; ## trim off ending comments        
+        $_=~s/;\s*?$comment.*?$//; ## trim off ending comments        
         $_=~s/^\s*//g; ## trim leading whitespace
         $_=~s/\s*$//g; ## trim ending whitespace
         $_;
@@ -2086,6 +2082,45 @@
   return @lines;
 }
 
+=head2 _split_line_into_statements
+
+  my @statements = $storage->_split_line_into_statements($line);
+
+=over
+
+=item Arguments: String
+
+=item Returns: Array of SQL Statements
+
+=back 
+
+Given a string, returns all the individual SQL statements in that String
+as an Array.
+
+my $maybe_quoted = qr/
+"[^"]+"
+|
+'[^']+'
+|
+.+?(?=$deliminator)
+/;
+
+my @parts = ($line=~m/$maybe_quoted*?$deliminator/g);
+
+=cut
+
+sub _split_line_into_statements {
+  my ($self, $line) = @_;
+  
+  my $deliminator=qr{;|$};
+  my $quote=qr{['"]};
+  my $quoted=qr{$quote.+?$quote};
+  my $block=qr{$quoted|.};
+  my @parts = ($line=~m/$block*?$deliminator/xg);
+
+  return @parts;
+}
+
 =head2 _normalize_statements_from_lines 
 
   my @statements = $storage->_normalize_statements_from_lines(@lines)




More information about the Bast-commits mailing list