Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord ArgumentError: negative string size (or size too big)

I've been working with this one for a few days. Here's the ActiveRecord error and the application trace.

ArgumentError: negative string size (or size too big): 
EXEC sp_executesql N'SELECT [ops_jobs_join].* FROM [ops_jobs_join] 
WHERE (work_center_id = N''M*1053'' OR work_center_id = N''M*1035'' OR
      work_center_id = N''M*1037'' OR work_center_id = N''M*1036'') AND
      (status != N''C'') AND (start_date != N'''') AND 
      (start_date >= N''20120516'') AND (comp_date <= N''20120527'') AND 
      (work_order NOT LIKE N''LA%'') 
ORDER BY work_center_id ASC, start_date ASC, starting_shift_num ASC, 
      status ASC, priority ASC, comp_date ASC, ending_shift_num ASC, 
      due_date ASC, sequence_number ASC'

It turns out if I call Op.all I get this error:

ActiveRecord ArgumentError: negative string size (or size too big)

If I ignore the column that uses may contain unicode characters it works fine. All the data is being stored in the database without a problem but for some reason rails3 isn't having it.

Some where clauses will return records while others result in the same error:

activerecord-sqlserver-adapter (3.2.4) lib/active_record/connection_adapters/sqlserver/database_statements.rb:421:in `fetch_all'

It's similar to these two posts:

  • ActiveRecord::StatementInvalid: ArgumentError: negative string size (or size too big): SELECT * FROM [shop]

  • ActiveRecord doesn't work on one table

It seems like the solution in the first post is to change the gem which I would like to avoid.

I looked at my table and I don't think I'm using any keywords as field names.

I use other queries similar to this one and they work fine. The only difference is the values I use in the where clause (work_center_id = N''M*1053'').

like image 619
riddler Avatar asked May 21 '12 18:05

riddler


1 Answers

Rails default encoding for manipulates with data is UTF8, you need to use this encoding as well in your database. Change it and all has to be fine.

like image 88
Petr Brazdil Avatar answered Sep 28 '22 05:09

Petr Brazdil