[Nitro] Errors with Og and existing table/data

Reid Thompson Reid.Thompson at ateb.com
Mon Apr 3 21:00:56 EDT 2006


given..
testexisting=# create table testtable(mytext text primary key, mynumber 
integer, yourtext text);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 
"testtable_pkey" for table "testtable"
CREATE TABLE
testexisting=# \d testtable;
    Table "public.testtable"
  Column  |  Type   | Modifiers
----------+---------+-----------
 mytext   | text    | not null
 mynumber | integer |
 yourtext | text    |
Indexes:
    "testtable_pkey" PRIMARY KEY, btree (mytext)

what am I missing in the program below that is causing the save to fail 
with 
error:/usr/local/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/connection.rb:115:in 
`query': ERROR C42601  Msyntax error at or near "new"       P81     
Fscan.l L761    Ryyerror (RuntimeError)
        from 
/usr/local/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/postgres-compat.rb:33:in 
`exec'
        from 
/usr/local/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store/psql.rb:307:in 
`sql_update'
        from (eval):6:in `og_update'
        from 
/usr/local/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store.rb:102:in `save'
        from 
/usr/local/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/entity.rb:32:in `save'
        from ogexisting.rb:35
)
-------------------------------------------
require 'og'

class  Testtable
    include  Og::EntityMixin

    property :mytext, String, Og::NotNull
    property :mynumber, Fixnum
    property :yourtext, String

    set_table :testtable
    set_primary_key :mytext, String
end

og_psql = {
  :destroy_tables => false,  # don't use this on a DB with tables that 
you DO NOT want to lose -- or set to false
  :store => :psql,
  :user => 'rthompso',
  :password => 'rthompso',
  :name => 'testexisting'
}

Og.table_prefix = '' # remove og generated table prefix
db = Og.setup(og_psql)

# if there are pre-existing recoreds, this DOES retrieve and print them
mystore = db.store
res = mystore.query("select * from testtable")
res.each {|rec|
    puts rec
}

a=Testtable.new
a.mynumber = 34
a.yourtext = 'some new your text'
a.mytext ='my new text'
a.save # failure here

res = mystore.query("select * from testtable")
res.each {|rec|
    puts rec
}




More information about the Nitro-general mailing list