<     May 2017     >
Su Mo Tu We Th Fr Sa  
    1  2  3  4  5  6  
 7  8  9 10 11 12 13  
14 15 16 17 18 19 20  
21 22 23 24 25 26 27  
28 29 30 31
01:08 banditro_ joined
03:57 claw joined
04:07 claw joined
06:56 aidalgol joined
13:09 tercenya joined
13:11 tercenya joined
13:13 tercenya joined
15:28 tercenya_ joined
20:45 Daivd_ joined
20:46 evanmorton joined
20:55 <evanmorton> I'm new to IRC, and somewhat new to sequel. I can read a table with DB.run, but not with DB[]. My example is below. (I've xxxed out the name of the host and database.) I'm talking to SQL Server.
20:56 <evanmorton> The DB.run succeeds. It doesn't produce output, but I can tell it's working because it gives an error when I change the tablename to nonsense, but doesn't give an error as is. The DB[] does not work. The final line causes an "invalid object name" error. I've pasted the long full error after the code. Thanks.
20:56 <evanmorton> #!/usr/bin/env ruby require "sequel" DB = Sequel.connect( :adapter=>'ado', :host =>'xxx', :database=>'xxx' ) DB.identifier_input_method = nil DB.identifier_output_method = nil inTableName = "sys.tables" DB.run('select count(*) from ' + inTableName) inTable = DB[inTableName.to_sym] puts 'row count is ' + inTable.count()
20:56 <evanmorton> C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/sequel-4.41.0/lib/sequel/adapters/ado.rb: 159:in `method_missing': WIN32OLERuntimeError: (in OLE method `Execute': ) (Sequel::DatabaseError) OLE error code:80040E37 in Microsoft OLE DB Provider for ODBC Drivers [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'sys.tables'. HRESULT error code:0x80020009 Exception occurred. from C:/Ruby23-x64/lib/rub
20:56 <evanmorton> Sorry, I don't know how to make line breaks work properly in this chat!
21:06 banditron joined
21:08 <jeremyevans> evanmorton: Sequel quotes identifiers by default. Use DB[Sequel[:sys][:tables]] or DB.from(Sequel.lit('sys.tables'))
21:24 <evanmorton> Thanks! I tried the second solution, and it works for both my test case and my real code. You, and the open source movement, rock.
21:30 ashah joined
21:32 <ashah> Hey @jeremyevans. We are using "add_unique_constraint", and wish for it to consider null values in columns as equal. Is this possible? (Our usage of add_unique_constraint is enforced on a tuple of columns)
21:33 <ashah> We feel confident in doing the check ourselves in Ruby, but wish to see whether the constraint applied in a migration can support this.
21:53 <jeremyevans> ashah: You'll probably have to use coalesce database function to handle nil values specially, and add it as a unique index instead of a unique constraint, and have a database that supports indexes on expressions (PostgreSQL does)
21:53 <jeremyevans> ashah: Alternatively, a partial unique index on one column where the other column is null may work
23:25 gregburek joined
23:58 <ashah> Thanks jeremyevans.