Markus W. Barth | 5 Apr 2009 13:02
Picon

DateCol & DateTimecol

The value for DateCol is set as a formatted date string but returns a datetime 
(or mxDateTime)

What's the reason for this asymmetric behaviour? In the docs it also says that 
it's _usually_ returned as these data types. Does this depend on the used db 
and is it predictable or do you have to check the datatype to make sure your 
code runs no matter where?

Thanks for explanations
markus

------------------------------------------------------------------------------
Oleg Broytmann | 5 Apr 2009 15:08
X-Face
Picon
Favicon

Re: DateCol & DateTimecol

On Sun, Apr 05, 2009 at 01:02:35PM +0200, Markus W. Barth wrote:
> The value for DateCol is set as a formatted date string

   Why? You can set datetime:

class Test(SQLObject):
    date = DateCol()

Test.createTable()

t = Test(date=date(2001, 12, 21))
print type(t.date), t.date

t.date = date(2002, 1, 1)
print type(t.date), t.date

   Output:

 1/Query   :  CREATE TABLE test (
    id INTEGER PRIMARY KEY,
    date DATE
)
 1/QueryR  :  CREATE TABLE test (
    id INTEGER PRIMARY KEY,
    date DATE
)
 2/QueryIns:  INSERT INTO test (date) VALUES ('2001-12-21')
 2/QueryR  :  INSERT INTO test (date) VALUES ('2001-12-21')
 3/QueryOne:  SELECT date FROM test WHERE ((test.id) = (1))
 3/QueryR  :  SELECT date FROM test WHERE ((test.id) = (1))
(Continue reading)

Markus W. Barth | 5 Apr 2009 19:26
Picon

Re: DateCol & DateTimecol

On Sunday 05 April 2009 15:08:37 Oleg Broytmann wrote:
> On Sun, Apr 05, 2009 at 01:02:35PM +0200, Markus W. Barth wrote:
> > The value for DateCol is set as a formatted date string
>
>    Why? You can set datetime:
>
> class Test(SQLObject):
>     date = DateCol()
>
> Test.createTable()
>
> t = Test(date=date(2001, 12, 21))
> print type(t.date), t.date
>
> t.date = date(2002, 1, 1)
> print type(t.date), t.date
>
>    Output:
>
>  1/Query   :  CREATE TABLE test (
>     id INTEGER PRIMARY KEY,
>     date DATE
> )
>  1/QueryR  :  CREATE TABLE test (
>     id INTEGER PRIMARY KEY,
>     date DATE
> )
>  2/QueryIns:  INSERT INTO test (date) VALUES ('2001-12-21')
>  2/QueryR  :  INSERT INTO test (date) VALUES ('2001-12-21')
>  3/QueryOne:  SELECT date FROM test WHERE ((test.id) = (1))
(Continue reading)

Oleg Broytmann | 5 Apr 2009 19:53
X-Face
Picon
Favicon

Re: DateCol & DateTimecol

On Sun, Apr 05, 2009 at 07:26:05PM +0200, Markus W. Barth wrote:
> Sorry, Oleg, you are right, it accepts both string and datetime. I got a bit 
> misleaded by the formencode exception
> <snippet>
> formencode.api.Invalid: expected a date/time string of the '%Y-%m-%d' format 
> in the DateTimeCol 'date', got <type 'str'> '' instead
> </snippet>

   Validator/converter tries hard to convert, but if there was an exception
it assumes the exception was from strptime() due to a non-corresponding
date and format strings.

Oleg.
--

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

------------------------------------------------------------------------------
Oleg Broytmann | 7 Apr 2009 22:40
X-Face
Picon
Favicon

Re: Is this a bug?

On Mon, Mar 30, 2009 at 04:16:16PM +0200, Iwan Vosloo wrote:
> This looks like a bug - correct me if I'm wrong.  Transaction.close()
> does not close the underlying connection. Seems like the __getattr__ of
> Transaction is to blame if I understand correctly.

   I think .close() on a Transaction must be forbidden. I am going to add a
.close() method to Transaction that raises an exception saying "Do not call
close() - call either commit(), commit(close=True) or rollback()". Ok?

Oleg.
--

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

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
Oleg Broytmann | 7 Apr 2009 22:40
X-Face
Picon
Favicon

Re: Bug? Spurious connection to postgresql

Hello! I am going to work on this. If you are still interested I'd like to
have a discussion.

On Sat, Dec 13, 2008 at 07:26:14PM +0200, Iwan Vosloo wrote:
> When you call dropTable on a SQLObject class, _inside a transaction_,
> sqlobject creates a second connection to postgresql.  This connection
> later deadlocks randomly with the first (which is sometimes busy inside
> a transaction).  
> 
> I can't figure out why the deadlock happens, but the second connection
> should never have been created to start with.
> 
> If you run the code below, you'll see that createTable works correctly.
> This code does not illustrate the deadlock, only the extra connection.
> 
> Using PDB, we've narrowed it to the following:
> 
> In pgconnection.py, line:
> 163  	        if self.server_version[:3] <= "7.2":
> 
> the attribute access to server_version results in a "poor mans
> aquisition" call to the method server_version on the Transaction's
> _dbConnection (a PostgresConnection).
> 
> In there, on line:
> 304  	            server_version = self.queryOne("SELECT version()")[0]
> 
> A query is executed on the underlying db connection.
> 
> This is where the extra connection is created (the original is already
(Continue reading)

Hanjie | 9 Apr 2009 23:44
Picon

A problem about "ForeignKey", help!!

Hi any man:
please help me, I have been confused by this problem for whole day.

I have two table and I want to use a foreignKey connect then together.

My coding is following:
 

class postTable(SQLObject):
    title = UnicodeCol(length=50)
    content = UnicodeCol()
    comments=MultipleJoin('commentTable')

class commentTable(SQLObject):
    post=ForeignKey('postTable')
    authorName=UnicodeCol(length=255,notNull=False)
    content=UnicodeCol()


Then I input "describe table post_table"
find the structure of post_table only content : id, title,content.
I can use like q.id, q.title, q.content.
But, when I want to use q.comment, the error arise:

I waste a whole day on this issue, please help me, I really need to use q.comment.
how to solve it.
Thank you in advance


My problem detail(I am studying how to use turbogears):

---------------------------model.py---------------------------------
class postTable(SQLObject):
    title = UnicodeCol(length=50)
    content = UnicodeCol()
    postDate = DateTimeCol(default=datetime.now())
    isPublished= BoolCol(default=False)
    comments=MultipleJoin('commentTable')
    def _get_html_content(self):
        return publish_parts(self.content,
                writer_name="html")["html_body"]
    html_content=property(_get_html_content)

class commentTable(SQLObject):
    post=ForeignKey('postTable')
    authorName=UnicodeCol(length=255,notNull=False)
    authorEmail=StringCol(length=255,notNull=False)
    authorUrl=StringCol(length=255,notNull=False)
    commentDate=DateTimeCol(default=datetime.now())
    content=UnicodeCol()


------------------------------control.py-------------------------------------------

class Root(controllers.RootController):
    <at> expose(template="assignment.templates.welcome")
    def index(self):
        posts = assignment.model.postTable.select()
        return dict(posts=posts)
   
    <at> expose(template="assignment.templates.post")
    def post(self,id):
        p=assignment.model.postTable.get(int(id))
        return dict(post=p)


----------------------------------welcome.kid----------------------------------------
<body>
    <div id = "posts">
        <div py:for="post in posts" id="post_${post.id}">
            <h2 py:content="post.title">Post title here</h2>
            <div class="postmeta">
                Posted on
                <span class="postdate" py:content="post.postDate">01/01/01</span>
            </div>
            <div class="content" py:content="XML(post.html_content)">
                This is where your post's content is displayed.
            </div>
            <div class="comments">
                <div py:for="comment in post.comments" id="comment_${comment.id}"> ##problem should be here
                    <div class="commentmeta">
                        Comment by
                        <span py:if="comment.authorUrl" py:strip=''>
                            <a href="${comment.authorUrl}" py:content="comment.authorName">Author with link</a>
                        </span>
                        <span py:if="not comment.authorUrl" py:strip='' py:content="comment.authorName">
                            Author without link
                        </span>
                        on
                        <span py:content="comment.commentDate">01/01/01</span>
                    </div>
                </div>
            </div>
                    <div class="content" py:content="comment.content">
                            Comment content here.
                    </div>       
        </div>
    </div>   
</body>

--------------------------------------------trac-------------------------------------------------

Page handler: <bound method Root.index of <assignment.controllers.Root object at 0x019E90F0>>
Traceback (most recent call last):
File "c:\python25\lib\site-packages\cherrypy-2.3.0-py2.5.egg\cherrypy\_cphttptools.py", line 121, in _run
self.main()
File "c:\python25\lib\site-packages\cherrypy-2.3.0-py2.5.egg\cherrypy\_cphttptools.py", line 264, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in index
File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 360, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\database.py", line 359, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 373, in <lambda>
mapping, fragment, args, kw)))
File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 423, in _execute_func
return _process_output(output, template, format, content_type, mapping, fragment)
File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\controllers.py", line 88, in _process_output
fragment=fragment)
File "c:\python25\lib\site-packages\TurboGears-1.0.8-py2.5.egg\turbogears\view\base.py", line 159, in render
return engine.render(**kw)
File "c:\python25\lib\site-packages\TurboKid-1.0.4-py2.5.egg\turbokid\kidsupport.py", line 206, in render
output=output, format=format)
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\__init__.py", line 301, in serialize
raise_template_error(module=self.__module__)
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\__init__.py", line 299, in serialize
return serializer.serialize(self, encoding, fragment, format)
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 107, in serialize
text = ''.join(self.generate(stream, encoding, fragment, format))
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 629, in generate
for ev, item in self.apply_filters(stream, format):
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 165, in format_stream
for ev, item in stream:
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 221, in _coalesce
for ev, item in stream:
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\serialization.py", line 477, in inject_meta_tags
for ev, item in stream:
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 179, in _track
for p in stream:
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\filter.py", line 32, in apply_matches
item = stream.expand()
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 108, in expand
for ev, item in self._iter:
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 179, in _track
for p in stream:
File "c:\python25\lib\site-packages\kid-0.9.6-py2.5.egg\kid\parser.py", line 221, in _coalesce
for ev, item in stream:
File "C:\Documents and Settings\hanjie\assignment\assignment\templates\welcome.py", line 109, in _pull
File "<string>", line 1, in <lambda>
File "c:\python25\lib\site-packages\SQLObject-0.10.4-py2.5.egg\sqlobject\joins.py", line 144, in performJoin
inst.id)
File "c:\python25\lib\site-packages\SQLObject-0.10.4-py2.5.egg\sqlobject\dbconnection.py", line 547, in _SO_selectJoin
self.sqlrepr(value)))
File "c:\python25\lib\site-packages\SQLObject-0.10.4-py2.5.egg\sqlobject\dbconnection.py", line 696, in queryAll
return self._dbConnection._queryAll(self._connection, s)
File "c:\python25\lib\site-packages\SQLObject-0.10.4-py2.5.egg\sqlobject\dbconnection.py", line 353, in _queryAll
self._executeRetry(conn, c, s)
File "c:\python25\lib\site-packages\SQLObject-0.10.4-py2.5.egg\sqlobject\mysql\mysqlconnection.py", line 117, in _executeRetry
raise OperationalError(ErrorMessage(e))
OperationalError: Unknown column 'post_table_id' in 'where clause'
Error location in template file 'C:\\Documents and Settings\\hanjie\\assignment\\assignment\\templates\\welcome.kid'
between line 19, column 3 and line 20, column 4:
<div class="comments">

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 10 Apr 2009 01:17
X-Face
Picon
Favicon

Re: A problem about "ForeignKey", help!!

On Thu, Apr 09, 2009 at 11:44:52PM +0200, Hanjie wrote:
> class postTable(SQLObject):
>     title = UnicodeCol(length=50)
>     content = UnicodeCol()
>     comments=MultipleJoin('commentTable')
> 
> class commentTable(SQLObject):
>     post=ForeignKey('postTable')
>     authorName=UnicodeCol(length=255,notNull=False)
>     content=UnicodeCol()
> 
> But, when I want to use q.comment, the error arise:
> OperationalError: Unknown column 'post_table_id' in 'where clause'

   The problem lies here:

class postTable(SQLObject):
    comments=MultipleJoin('commentTable')

class commentTable(SQLObject):
    post=ForeignKey('postTable')

   There are simply too many different names: 'comments', 'commentTable',
'post' and 'postTable'. Multitude of these names confuses SQLObject so it
doesn't know how to count comments of a post. One can help SQLObject by
explicitly naming the column in the other table:

class postTable(SQLObject):
    comments=MultipleJoin('commentTable', joinColumn='post_id')

Oleg.
--

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

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
Hanjie | 10 Apr 2009 01:39
Picon

Re: A problem about "ForeignKey", help!!

Great!!!
eventually, i find the problem!!!!
ForeignKey should use the same name with the related table.
How simple it is, but I waste a whole day on it!


Worry: post=ForeignKey('postTable')
correct: postTable=ForeignKey('

postTable')


On Fri, Apr 10, 2009 at 1:17 AM, Oleg Broytmann <phd <at> phd.pp.ru> wrote:
On Thu, Apr 09, 2009 at 11:44:52PM +0200, Hanjie wrote:
> class postTable(SQLObject):
>     title = UnicodeCol(length=50)
>     content = UnicodeCol()
>     comments=MultipleJoin('commentTable')
>
> class commentTable(SQLObject):
>     post=ForeignKey('postTable')
>     authorName=UnicodeCol(length=255,notNull=False)
>     content=UnicodeCol()
>
> But, when I want to use q.comment, the error arise:
> OperationalError: Unknown column 'post_table_id' in 'where clause'

  The problem lies here:

class postTable(SQLObject):
   comments=MultipleJoin('commentTable')

class commentTable(SQLObject):
   post=ForeignKey('postTable')

  There are simply too many different names: 'comments', 'commentTable',
'post' and 'postTable'. Multitude of these names confuses SQLObject so it
doesn't know how to count comments of a post. One can help SQLObject by
explicitly naming the column in the other table:

class postTable(SQLObject):
   comments=MultipleJoin('commentTable', joinColumn='post_id')

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

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Markus W. Barth | 10 Apr 2009 12:06
Picon

ForeignKey

Hi,
is there a possibility to figure out at runtime wich table a ForeignKey refers 
to?

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com

Gmane