sequel_oracle_extensions 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -41,19 +41,37 @@ ORDER BY status DESC, constraint_name, cc.position
41
41
  ixs
42
42
  end
43
43
 
44
- # Returns the primary key for the given table.
45
- def primary_key(table)
46
- m = output_identifier_meth
47
- table = m[table]
48
- pks = Hash.new{|h,k| h[k] = {:table_name=>table, :columns=>[]}}
49
- metadata_dataset.with_sql(SELECT_PRIMARY_KEY_SQL, table.to_s.upcase).each do |r|
44
+ # Returns the primary key for the given table, as a hash.
45
+ #
46
+ # * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
47
+ # looks for all matching keys.
48
+ # * <tt>:all</tt> - Returns all matching keys. By default, returns the first matching key - provided
49
+ # that either there is only one key or that only the key is enabled.
50
+ # * <tt>:first</tt> - Returns the first matching key.
51
+ def primary_key(table, options={})
52
+ sql, m = SELECT_PRIMARY_KEY_SQL, output_identifier_meth
53
+ table, pks = m[table], []
54
+ pkh = Hash.new{|h,k| pks.push(h[k]=v={:table_name=>table, :columns=>[]}); v }
55
+
56
+ unless (z = options[:enabled]).nil?
57
+ sql = sql.sub /WHERE /, "WHERE c.status = #{z ? 'ENABLED' : 'DISABLED'}"
58
+ end
59
+
60
+ metadata_dataset.with_sql(sql, table.to_s.upcase).each do |r|
61
+ if options[:first] && pks.length==1 && r[:constraint_name] != pks[:constraint_name]
62
+ return pks.first
63
+ end
64
+
50
65
  r = Hash[ r.map{|k,v| [k, (k==:status || v.nil? || v=='') ? v : m[v]]} ]
51
- pk = pks[m.call r.delete(:constraint_name)]
66
+ pk = pkh[m.call r[:constraint_name]]
52
67
  pk[:enabled] = r.delete(:status)=='ENABLED'
53
68
  pk[:columns] << r.delete(:column_name)
54
69
  pk.update r
55
70
  end
56
- return pks.first.last if pks.size <= 1 or pks[0][:enabled] == pks[1][:enabled]
71
+
72
+ unless options[:all] or (pks.length>1 and pks[0][:enabled] != pks[1][:enabled])
73
+ return pks.first
74
+ end
57
75
  pks
58
76
  end
59
77
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sequel_oracle_extensions}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Khoobyar"]
12
- s.date = %q{2010-05-24}
12
+ s.date = %q{2010-05-27}
13
13
  s.description = %q{Oracle extensions for Sequel, including MERGE statements, optimizer hints, and schema extensions.}
14
14
  s.email = %q{joe@ankhcraft.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Khoobyar
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-24 00:00:00 -04:00
17
+ date: 2010-05-27 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency