Forum: Ruby Sequel: Cannot save model or limit varchars

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ee469623eb1b8e6e35d192822b9c4aa2?d=identicon&s=25 Florian Aßmann (Guest)
on 2007-06-05 00:10
(Received via mailing list)
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
   end

During testing I always recreate the models table.

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

Sincerely
Florian
Ee469623eb1b8e6e35d192822b9c4aa2?d=identicon&s=25 Florian Aßmann (Guest)
on 2007-06-05 02:01
(Received via mailing list)
Huh, did some hacking... to fix this problem I changed the sequel/
postgres.rb code a bit:

@L167:

   # 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 }
       sequences[table]
     end
   end
   # 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

       id
     end

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

   end

@L1: I'd replace:

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

with:

   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...

Sincerely
Florian

Am 05.06.2007 um 00:09 schrieb Florian Aßmann:
41c597a48c80e37ba68d1adc7095ea0e?d=identicon&s=25 Sam Smoot (Guest)
on 2007-06-05 04:32
(Received via mailing list)
On Jun 4, 7:01 pm, Florian Aßmann <florian.assm...@email.de> wrote:
>      # define default procedure for missing keys (tables) that
>
>
>
> Another question:
> > I experienced Problems when I tried to save a Sequel::Model
> >     timestamp :starts_at
> > Sincerely
> > Florian

Not that I mind, but you mind get a better response on the Sequel
mailing list: http://groups.google.com/group/sequel-talk
This topic is locked and can not be replied to.