On Dec 1, 12:08 pm, Gary Doades <[email protected]> wrote:
> Hmm, I'm not sure this is working right, or, more likely, I'm using it
> wrong.
>
> Simplified for testing:
>
> defaultDB =
> "jdbc:sqlserver://localhost;databaseName=bev1234;user=sa;password=testing;"
> servers = {}
> servers[:bev1234] = {:uri => defaultDB}
> DB = Sequel.connect(defaultDB, :servers => servers, :servers_hash =>
> Hash.new{|h,v| raise Exception.new("Unknown server: #{v}")})
>
> (so the :default server and the :bev1234 server should be the same?)

If they should be the same, use:

servers[:bev1234] = {}

> in irb results in:
>
> => #<Sequel::JDBC::Database:
> "jdbc:sqlserver://localhost;databaseName=bev1234;user=sa;password=testing;">
>
> irb(main):008:0> DB[:client].first
> Exception: Unknown server: read_only
>          from (irb):7

This is expected.  The read_only shard is used by default for all
SELECT times (anything using Dataset#each).  You should probably add
a :read_only=>{} entry to the servers hash to avoid this.

> irb(main):009:0> DB[:client].server(:default).first
> Exception: Unknown server: read_only
>          from (irb):7
> irb(main):010:0> DB[:client].server(:bev1234).first
> Exception: Unknown server: read_only
>          from (irb):7
> irb(main):011:0>

This is unexpected and I can't replicate it.

require 'rubygems'
require 'sequel'
p Sequel.sqlite(:servers=>{:read_only=>{}}, :servers_hash=>Hash.new{|
h,v| raise Exception.new("Unknown server: #{v}")})['SELECT 1'].all
# => [{:"1"=>1}]
Sequel.sqlite(:servers=>{}, :servers_hash=>Hash.new{|h,v| raise
Exception.new("Unknown server: #{v}")})['SELECT 1'].all
# => Exception raised: Unknown server: read_only
Sequel.sqlite(:servers=>{}, :servers_hash=>Hash.new{|h,v| raise
Exception.new("Unknown server: #{v}")})['SELECT
1'].server(:default).all
# => [{:"1"=>1}]
Sequel.sqlite(:servers=>{}, :servers_hash=>Hash.new{|h,v| raise
Exception.new("Unknown server: #{v}")})['SELECT 1'].server(:blah).all
# => Exception raised: Unknown server: blah

> Normally the servers hash contains around 70 databases (shards) and then
> I initialise all my models. I'm guessing all the models try to use the
> default database, which they now can't and throw the above "Unknown
> server: ... " error. Even specifying the shard to one I know exists
> throws the exception.
>
> I was hoping that not specifying any server (like for initialising the
> models) would still use :default, but any specific reference to a server
> that did not exist would raise an exception.
>
> What am I doing wrong?

Well, you probably want to add a :read_only=>{} entry to your servers
hash.  However, that doesn't explain why it's not picking up the shard
you specifically tell it to use.  Can you put together a self
contained example showing the above behavior?

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to