sqlstmt 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sqlstmt/query.rb +11 -4
- data/test/select.dt.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eea31417385f00ff44f3de6c5b3f4189dee5fc1a
|
4
|
+
data.tar.gz: 75f4bc36ea768d7adc4c22257edc46507d00928d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c88c7be9a31bd556031b6caa3ea35f06f7f7f0d1b0056dad45b92bd2154a047b6ce511c94a95597916d49033db714b8108e5bdf43d05614c74b7f1f3d90f6d2
|
7
|
+
data.tar.gz: 7ce5bfee85d705899e425970d9824885ca8007b7b3fba31c9f3f2dd240bce4e4bb3e5449a0a2e0e84af8cce0274e2fbaeccd35755f24bef7a084aaa718151224
|
data/lib/sqlstmt/query.rb
CHANGED
@@ -67,13 +67,20 @@ class Query
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def includes_table?(table_to_find)
|
70
|
-
|
71
|
-
@joins.find
|
72
|
-
|
73
|
-
end
|
70
|
+
retval = @tables.find { |table| table_names_match?(table, table_to_find) }
|
71
|
+
retval ||= @joins.find { |_, table, _| table_names_match?(table, table_to_find) }
|
72
|
+
retval
|
74
73
|
end
|
75
74
|
|
76
75
|
private
|
76
|
+
def table_names_match?(fullstr, tofind)
|
77
|
+
if tofind.index(' ') || !fullstr.index(' ')
|
78
|
+
return fullstr == tofind
|
79
|
+
end
|
80
|
+
orig_name, _, tblas = fullstr.partition(' ')
|
81
|
+
(orig_name == tofind) || (tblas == tofind)
|
82
|
+
end
|
83
|
+
|
77
84
|
def verify_minimum_requirements
|
78
85
|
if (@where_behavior == :require) && @wheres.empty?
|
79
86
|
raise SqlStmt::Error, "unable to build sql - must call :where, :no_where, or :optional_where"
|
data/test/select.dt.rb
CHANGED
@@ -3,6 +3,13 @@ require 'sqlstmt/select'
|
|
3
3
|
module SqlStmt
|
4
4
|
|
5
5
|
class TestSelect < DohTest::TestGroup
|
6
|
+
def test_includes_table
|
7
|
+
sqlb = Select.new.table('target t')
|
8
|
+
assert(sqlb.includes_table?('target'))
|
9
|
+
assert(sqlb.includes_table?('t'))
|
10
|
+
assert(!sqlb.includes_table?('blah'))
|
11
|
+
end
|
12
|
+
|
6
13
|
def test_minimum_requirements
|
7
14
|
assert_raises(SqlStmt::Error) { Select.new.table('target').to_s }
|
8
15
|
assert_raises(SqlStmt::Error) { Select.new.table('target').no_where.to_s }
|