georgiev / rubyfb

ruby/rails Firebird db access library
Other
16 stars 5 forks source link

Error preparing a SQL statement. invalid request BLR at offset 76 generator #19

Closed EddieDee closed 10 years ago

EddieDee commented 10 years ago

I am getting this problem in some tables, and sometime to fix this, i just need to create a new generator for that table, the weird thing is that this legacy Database is being used with other system with DELPHI and is working good:

This is the error:

Error preparing a SQL statement. invalid request BLR at offset 76 generator MSFIMPUESTOS_SEQ is not defined Invalid token SQL Code = -104 Firebird Code = 335544343

Model: class Tax < ActiveRecord::Base attr_accessible :code, :description, :rate establish_connection( :adapter => "rubyfb", :database => "localhost:/home/developer/Desktop/MFSBASE.Ib", :username => "SYSDBA", :password => "masterkey", :charset => "NONE")

self.table_name = 'msfimpuestos'

end

georgiev commented 10 years ago

That's the way the adapter works - it uses derived names for generators in the form of "#{table_name}_seq" to prefetch id values. Using database with DELPHI is not a way to judge (in your case it's not even advisable to use the same database with both DELPHI and Rails as they obviously use different id generation schemes and this will lead to PK violations).

EddieDee commented 10 years ago

Is there a way to capture this Exception and create on the fly the sequence?

maybe something like:

begin @invoice = Invoice.new(params[:invoice]) rescue Rubyfb::FireRubyException execute "CREATE GENERATOR #{@invoice.class.table_name}_SEQ; SET GENERATOR #{@invoice.class.table_name}_SEQ TO #{Invoice.count+1};" end