I am having the same problem. I am using jruby (jre 1.8) and jdbc ...
require 'sequel'
require 'sqljdbc_4.0/enu/sqljdbc4.jar'
server_name = "yours"
user = "YOURS"
pass = "YOURS"
DB = Sequel.connect
"jdbc:sqlserver://#{server_name};databaseName=master;user=#{user};password=#{password}"
DB.fetch("SELECT TOP 5 * FROM INFORMATION_SCHEMA.TABLES").first
works
ss = DB['INFORMATION_SCHEMA.TABLES']
ss.limit(5).all generates an error
Sequel::DatabaseError: Java::ComMicrosoftSqlserverJdbc::SQLServerException:
Incorrect syntax near ')'.
from
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(com/microsoft/sqlserver/jdbc/SQLServerException.java:216)
from
com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(com/microsoft/sqlserver/jdbc/SQLServerStatement.java:1515)
from
com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(com/microsoft/sqlserver/jdbc/SQLServerStatement.java:792)
from
com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(com/microsoft/sqlserver/jdbc/SQLServerStatement.java:689)
from
com.microsoft.sqlserver.jdbc.TDSCommand.execute(com/microsoft/sqlserver/jdbc/IOBuffer.java:5696)
from
com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(com/microsoft/sqlserver/jdbc/SQLServerConnection.java:1715)
from
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(com/microsoft/sqlserver/jdbc/SQLServerStatement.java:180)
from
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(com/microsoft/sqlserver/jdbc/SQLServerStatement.java:155)
from
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(com/microsoft/sqlserver/jdbc/SQLServerStatement.java:616)
from java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:497)
from RUBY.block in
execute(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/adapters/jdbc.rb:251)
from
RUBY.log_yield(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/database/logging.rb:33)
from RUBY.block in
execute(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/adapters/jdbc.rb:251)
from
RUBY.statement(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/adapters/jdbc.rb:658)
from RUBY.block in
execute(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/adapters/jdbc.rb:246)
from
RUBY.hold(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/connection_pool/threaded.rb:103)
from
RUBY.synchronize(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/database/connecting.rb:254)
from
RUBY.execute(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/adapters/jdbc.rb:245)
from
RUBY.execute(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:950)
from
RUBY.fetch_rows(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/adapters/jdbc.rb:721)
from
RUBY.with_sql_each(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:833)
from
RUBY.with_sql_first(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:841)
from
RUBY.single_record!(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:659)
from
RUBY.single_record(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:647)
from
RUBY.first(/Users/cortman/.gem/jruby/2.2.3/gems/sequel-4.29.0/lib/sequel/dataset/actions.rb:192)
from RUBY.<eval>((irb):16)
from org.jruby.RubyKernel.eval(org/jruby/RubyKernel.java:976)
from org.jruby.RubyKernel.loop(org/jruby/RubyKernel.java:1287)
from org.jruby.RubyKernel.catch(org/jruby/RubyKernel.java:1096)
from org.jruby.RubyKernel.catch(org/jruby/RubyKernel.java:1096)
from
Users.cortman.$_dot_rubies.jruby_minus_9_dot_0_dot_5_dot_0.bin.jirb.<top>(/Users/cortman/.rubies/jruby-9.0.5.0/bin/jirb:13)
from
java.lang.invoke.MethodHandle.invokeWithArguments(java/lang/invoke/MethodHandle.java:627)irb(main):017:0>
And ss.limit(5).sql is
"SELECT TOP (5) * FROM (INFORMATION_SCHEMA.TABLES) AS [T1]"
Setting quote_identifiers seems to have no effect.
On Monday, February 2, 2015 at 7:48:50 AM UTC-6, Horacio Peña wrote:
>
> I am able to connect to a MSSQL server using sequel, and I can fetch data
> using .fetch, but when trying to use datasets I got "Incorrect syntax"
>
> 2.0.0-p247 :002 > a= Sequel.odbc('server', user: 'sqluser', password:
> 'password')
> #<Sequel::ODBC::Database: {:adapter=>:odbc, :database=>"server",
> :user=>"sqluser", :password=>"password"}>
> 2.0.0-p247 :006 > a.fetch("select * from
> _PRODUCTIVIDAD_DIARIA_USUARIO").first
>
> {
> :cliente => " ",
> :fecha => 2014-02-03 00:00:00 -0300,
> ...
>
> 2.0.0-p247 :008 > a[:_PRODUCTIVIDAD_DIARIA_USUARIO]
> #<Sequel::ODBC::Dataset: "SELECT * FROM \"_PRODUCTIVIDAD_DIARIA_USUARIO\"">
>
> 2.0.0-p247 :009 > a[:_PRODUCTIVIDAD_DIARIA_USUARIO].first
> Sequel::DatabaseError: ODBC::Error: 37000 (102) [FreeTDS][SQL
> Server]Incorrect syntax near '_PRODUCTIVIDAD_DIARIA_USUARIO'.
> from
> /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.17.0/lib/sequel/adapters/odbc.rb:45:in
>
> `run'
> from
> /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.17.0/lib/sequel/adapters/odbc.rb:45:in
>
> `block (2 levels) in execute'
> from
> /usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.17.0/lib/sequel/database/logging.rb:33:in
>
> `log_yield'
> ...
>
> It seems to me that the quotes around the table name are the problem. How
> can that be solved?
>
> Also, the MSSQL server has some tables with non-ascii names, like:
>
> 2.0.0-p247 :031 > a.fetch("select TABLE_NAME from
> information_schema.tables").all
>
> [63] {
> :table_name => "_CAMPA\xC3\x91AS"
> },
>
> I've tried both:
>
> 2.0.0-p247 :034 > a.fetch("select * from _CAMPA\xC3\x91AS").all
> Sequel::DatabaseError: ODBC::Error: 37000 (102) [FreeTDS][SQL
> Server]Incorrect syntax near '�'.
>
> and
>
> 2.0.0-p247 :035 > a.fetch("select * from _CAMPAÑAS").all
> Sequel::DatabaseError: ODBC::Error: 37000 (102) [FreeTDS][SQL
> Server]Incorrect syntax near '�'.
>
> Can that be solved?
>
> Thanks,
> Horacio J. Peña
>
--
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.