From dc9639b640fe536e75e372d05a7af35b86cb87f2 Mon Sep 17 00:00:00 2001
From: Jonas Kramer <jkramer@nex.scrapping.cc>
Date: Fri, 10 Apr 2009 12:11:06 +0200
Subject: [PATCH] Name quote and separator fix.
---
lib/SQL/Tokenizer.pm | 5 ++++-
t/11-name-sep.t | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletions(-)
create mode 100644 t/11-name-sep.t
diff --git a/lib/SQL/Tokenizer.pm b/lib/SQL/Tokenizer.pm
index 7d5b1c8..6e8b158 100644
--- a/lib/SQL/Tokenizer.pm
+++ b/lib/SQL/Tokenizer.pm
@@ -20,7 +20,7 @@ my $re= qr{
(?:<>|<=>|>=|<=|==|=|!=|!|<<|>>|<|>|\|\||\||&&|&|-|\+|\*(?!/)|/(?!\*)|\%|~|\^|\?)
# operators and tests
|
- [\[\]\(\),;] # punctuation (parenthesis, comma)
+ [\[\]\(\),;.] # punctuation (parenthesis, comma)
|
\'\'(?!\') # empty single quoted string
|
@@ -28,6 +28,9 @@ my $re= qr{
|
".*?(?:(?:""){1,}"|(?<!["\\])"(?!")|\\"{2})
# anything inside double quotes, ungreedy
+ |
+ `.*?(?:(?:``){1,}`|(?<![`\\])`(?!`)|\\`{2})
+ # anything inside backticks quotes, ungreedy
|
'.*?(?:(?:''){1,}'|(?<!['\\])'(?!')|\\'{2})
# anything inside single quotes, ungreedy.
diff --git a/t/11-name-sep.t b/t/11-name-sep.t
new file mode 100644
index 0000000..9964f8f
--- /dev/null
+++ b/t/11-name-sep.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use SQL::Tokenizer;
+
+use constant SPACE => ' ';
+use constant COMMA => ',';
+use constant NL => "\n";
+
+my $query;
+my @query;
+my @tokenized;
+
+my @tests = (
+ {
+ description => q{PostgreSQL style},
+ query => qq{SELECT "foo"."bar"},
+ wanted => [ 'SELECT', SPACE, '"foo"', '.', '"bar"' ],
+ }, {
+ description => q{MySQL style},
+ query => qq{SELECT `foo`.`bar`},
+ wanted => [ 'SELECT', SPACE, '`foo`', '.', '`bar`' ],
+ }
+
+);
+
+plan tests => scalar @tests;
+
+foreach my $test (@tests) {
+ my @tokenized= SQL::Tokenizer->tokenize( $test->{query} );
+ is_deeply( \@tokenized, $test->{wanted}, $test->{description} );
+}
+
+__END__
+
--
1.6.2.1