On Monday, March 14, 2016 at 6:43:43 AM UTC-7, Ilja Resch wrote:
>
> Hi,
>
> After connect to my oracle database I have to switch the schema:
> url = "jdbc:oracle:thin:#{ user}/#{ password}@#{ host}:#{
> port}/#{service_name}"
>
> opts = { after_connect: proc{|conn| conn.createStatement.execute("ALTER
> SESSION SET CURRENT_SCHEMA =#{schema}")} }
> DB = Sequel.connect(url, opts)
> DB.autosequence = true
>
>
> This works fine in all cases, when autosequence is not needed. But after
> an insert I get following exception:
>
>
> Sequel::Error: schema parsing returned no columns, table probably doesnt
> exist
> schema at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-
> 4.32.0/lib/sequel/database/query.rb:162
> sequence_for_table at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/
> gems/sequel-4.32.0/lib/sequel/adapters/shared/oracle.rb:224
> fetch at org/jruby/RubyHash.java:1181
> sequence_for_table at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/
> gems/sequel-4.32.0/lib/sequel/adapters/shared/oracle.rb:221
> last_insert_id at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/
> sequel-4.32.0/lib/sequel/adapters/jdbc/oracle.rb:68
> execute at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-
> 4.32.0/lib/sequel/adapters/jdbc.rb:260
> statement at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-
> 4.32.0/lib/sequel/adapters/jdbc.rb:675
> execute at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-
> 4.32.0/lib/sequel/adapters/jdbc.rb:248
> hold at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-4.32.
> 0/lib/sequel/connection_pool/threaded.rb:105
> synchronize at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/
> sequel-4.32.0/lib/sequel/database/connecting.rb:256
> execute at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-
> 4.32.0/lib/sequel/adapters/jdbc.rb:247
> execute_insert at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/
> sequel-4.32.0/lib/sequel/adapters/jdbc.rb:283
> execute_insert at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/
> sequel-4.32.0/lib/sequel/dataset/actions.rb:968
> execute_insert at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/
> sequel-4.32.0/lib/sequel/adapters/shared/oracle.rb:500
> insert at C:/oracle-insert-test/jruby/lib/ruby/gems/shared/gems/sequel-
> 4.32.0/lib/sequel/dataset/actions.rb:338
> (root) at super.rb:15
>
>
> The Exception is thrown because the function *schema_parse_table_skip?(h,
> schema)* in *sequel/adapters/jdbc/oracle.rb:102* does not have any schema
> and the current_user is not the schema-owner.
>
> I removed this function with an extension and inserts seem to work. I
> would like to understand why this check is needed. And how this problem
> could be solved in a “good” way.
>
> Thanks!
>
If you set autosequence = true, it means the Database object attempts to
guess the sequence. In this case, it can't guess correctly as it can't
figure out the primary key column, which is used to determine the sequence
name. The easiest fix is for you to set the sequence manually:
DB[:table].sequence(:seq_table_id).insert(...)
It is possible to work around the schema parsing issue, but I'm not sure if
it is a good idea as it will hide errors like this. Here's a diff that
does that, though I don't think I want to use it:
diff --git a/lib/sequel/adapters/shared/oracle.rb
b/lib/sequel/adapters/shared/oracle.rb
index 4a90621..178ff25 100644
--- a/lib/sequel/adapters/shared/oracle.rb
+++ b/lib/sequel/adapters/shared/oracle.rb
@@ -219,7 +219,13 @@ module Sequel
def sequence_for_table(table)
return nil unless autosequence
@primary_key_sequences.fetch(table) do |key|
- pk = schema(table).select{|k, v| v[:primary_key]}
+ begin
+ sch = schema(table)
+ rescue Sequel::Error
+ return nil
+ end
+
+ pk = sch.select{|k, v| v[:primary_key]}
@primary_key_sequences[table] = if pk.length == 1
seq = "seq_#{table}_#{pk.first.first}"
seq.to_sym unless
from(:user_sequences).filter(:sequence_name=>input_identifier_meth.call(seq)).empty?
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.