[ruby-oci8-commit] [568] trunk/ruby-oci8: OCI8#describe_synonym and OCI8#describe_any accept ' PUBLIC.XXX' as a public synonym name.

nobody at rubyforge.org nobody at rubyforge.org
Sun Jun 23 09:24:52 UTC 2013


Revision: 568
Author:   kubo
Date:     2013-06-23 09:24:51 +0000 (Sun, 23 Jun 2013)
Log Message:
-----------
OCI8#describe_synonym and OCI8#describe_any accept 'PUBLIC.XXX' as a public synonym name.
Add tests for OCI8#describe_synonym.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/lib/oci8/metadata.rb
    trunk/ruby-oci8/test/test_metadata.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2013-06-11 02:36:35 UTC (rev 567)
+++ trunk/ruby-oci8/ChangeLog	2013-06-23 09:24:51 UTC (rev 568)
@@ -1,3 +1,8 @@
+2013-06-23  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8/metadata.rb: OCI8#describe_synonym and OCI8#describe_any
+	    accept 'PUBLIC.XXX' as a public synonym name.
+	* test/test_metadata.rb: add tests for OCI8#describe_synonym.
+
 2013-06-11  KUBO Takehiro  <kubo at jiubao.org>
 	* ruby-oci8.gemspec: fix ruby version checking in binary gem.
 	    Gem::ruby_version of ruby 2.0.0p195 is 2.0.0.195, which

Modified: trunk/ruby-oci8/lib/oci8/metadata.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/metadata.rb	2013-06-11 02:36:35 UTC (rev 567)
+++ trunk/ruby-oci8/lib/oci8/metadata.rb	2013-06-23 09:24:51 UTC (rev 568)
@@ -1994,7 +1994,13 @@
   # @param [String] object_name
   # @return [a subclass of OCI8::Metadata::Base]
   def describe_any(object_name)
-    __describe(object_name, OCI8::Metadata::Unknown, true)
+    if /^PUBLIC\.(.*)/i =~ object_name
+      md = __describe($1, OCI8::Metadata::Unknown, true)
+      raise OCIError.new(4043, object_name) if md.obj_schema != 'PUBLIC'
+      md
+    else
+      __describe(object_name, OCI8::Metadata::Unknown, true)
+    end
   end
   # Returns table or view information. If the name is a current schema's synonym
   # name or a public synonym name, it returns table or view information which
@@ -2066,7 +2072,13 @@
   # @param [String] synonym_name
   # @return [OCI8::Metadata::Synonym]
   def describe_synonym(synonym_name, check_public_also = true)
-    __describe(synonym_name, OCI8::Metadata::Synonym, check_public_also)
+    if /^PUBLIC\.(.*)/i =~ synonym_name
+      md = __describe($1, OCI8::Metadata::Synonym, true)
+      raise OCIError.new(4043, synonym_name) if md.obj_schema != 'PUBLIC'
+      md
+    else
+      __describe(synonym_name, OCI8::Metadata::Synonym, check_public_also)
+    end
   end
   # Returns sequence information
   #

Modified: trunk/ruby-oci8/test/test_metadata.rb
===================================================================
--- trunk/ruby-oci8/test/test_metadata.rb	2013-06-11 02:36:35 UTC (rev 567)
+++ trunk/ruby-oci8/test/test_metadata.rb	2013-06-23 09:24:51 UTC (rev 568)
@@ -1482,4 +1482,49 @@
     @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
   end
 
+  def test_synonym_metadata
+    begin
+      @conn.exec("DROP SYNONYM test_synonym")
+    rescue OCIError
+      raise if $!.code != 1434 # ORA-01434: private synonym to be dropped does not exist
+    end
+
+    # private synonym
+    begin
+      @conn.exec("CREATE SYNONYM test_synonym FOR foo.bar at baz.quz")
+      [
+       @conn.describe_any('test_synonym'),
+       @conn.describe_synonym('Test_Synonym'),
+       @conn.describe_any(@conn.username + '.test_synonym'),
+       @conn.describe_synonym(@conn.username + '.Test_Synonym'),
+      ].each do |desc|
+        assert_equal(@conn.username, desc.obj_schema)
+        assert_equal('TEST_SYNONYM', desc.obj_name)
+        assert_equal('FOO', desc.schema_name)
+        assert_equal('BAR', desc.name)
+        assert_equal('BAZ.QUZ', desc.link)
+        assert_equal('FOO.BAR at BAZ.QUZ', desc.translated_name)
+      end
+      @conn.exec("DROP SYNONYM test_synonym")
+    rescue OCIError
+      raise if $!.code != 1031 # ORA-01031: insufficient privileges
+    end
+
+    # public synonym
+    [
+     @conn.describe_any('sdo_geometry'),
+     @conn.describe_synonym('sdo_geometry'),
+     @conn.describe_any('public.sdo_geometry'),
+     @conn.describe_synonym('PUBLIC.sdo_geometry'),
+    ].each do |desc|
+      assert_equal('PUBLIC', desc.obj_schema)
+      assert_equal('SDO_GEOMETRY', desc.obj_name)
+      assert_equal('MDSYS', desc.schema_name)
+      assert_equal('SDO_GEOMETRY', desc.name)
+      assert_equal(nil, desc.link)
+      assert_equal('MDSYS.SDO_GEOMETRY', desc.translated_name)
+    end
+
+  end
+
 end # TestMetadata



More information about the ruby-oci8-commit mailing list