[Nitro] Errors with Og and existing table/data

Reid Thompson reid.thompson at ateb.com
Thu Apr 6 12:10:20 EDT 2006


Bryan Soto wrote:
> 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
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>   
Hmm.. why is it attempting to do an update, rather than an insert?
Using a pre-existing table does not restrict you to ONLY updating 
existing data does it????

And the where clause is not quoted....

I, [2006-04-06T12:04:46.426000 #2500]  INFO -- : Og uses the Psql store.
D, [2006-04-06T12:04:47.614000 #2500] DEBUG -- : Og manageable classes: 
[Testtable]
D, [2006-04-06T12:04:47.629000 #2500] DEBUG -- : Table testtable already 
exists
D, [2006-04-06T12:04:47.661000 #2500] DEBUG -- : PostgreSQL processing 
foreign key constraints
D, [2006-04-06T12:04:47.661000 #2500] DEBUG -- : PostgreSQL finished 
setting constraints. No action was taken in 0.00 seconds.
D, [2006-04-06T12:04:47.661000 #2500] DEBUG -- : select * from testtable
D, [2006-04-06T12:04:47.661000 #2500] DEBUG -- : UPDATE testtable SET 
mynumber=34, yourtext='some new your text' WHERE mytext=my new text
c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.3.6/lib/postgres-pr/connection.rb:115:in 
`query': ERROR    C42601    Msyntax error at or near "new"    P81    
Fscan.l    L761    Ryyerror (RuntimeError)
    from 
c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.3.6/lib/postgres-pr/postgres-compat.rb:32:in 
`exec'
    from 
c:/ruby/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 c:/ruby/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/store.rb:102:in 
`save'
    from c:/ruby/lib/ruby/gems/1.8/gems/og-0.29.0/lib/og/entity.rb:32:in 
`save'
    from C:/cygwin/home/rthompso/rbB1.tmp:36
Completed(1)



More information about the Nitro-general mailing list