sqlstmt 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 171563e5033c5838b9c8a2055d841b0ab97a7b59
4
- data.tar.gz: 6aab01e8dc7fd4ace0d64d4f5514036cc605ba9d
3
+ metadata.gz: eea31417385f00ff44f3de6c5b3f4189dee5fc1a
4
+ data.tar.gz: 75f4bc36ea768d7adc4c22257edc46507d00928d
5
5
  SHA512:
6
- metadata.gz: 0adcff0c4693dc8c2cbebfe74b3e88a47db21c943dce993e970bb6792cb74f1ba200133f955812872b673085f2ead5e886f9db1bb7413efaa09e8d47f618faba
7
- data.tar.gz: 13c6f5d0b69919ff840cebf92aaf35c0603c7a59ad8430a0cdd81485416986d2a70f6c98c74e83cf8971fbf2b940dc93215ced7a81e1341c7a2ca8619f18ba7b
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
- return true if @tables.include?(table_to_find)
71
- @joins.find do |_, table, _|
72
- table_to_find == table
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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlstmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makani Mason