[Nitro] Errors with Og and existing table/data

Bryan Soto bryan.a.soto at gmail.com
Wed Apr 5 01:44:35 EDT 2006


On 4/3/06, Reid Thompson <Reid.Thompson at ateb.com> wrote:
> 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

Could you add the line below and re-run? We might get better info if
we see the sql that is generated. Unfortunately I'm not a postgres
user, so I can't easily replicate this. Hopefully someone more
familiar with it will chime in...

$DBG = true

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

--
"Never tell people how to do things. Tell them what to do and they
will surprise you with their ingenuity." —General George S. Patton




More information about the Nitro-general mailing list