Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix Dataset#split_symbol. Next try :) #23

Closed
wants to merge 2 commits into from

2 participants

@authorNari

#22

Please check it.

@jeremyevans
Owner

Can you rebase your commits so that there is only one to apply?

I'll take a look at this tomorrow. It looks more likely to work, so unless there is a noticeable performance difference, if it passes the test suites it will get merged.

@jeremyevans
Owner

Committed the rebased patch. Thanks!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 10 deletions.
  1. +6 −6 lib/sequel/dataset/sql.rb
  2. +17 −4 spec/core/dataset_spec.rb
View
12 lib/sequel/dataset/sql.rb
@@ -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
21 spec/core/dataset_spec.rb
@@ -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
Something went wrong with that request. Please try again.