Sequel: Cannot save model or limit varchars

  • Thread starter Florian Aßmann
  • Start date
F

Florian Aßmann

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
 
F

Florian Aßmann

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

@L167:

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

# Initializes and returns @table_sequence
def table_sequences
# define default procedure for missing keys (tables) that =20
fetches the pkey
@table_sequences ||=3D Hash.new do |sequences, table|
# this is not threadsafe but the results shouldn't differ
@pool.hold { |conn| sequences
=3D conn.pkey_and_sequence=20=

(table).first }
sequences

end
end
# Ahh, protect this Method... *paranoia*
protected :table_sequences

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


@logger.info(sql) if @logger

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

id
end

rescue =3D> 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 =20
it in the Sequel::postgres module...

Sincerely
Florian

Am 05.06.2007 um 00:09 schrieb Florian A=DFmann:
 
S

Sam Smoot

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
= conn.pkey_and_sequence
(table).first }
sequences

end
end
# Ahh, protect this Method... *paranoia*
protected :table_sequences

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


@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:
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


Not that I mind, but you mind get a better response on the Sequel
mailing list: http://groups.google.com/group/sequel-talk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top