Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ruby Programming Language

Sequel: Cannot save model or limit varchars

Hi out there,

I experienced Problems when I tried to save a Sequel::Model

   ERROR database: ERROR:  currval of sequence "schedules_id_seq" is  
not yet defined in this session

The model schema is:

   set_schema do
     serial    :id, :primary_key => true
     varchar   :state, :default => 'running'

     timestamp :starts_at
     timestamp :stops_at

     integer   :aberrate_with
     integer   :dispersal_shift

During testing I always recreate the models table.

Also I cant figure out how to limit varchars...


Huh, did some hacking... to fix this problem I changed the sequel/
postgres.rb code a bit:


   # See: http://www.postgresql.org/docs/8.2/static/sql-insert.html
   RETURNING = " RETURNING (%s)".freeze

   # Initializes and returns @table_sequence
   def table_sequences
     # define default procedure for missing keys (tables) that  
fetches the pkey
     @table_sequences ||= Hash.new do |sequences, table|
       # this is not threadsafe but the results shouldn't differ
       @pool.hold { |conn| sequences[table] = conn.pkey_and_sequence
(table).first }
   # Ahh, protect this Method... *paranoia*
   protected :table_sequences

   def execute_insert(sql, table)
     # add RETURNING statement to sql
     sql << RETURNING % table_sequences[table]

     @logger.info(sql) if @logger

     # this is not nice :(
     @pool.hold do |conn|
       result = conn.execute sql
       id = result[0][0].to_i and result.clear


   rescue => e
     @logger.error(e.message) if @logger
     raise e


@L1: I'd replace:

   if !Object.const_defined?('Sequel')
     require File.join(File.dirname(__FILE__), '../sequel')


   require File.join(File.dirname(__FILE__), '../sequel')

since Ruby itself checks whether a file is already required...

Another question:
Is PGconn the right place for the @table_sequences cache? I'd place  
it in the Sequel::Postgres module...


Am 05.06.2007 um 00:09 schrieb Florian Amann:

On Jun 4, 7:01 pm, Florian Amann <florian.assm@email.de> wrote:

Not that I mind, but you mind get a better response on the Sequel
mailing list: http://groups.google.com/group/sequel-talk
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc