wzinsmey | 3 Mar 18:55
Picon

cannot insert with Sybase

Hello,     ... has anyone gotten SQLObject to work with Sybase?
I can query the database but I can't insert.  Any advice would be
appreciated.  The table already exists and is extremely simple,
with just two columns, a key and a text string.

Here's the class for the table:
==========================================
from sqlobject import *

class titles( SQLObject ):
   
    title_id = IntCol()
    title = StringCol()

    class sqlmeta:
        print 'class sqlmeta'
        idName = 'title_id'
        lazyUpdate = False
        autoCommit = True
==========================================
And here's a separate class where I attempt to insert:
==========================================
from sqlobject import *
import titles

class InsertNewTitle:

    def __init__( self, newKey, newTitle ):
        sybURI = "sybase://my_user_id:my_password <at> DBSERVER//library_info"
        konnection = connectionForURI( sybURI )
        sqlhub.processConnection = konnection

        book_a = titles.titles(title_id=0, title='zero')
        book_a._connection.debug = True
        book_a._connection.autoCommit = True
       
        book_b = titles.titles(title_id=newKey, title=newTitle)
        book_b._connection.debug = True
        book_b._connection.autoCommit = True
        book_b.id = newKey
        book_b.set(title_id=newKey, title = newTitle)
        book_b.syncUpdate()

        print 'for ID %d the title is %s' % ( book_b.title_id, book_b.title )
        return None

if __name__ == "__main__":
    instantiatedObject = InsertNewTitle(506,"Spy Story")
==========================================
This code actually appears to work with no errors, but I can run it
many times with no duplicate rows because nothing gets inserted into
the database.  I tried wrapping it all in a transaction and doing a
commit, but that didn't help.  It's not a permission problem because
I've used the same ID and password in an SQL tool and I can insert.

Note I instantiate two books.  I don't want to, but I'm forced to
because if I try to give it a non-zero first key I get the error:
"sqlobject.main.SQLObjectNotFound: The object titles by the ID 0
does not exist"    ....even though I'm providing a non-zero key!

So I have 2 questions, if anyone would be kind enough to help:
why does it complain about 0 not existing when I create only one
book using a non-zero key (but doesn't complain as long as I use
the 2 book work-around shown) and why does nothing get written
to the database, even when I put in a commit? 

Thanks in advance for any help. 
    .....WZ


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 3 Mar 19:18
X-Face
Picon
Favicon

Re: cannot insert with Sybase

