Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String literal to long #80

Open
choallin opened this issue Nov 27, 2018 · 3 comments
Open

String literal to long #80

choallin opened this issue Nov 27, 2018 · 3 comments

Comments

@choallin
Copy link

choallin commented Nov 27, 2018

I have a table that saves various input from users. In one column we write a giant json string produced by a step by step wizard. This column is defined as a blob sub_type 1 with the utf-8 charset.

Now I when I want to save the last step I get this error:

String literal with 16538 characters exceeds the maximum length of 16383 characters for the UTF8 character set

When I manually make a string concat in the middle of the string (with "||" ) the statement works. According to a comment from my Stackoverflow question this could be fixed here

@rowland
Copy link
Owner

rowland commented Nov 27, 2018

Are you using parameterized statements? Using the UTF-8 charset (or UNICODE_FSS) can cause the implementation to allocate 3 bytes per character, which can surprise you if Firebird thinks it's dealing with a VARCHAR, which is limited to 32K.

@choallin
Copy link
Author

choallin commented Dec 3, 2018

I'm using the update_attributes method with a simple hash with one key.

@woblavobla
Copy link

@choallin I'm using modified version of ActiveRecord::Relation.update_all in my fork to make attributes work;

require 'active_record/relation'

ActiveRecord::Relation.class_eval do
  prepend(RelationExtensions = Module.new do
    def update_all(updates)
      raise ArgumentError, "Empty list of attributes to change" if updates.blank?
      stmt = Arel::UpdateManager.new
      stmt.table(table)
      value_binds = []
      arel_values = []
      if !updates.empty? && !updates.first.nil? && !updates.first.is_a?(String)
        updates.each do |column, value|
          value_binds.push ActiveRecord::Relation::QueryAttribute.new(column, value, @klass.type_for_attribute(column))
          arel_values.push Arel::Nodes::Assignment.new(Arel::Nodes::UnqualifiedColumn.new(Arel::Attributes::Attribute.new(table, column)), Arel::Nodes::BindParam.new)
        end
        stmt.ast.values = arel_values
      else
        stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates))
      end
      if has_join_values?
        @klass.connection.join_to_update(stmt, arel, arel_attribute(primary_key))
      else
        stmt.key = arel_attribute(primary_key)
        stmt.take(arel.limit)
        stmt.order(*arel.orders)
        stmt.wheres = arel.constraints
      end
      @klass.connection.update stmt, "SQL", value_binds + bound_attributes
    end
  end)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants