I am also having troubles using sqlserver + octopus + tiny_tds.
uname -a
Linux brett-laptop 2.6.38-9-generic #43-Ubuntu SMP Thu Apr 28 15:23:06
UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
gem list:
activerecord (3.0.7, 3.0.5, 3.0.1, 2.3.8, 2.3.5)
activerecord-oracle_enhanced-adapter (1.3.2, 1.3.0)
activerecord-sqlserver-adapter (3.0.15)
activeresource (3.0.7, 3.0.5, 3.0.3, 3.0.1, 2.3.5)
activesupport (3.0.7, 3.0.5, 3.0.3, 3.0.1, 2.3.8, 2.3.5)
ar-octopus (0.3.4)
...
ruby-oci8 (2.0.4)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3, 1.3.2)
cat config/shards.yml
octopus:
environments:
- development
development:
shard_sqlite:
adapter: sqlite3
database: db/db_one.sqlite3
pool: 5
timeout: 5000
shard_ms:
adapter: sqlserver
host: 192.168.0.58
database: test
username: sa
password:
changedforthispostbutthepasswordisworkingsodontworryaboutit
I have an SQL Server Express (:shard_ms) and an sqlite (:shard_sqlite)
DB with *almost* the same schema. The SQL Server has an extra table,
but it isn't used (no model). Both DBs have a table called posts
(model: Post) for my testing. The SQL Server table has about 5
records. The sqlite table doesn't have any. My goal is to copy a
record from the SQL Server to the sqlite server like:
p = Post.using(:shard_ms).first
Post.using(:shard_sqlite).create( p.attributes )
Here are the two items I've noticed so far:
1) Oddly, the first time I run a command to pull a record from the
sqlite db (which has no records) it finds some. I'm pretty sure its
getting them from the :shard_ms server. The second time I run the
exact same request it gets it from the correct DB.
Loading development environment (Rails 3.0.7)
irb(main):001:0> Post.using(:shard_sqlite).count
=> 4
irb(main):002:0> Post.using(:shard_sqlite).count
=> 0
2) The second bug is the sqlite queries fail (besides the count
query). It looks like it is trying to run the SQL Server query against
the sqlite DB. (BTW: in the dump below you can also see the first bug
I mentioned, where it gets the record from the wrong DB)
Loading development environment (Rails 3.0.7)
irb(main):001:0> Post.using(:shard_sqlite).first
=> #<Post id: 1, name: "Brett", title: "my title", content: "blah blah
blah blah changed", created_at: "2011-05-19 18:19:24", updated_at:
"2011-05-19 18:19:24">
irb(main):002:0> Post.using(:shard_sqlite).first
ActiveRecord::StatementInvalid: SQLite3::SQLException: near ".":
syntax error: SELECT TOP (1) "posts".* FROM [posts]
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract_adapter.rb:207:in `log'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/sqlite_adapter.rb:284:in `select'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract/database_statements.rb:7:in
`select_all'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract/query_cache.rb:56:in
`select_all'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:142:in `send'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:142:in `method_missing'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/base.rb:468:in `find_by_sql'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/relation.rb:64:in `to_a'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/relation/finder_methods.rb:341:in `find_first'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/relation/finder_methods.rb:122:in `first'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/base.rb:439:in `__send__'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/base.rb:439:in `first'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
scope_proxy.rb:29:in `send'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
scope_proxy.rb:29:in `method_missing'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:97:in `run_queries_on_shard'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
scope_proxy.rb:28:in `method_missing'
And again with a create:
irb(main):003:0> p = Post.using(:shard_ms).first
=> #<Post id: 1, name: "Brett", title: "my title", content: "blah blah
blah blah changed", created_at: "2011-05-19 18:19:24", updated_at:
"2011-05-19 18:19:24">
...
irb(main):006:0> Post.using(:shard_sqlite).create( p.attributes )
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "'blah
blah blah blah changed'": syntax error: INSERT INTO [posts]
([content], [updated_at], [name], [created_at], [title]) VALUES
(N'blah blah blah blah changed', '2011-05-19 18:19:24.043', N'Brett',
'2011-05-19 18:19:24.043', N'my title')
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract_adapter.rb:207:in `log'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract/database_statements.rb:
282:in `insert_sql'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/sqlite_adapter.rb:149:in
`insert_sql'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract/database_statements.rb:
44:in `insert'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract/query_cache.rb:16:in
`insert'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:142:in `send'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:142:in `method_missing'
from /var/lib/gems/1.8/gems/arel-2.0.9/lib/arel/
select_manager.rb:217:in `insert'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/relation.rb:14:in `__send__'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/relation.rb:14:in `insert'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/persistence.rb:270:in `create'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/timestamp.rb:47:in `create'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/callbacks.rb:277:in `create'
from /var/lib/gems/1.8/gems/activesupport-3.0.7/lib/
active_support/callbacks.rb:414:in `_run_create_callbacks'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/callbacks.rb:277:in `create'
... 6 levels...
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/attribute_methods/dirty.rb:21:in `save'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:240:in `save'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:292:in
`with_transaction_returning_status'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/connection_adapters/abstract/database_statements.rb:
139:in `transaction'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:129:in `transaction'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:207:in `transaction'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:290:in
`with_transaction_returning_status'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:240:in `save'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:251:in `rollback_active_record_state!'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/transactions.rb:239:in `save'
from /var/lib/gems/1.8/gems/activerecord-3.0.7/lib/
active_record/base.rb:499:in `create'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
scope_proxy.rb:29:in `send'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
scope_proxy.rb:29:in `method_missing'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
proxy.rb:97:in `run_queries_on_shard'
from /var/lib/gems/1.8/gems/ar-octopus-0.3.4/lib/octopus/
scope_proxy.rb:28:in `method_missing'
from (irb):6irb(main):007:0>
Thoughts?