Permalink
Browse files

fixed symbol split regexp. it don't match include '__' (also '___').

  • Loading branch information...
1 parent 3f26802 commit 51ffd3c65ebc10603c498cd1206f6ee6796787b2 @authorNari authorNari committed Feb 23, 2011
Showing with 23 additions and 10 deletions.
  1. +6 −6 lib/sequel/dataset/sql.rb
  2. +17 −4 spec/core/dataset_spec.rb
View
@@ -177,9 +177,9 @@ def self.clause_methods(type, clauses)
BOOL_FALSE = "'f'".freeze
BOOL_TRUE = "'t'".freeze
COMMA_SEPARATOR = ', '.freeze
- COLUMN_REF_RE1 = /\A([\w ]+)__([\w ]+)___([\w ]+)\z/.freeze
- COLUMN_REF_RE2 = /\A([\w ]+)___([\w ]+)\z/.freeze
- COLUMN_REF_RE3 = /\A([\w ]+)__([\w ]+)\z/.freeze
+ COLUMN_REF_RE1 = /\A(((?!__).)+)__(((?!___).)+)___(.+)\z/.freeze
+ COLUMN_REF_RE2 = /\A(((?!___).)+)___(.+)\z/.freeze
+ COLUMN_REF_RE3 = /\A(((?!__).)+)__(.+)\z/.freeze
COUNT_FROM_SELF_OPTS = [:distinct, :group, :sql, :limit, :compounds]
COUNT_OF_ALL_AS_COUNT = SQL::Function.new(:count, LiteralString.new('*'.freeze)).as(:count)
DATASET_ALIAS_BASE_NAME = 't'.freeze
@@ -934,11 +934,11 @@ def source_list(source)
def split_symbol(sym)
s = sym.to_s
if m = COLUMN_REF_RE1.match(s)
- m[1..3]
+ [m[1], m[3], m[5]]
elsif m = COLUMN_REF_RE2.match(s)
- [nil, m[1], m[2]]
+ [nil, m[1], m[3]]
elsif m = COLUMN_REF_RE3.match(s)
- [m[1], m[2], nil]
+ [m[1], m[3], nil]
else
[nil, s, nil]
end
View
@@ -927,22 +927,23 @@ def d1.fetch_rows(sql)
@dataset.literal(1).should == "1"
@dataset.literal(1.5).should == "1.5"
end
-
+
specify "should literalize nil as NULL" do
@dataset.literal(nil).should == "NULL"
end
-
+
specify "should literalize an array properly" do
@dataset.literal([]).should == "(NULL)"
@dataset.literal([1, 'abc', 3]).should == "(1, 'abc', 3)"
@dataset.literal([1, "a'b''c", 3]).should == "(1, 'a''b''''c', 3)"
end
-
+
specify "should literalize symbols as column references" do
@dataset.literal(:name).should == "name"
@dataset.literal(:items__name).should == "items.name"
+ @dataset.literal(:"items__na#m$e").should == "items.na#m$e"
end
-
+
specify "should call sql_literal with dataset on type if not natively supported and the object responds to it" do
@a = Class.new do
def sql_literal(ds)
@@ -1114,10 +1115,22 @@ def d.to_s; "adsf" end
specify "should accept :schema__table___alias symbol format" do
@dataset.from(:abc__def).select_sql.should ==
"SELECT * FROM abc.def"
+ @dataset.from(:a_b__c).select_sql.should ==
+ "SELECT * FROM a_b.c"
+ @dataset.from(:'#__#').select_sql.should ==
+ 'SELECT * FROM #.#'
@dataset.from(:abc__def___d).select_sql.should ==
"SELECT * FROM abc.def AS d"
+ @dataset.from(:a_b__d_e___f_g).select_sql.should ==
+ "SELECT * FROM a_b.d_e AS f_g"
+ @dataset.from(:'#__#___#').select_sql.should ==
+ 'SELECT * FROM #.# AS #'
@dataset.from(:abc___def).select_sql.should ==
"SELECT * FROM abc AS def"
+ @dataset.from(:a_b___c_d).select_sql.should ==
+ "SELECT * FROM a_b AS c_d"
+ @dataset.from(:'#___#').select_sql.should ==
+ 'SELECT * FROM # AS #'
end
end

0 comments on commit 51ffd3c

Please sign in to comment.