On Tue, Mar 03, 2009 at 05:55:43PM +0000, wzinsmey <at> comcast.net wrote:
> class sqlmeta: 
> print 'class sqlmeta' 
> idName = 'title_id' 
> lazyUpdate = False 
> autoCommit = True 

   sqlmeta doesn't have 'autoCommit' attribute.

   (It'd also be helpful to send python code properly formatted.)

> book_a._connection.debug = True 
> book_a._connection.autoCommit = True 

   It is too late to set this after creating a row. The settings should be
set on the 'konnection' before inserting.

> This code actually appears to work with no errors, but I can run it 
> many times with no duplicate rows because nothing gets inserted into 
> the database.

   No commit has been done.

> I tried wrapping it all in a transaction and doing a 
> commit, but that didn't help.

   It'd be interesting to see the code.

> It's not a permission problem

   Certainly not - with a permission problem you'd get an exception.

> Note I instantiate two books. I don't want to, but I'm forced to 
> because if I try to give it a non-zero first key I get the error: 
> "sqlobject.main.SQLObjectNotFound: The object titles by the ID 0 
> does not exist" ....even though I'm providing a non-zero key! 

   Please show the debugging output and the entire traceback.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
wzinsmey | 4 Mar 11:31
Picon

Re: cannot insert with Sybase

Hello Oleg and others,

Thanks sincerely for the help; I'm much further along because
now rows are inserted successfully.  However, I still get an
odd error message referring to key 0 when I do a simple print 
to show the values in the object.

BTW, I will do my best to preserve indenting but my web-based
email service is determined to ruin the code.

better class 1:
===========================================================
from sqlobject import *

class titles( SQLObject ):
   
    title_id = IntCol()
    title = StringCol()

    class sqlmeta:
        print 'class sqlmeta'
        idName = 'title_id'
        lazyUpdate = False
===========================================================
better class 2:
===========================================================
from sqlobject import *
import titles

class InsertNewTitle:

    def makeNewBook( self ):
        sybURI = "sybase://my_user_id:my_password <at> DBSERVER//library_info"
        konnection = connectionForURI( sybURI )
        konnection.debug = True
        konnection.autoCommit = True
        sqlhub.processConnection = konnection
      
        newKey = 1234
        newTitle = "Mystery Book"
        book_b = titles.titles(title_id=newKey, title=newTitle) # works!
#        book_b.id = newKey
#        book_b.set(title_id=newKey, title = newTitle)
#        book_b.syncUpdate()
#        book_b = titles.get(newKey)

        print 'for ID %d the title is %s' % ( book_b.title_id, book_b.title ) # fails
        return None

if __name__ == "__main__":
    instantiatedObject = InsertNewTitle()
    instantiatedObject.makeNewBook()
===========================================================
and the error and the messages I cannot prevent are:
===========================================================
class sqlmeta
QueryIns: INSERT INTO titles (title_id, title) VALUES (1234, 'Mystery Book')
 1/QueryOne:  SELECT title_id, title FROM titles WHERE ((titles.title_id) = (0))
 1/QueryR  :  SELECT title_id, title FROM titles WHERE ((titles.title_id) = (0))
Traceback (most recent call last):
  File "/diska/data/workspace/PyXtern/src/tmpTry/InsertNewTitle.py", line 30, in <module>
    instantiatedObject.makeNewBook()
  File "/diska/data/workspace/PyXtern/src/tmpTry/InsertNewTitle.py", line 18, in makeNewBook
    book_b = titles.titles(title_id=newKey, title=newTitle)
  File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1203, in __init__
  File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1251, in _create
  File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1278, in _SO_finishCreate
  File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 931, in _init
sqlobject.main.SQLObjectNotFound: The object titles by the ID 0 does not exist
===========================================================

Note the commented code showing ways I have tried to persuade
the object to think about my new key, but clearly it remains focused
on key 0 which does not exist in the database, so the commented
lines did not help.  What might be the appropriate remedy for this error? 

Again thank you for the timely help,
    .....WZ
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 4 Mar 11:55
X-Face
Picon
Favicon

Re: cannot insert with Sybase

On Wed, Mar 04, 2009 at 10:31:31AM +0000, wzinsmey <at> comcast.net wrote:
> from sqlobject import * 
> 
> class titles( SQLObject ): 
> 
> title_id = IntCol() 
> title = StringCol() 
> 
> class sqlmeta: 
> print 'class sqlmeta' 
> idName = 'title_id' 
[skip]
> newKey = 1234 
> newTitle = "Mystery Book" 
> book_b = titles.titles(title_id=newKey, title=newTitle)

   Throughout entire SQLObject the 'id' column is called 'id'. After you
named your column 'title_id' in sqlmeta you have to use 'id' name for the
column:

book_b = titles.titles(id=newKey, title=newTitle)

   Without that SQLObject thinks id is None and creates a new id by asking
the backend - see sqlobject/sybase/sybaseconnection.py, methods
_queryInsertId() and insert_id(). insert_id() creates a new id (0) and then
SQLObject tries to SELECT the row back by that id.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
wzinsmey | 4 Mar 17:13
Picon

Re: cannot insert with Sybase

Hello Oleg and others,
             
But if I use 'id' instead of 'title_id' I get:
              
  File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1203, in __init__
  File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1237, in _create
TypeError: titles() did not get expected keyword argument 'title_id'
                   
I hope it helps if I use dots to preserve the indentation:
=======================================
from.sqlobject.import.*

class.titles(.SQLObject.):

....title_id = IntCol()
....title = StringCol()

....class.sqlmeta:
........print.'class.sqlmeta'
........idName = 'title_id'
........lazyUpdate = False
=======================================
second class to insert a row:
=======================================
from sqlobject import *
import titles

class InsertNewTitle:

....def makeNewBook( self ):
........sybURI = "sybase://my_user_id:my_password <at> DBSERVER//library_info"
........konnection = connectionForURI(sybURI)
........konnection.debug = True
........konnection.autoCommit = True
........sqlhub.processConnection = konnection
      
........newKey = 1237
........newTitle = "Mystery Book"
........book_b = titles.titles(id=newKey, title=newTitle)

........print 'for ID %d the title is %s' % (book_b.id, book_b.title)
........return None

if __name__ == "__main__":
....instantiatedObject = InsertNewTitle()
....instantiatedObject.makeNewBook()
=========================================
I also tried mixing various combinations of
'id' and 'title_id' in the two locations
but an error always results, with no
indication what it really wants. 
                         
Thanks very much, 
   ....WZ

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 4 Mar 17:22
X-Face
Picon
Favicon

Re: cannot insert with Sybase

On Wed, Mar 04, 2009 at 04:13:54PM +0000, wzinsmey <at> comcast.net wrote:
> Hello Oleg and others, 
> 
> But if I use 'id' instead of 'title_id' I get: 
> 
> File
"/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py",
line 1203, in __init__ 
> File
"/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py",
line 1237, in _create 
> TypeError: titles() did not get expected keyword argument 'title_id' 

   Oops, my fault, sorry. You must not declare the 'id' column.

> I hope it helps if I use dots to preserve the indentation: 
> ======================================= 
> from.sqlobject.import.* 
> 
> class.titles(.SQLObject.): 
> 
> ....title_id = IntCol() 
> ....title = StringCol() 
> 
> ....class.sqlmeta: 
> ........print.'class.sqlmeta' 
> ........idName = 'title_id' 
> ........lazyUpdate = False 

   Remove 'title_id = IntCol()' from the class declaration. idName is the
only way to name the column, and 'id' is the only way to refer to the
column.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
wzinsmey | 4 Mar 17:51
Picon

Re: cannot insert with Sybase

No need to apologize; your help has been invaluable.
It's working well now, so it's on to joins and other challenges!
(Though I'll try not to bother you for a few days!)

Thanks again,
    ....WZ


----- Original Message -----
From: "Oleg Broytmann" <phd <at> phd.pp.ru>
To: sqlobject-discuss <at> lists.sourceforge.net
Sent: Wednesday, March 4, 2009 4:22:59 PM GMT +00:00 Monrovia
Subject: Re: [SQLObject] cannot insert with Sybase

On Wed, Mar 04, 2009 at 04:13:54PM +0000, wzinsmey <at> comcast.net wrote:
> Hello Oleg and others,
>
> But if I use 'id' instead of 'title_id' I get:
>
> File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1203, in __init__
> File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1237, in _create
> TypeError: titles() did not get expected keyword argument 'title_id'

   Oops, my fault, sorry. You must not declare the 'id' column.

> I hope it helps if I use dots to preserve the indentation:
> =======================================
> from.sqlobject.import.*
>
> class.titles(.SQLObject.):
>
> ....title_id = IntCol()
> ....title = StringCol()
>
> ....class.sqlmeta:
> ........print.'class.sqlmeta'
> ........idName = 'title_id'
> ........lazyUpdate = False

   Remove 'title_id = IntCol()' from the class declaration. idName is the
only way to name the column, and 'id' is the only way to refer to the
column.

Oleg.
--
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 4 Mar 17:56
X-Face
Picon
Favicon

Re: cannot insert with Sybase

On Wed, Mar 04, 2009 at 04:51:17PM +0000, wzinsmey <at> comcast.net wrote:
> (Though I'll try not to bother you for a few days!) 

   Actually, you can't. (-: Tomorrow I am leaving the town (even the
country) for a short vacation. Will be back March 9, late at night.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
Daniel Fetchinson | 11 Mar 07:59

a complex query question

I'm sorry to come up again with a complex query question but I simply
couldn't find a simple solution for this.

My schema is the following: there are zoos, zoos have cages, cages
have animals. And to any of these objects comments can be associated.
For a given zoo I need to select all comments that are either:
comments on the zoo OR comments on a cage belonging to this zoo OR
comments on an animal belonging to a cage belonging to this zoo.

The schema is this:

class zoo( SQLObject ):
    cages = MultipleJoin( 'cage' )

class cage( SQLObject ):
    animals = MultipleJoin( 'animal' )
    zoo = ForeignKey( 'zoo' )

class animal( SQLObject ):
    cage = ForeignKey( 'cage' )

class comment( SQLObject ):
    object_id = Int( ) # this is the 'id' of the object this comment
is associated to
    object_ = StringCol( validator=OneOf( [ 'animal', 'cage', 'zoo' ]
) ) # type of object
    content = UnicodeCol( ) # the actual comment

It might very well be the case that this setup is not optimal but
unfortunately I can't change it. So given a zoo instance with comments
on zoos, cages and animals, does anyone know an elegant query that
will select all comments that belong either to this zoo instance or to
any cage in this zoo or any animal that is in a cage in the zoo?

Thanks very much for any help,
Daniel

--

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
Oleg Broytmann | 11 Mar 10:36
X-Face
Picon
Favicon

Re: a complex query question

On Tue, Mar 10, 2009 at 11:59:33PM -0700, Daniel Fetchinson wrote:
> class comment( SQLObject ):
>     object_id = Int( ) # this is the 'id' of the object this comment
> is associated to
>     object_ = StringCol( validator=OneOf( [ 'animal', 'cage', 'zoo' ]
> ) ) # type of object
>     content = UnicodeCol( ) # the actual comment
> 
> select all comments that belong either to this zoo instance or to
> any cage in this zoo or any animal that is in a cage in the zoo?

   With such a setup the only way I can see is to issue a complex UNION
query that unions 3 different queries - SELECT comments for zoo, cages and
animals.
   UNION queries are, of course, impossible with SQLObject tables but
possible with SQLBuilder.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

Gmane