Oleg Broytmann | 3 Jun 10:42
X-Face
Picon
Favicon

Vacation

Hi, all! I am leaving the town for a vacation. Will be back 20 June. Please
help each other in the list.

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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Diez B. Roggisch | 3 Jun 15:45
Picon

Re: Vacation

On Tuesday 03 June 2008 10:42:41 Oleg Broytmann wrote:
> Hi, all! I am leaving the town for a vacation. Will be back 20 June. Please
> help each other in the list.

Have fun :)

Diez

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Oleg Broytmann | 3 Jun 15:49
X-Face
Picon
Favicon

Re: Vacation

On Tue, Jun 03, 2008 at 03:45:03PM +0200, Diez B. Roggisch wrote:
> On Tuesday 03 June 2008 10:42:41 Oleg Broytmann wrote:
> > Hi, all! I am leaving the town for a vacation. Will be back 20 June. Please
> > help each other in the list.
> 
> Have fun :)
> 
> Diez

   Thanks to you and to all!

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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Sam's Lists | 4 Jun 07:34
Picon
Gravatar

Having trouble with queryall under postgresql...

This used to work pretty well under mysql but I'm now having trouble with the following under postgresql:

#!/usr/bin/env python

import sqlobject
connection = sqlobject.connectionForURI("postgres://connection_string_here")
sqlobject.sqlhub.processConnection = connection

def qa(query):
    print "\tRunnng query: ", query
    return connection.queryAll(query)
    print

qa("drop table the_wines_backup")

-----

Now it does drop the table, so that's good.  But it also errors out with this error message:

  Runnng query:  drop table the_wines_backup
Traceback (most recent call last):
  File "./adjustdb.py", line 13, in <module>
    qa("drop table the_wines_backup")
  File "./adjustdb.py", line 10, in qa
    return connection.queryAll(query)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py", line 350, in queryAll
    return self._runWithConnection(self._queryAll, s)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py", line 250, in _runWithConnection
    val = meth(conn, *args)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py", line 344, in _queryAll
    value = c.fetchall()
psycopg2.ProgrammingError: no results to fetch


Any ideas what's wrong? 

Thanks

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
jonhattan | 7 Jun 11:11
Favicon

Re: Having trouble with queryall under postgresql...

Sam's Lists escribió:
> This used to work pretty well under mysql but I'm now having trouble
> with the following under postgresql:
>
> #!/usr/bin/env python
>
> import sqlobject
> connection =
> sqlobject.connectionForURI("postgres://connection_string_here")
> sqlobject.sqlhub.processConnection = connection
>
> def qa(query):
>     print "\tRunnng query: ", query
>     return connection.queryAll(query)
>     print
>
> qa("drop table the_wines_backup")
>
> -----
>
> Now it does drop the table, so that's good.  But it also errors out
> with this error message:
>
>   Runnng query:  drop table the_wines_backup
> Traceback (most recent call last):
>   File "./adjustdb.py", line 13, in <module>
>     qa("drop table the_wines_backup")
>   File "./adjustdb.py", line 10, in qa
>     return connection.queryAll(query)
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py",
> line 350, in queryAll
>     return self._runWithConnection(self._queryAll, s)
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py",
> line 250, in _runWithConnection
>     val = meth(conn, *args)
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py",
> line 344, in _queryAll
>     value = c.fetchall()
> psycopg2.ProgrammingError: no results to fetch
>
>
> Any ideas what's wrong? 

The error is "no results to fetch", due you perform a drop table
statement, that does not retrieve any data. For this kind of operations
you can use connection.query() instead of queryAll(). It seems the only
difference between both is that queryAll also fetch the (assumed that
there exist) results.

-- jonhattan

>
> Thanks
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> ------------------------------------------------------------------------
>
> _______________________________________________
> sqlobject-discuss mailing list
> sqlobject-discuss <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>   

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Nick Murdoch | 9 Jun 12:46
Favicon

backslash escaping in postgresql 8.3

Hi everyone,

I'm having trouble with backslash escapes in PostgreSQL 8.3 and SQLObject.

I currently have a Resource class that looks like:

class Resource(SQLObject):
     resource = UnicodeCol(unique=True)

     @classmethod
     def autocomplete(cls, input):
         """ Controller for the autocomplete widget. """
         return cls.select(cls.q.resource.startswith(input))

If I call Resource.autocomplete('blah'), the following statement is  
generated:

SELECT collateral.id, collateral.resource, collateral.description,  
collateral.icon FROM collateral WHERE ((collateral.resource) LIKE  
('blah%'))

That works great, but if I call it with r'\', like so, I get an error from  
postgres:

2008-06-09 11:43:21 BST WARNING:  nonstandard use of \\ in a string  
literal at character 135
2008-06-09 11:43:21 BST HINT:  Use the escape string syntax for  
backslashes, e.g., E'\\'.
2008-06-09 11:43:21 BST LOG:  statement: SELECT collateral.id,  
collateral.resource, collateral.description, collateral.icon FROM  
collateral WHERE ((collateral.resource) LIKE ('\\%'))

and no records are returned, despite there being records in the table  
starting with '\'. Currently I'm working around this by duplicating the  
backslash in python, which generates the same error from postgres but  
actually returns records beginning with a single backslash. It looks like  
postgres has a special E'' syntax for escaping which I don't entirely  
understand, but would it make sense for SQLObject to be using that in the  
future?

Thanks,

Nick

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Diez B. Roggisch | 9 Jun 12:54
Picon

Re: backslash escaping in postgresql 8.3

> Currently I'm working around this by duplicating the
> backslash in python, which generates the same error from postgres but
> actually returns records beginning with a single backslash. It looks like
> postgres has a special E'' syntax for escaping which I don't entirely
> understand, but would it make sense for SQLObject to be using that in the
> future?

I'm actually less than satisfied with the way SO currently deals with 
parameters - because it essentially does the escaping itself, and then 
creates full SQL-statements.

The better way to go would of course be to use the parametrized version of 
cursor.execute, which should shift the problem (if it persisted) to the 
db-adapter itself. 

However, this would mean a rather major rewrite of sqlbuilder. Yet I do 
believe it's worth it, because otherwise we open up for SQL injection attacks 
and similar problems.

Diez

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Fred C | 12 Jun 20:20
Picon

Problem with a related join.


Hello Gang,

I am trying to create a related join with a creation date. After digging on google. I found an example looking a little bit like that.


class Tags(SQLObject):
    term = UnicodeCol(length=64, alternateID=True,
              alternateMethodName='by_term')    
    articles = SQLRelatedJoin("Article", intermediateTable="article_tag",
                      createRelatedTable=False,
                      joinColumn="tag_id", otherColumn="article_id")

class ArticleTag(SQLObject):
    class sqlmeta:
        table = "article_tag"

    article = ForeignKey('Article', notNull=True, cascade=True)
    tag = ForeignKey('Tags', notNull=True, cascade=True)

    created = DateTimeCol(default=datetime.now)

    unique = index.DatabaseIndex(article, tag, unique=True)


The problem is that when the record is created for the table article_tag the created field is not set to the default. Is there something obvious I am missing or is what am am doing not possible ?


>>> a = Article.get(139)
>>> list(a.tags)
[]
>>> t=Tags(term='foobar')
>>> t.addArticle(a)
 1/Query   :  INSERT INTO article_tag (tag_id, article_id) VALUES (929, 139)
 1/QueryR  :  INSERT INTO article_tag (tag_id, article_id) VALUES (929, 139)
>>>
>>> # the insert doesn't include the field "created"
>>>
>>> for at in ArticleTag.selectBy(articleID=139):
...     print at
... 
 1/Select  :  SELECT article_tag.id, article_tag.article_id, article_tag.tag_id, article_tag.created FROM article_tag WHERE article_id = 139
 1/QueryR  :  SELECT article_tag.id, article_tag.article_id, article_tag.tag_id, article_tag.created FROM article_tag WHERE article_id = 139
<ArticleTag 1461 articleID=139 tagID=929 created=None>
>>> 

Thanks for your suggestions. 
-fred-


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Simon Cross | 13 Jun 14:58
Picon

Re: Problem with a related join.

Hi Fred,

On Thu, Jun 12, 2008 at 8:20 PM, Fred C <bsdhost <at> gmail.com> wrote:
> I am trying to create a related join with a creation date. After digging on
> google. I found an example looking a little bit like that.

Despite the example in the FAQ [1] it looks like this isn't directly
supported by SQLObject at all. t.addArticle(...) goes straight to the
.add(...) method on the underlying join object which bypasses the
intermediate table class entirely and uses just the table and column
names and the two IDs.

It is how ever possible to get the desired effect if the underlying
database allows it. For example, if using SQLite one can do:

    created = DateTimeCol(defaultSQL="CURRENT_TIMESTAMP")

and then the database itself will add the necessary information when
the row is created (and you can access this via ArticleTag instances
as expected).

[1] http://www.sqlobject.org/FAQ.html#how-can-i-define-my-own-intermediate-table-in-my-many-to-many-relationship

Schiavo
Simon

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Diez B. Roggisch | 16 Jun 11:13
Picon

Re: Problem with a related join.

> The problem is that when the record is created for the table
> article_tag the created field is not set to the default. Is there
> something obvious I am missing or is what am am doing not possible ?

Not in that way, no. A bit unfortunately, SO has no concept of declaration for 
intermediate tables - they are a bit the orpahns of SO.

What you can of course do is to 

 - declare the intermediate table with two ForeignKey-columns
 - create the accessors for both sides on the related tables yourself, like 
this:

class Foo(..):

   @property
   def bars(self):
         return list(Bar.select(AND(IntermediatTable.q.foo == self, 
IntermediatTable.q.bar_id == Bar.q.id)))

And of course add/remove-methods. Not really that much work, and you end up 
with an intermediate table with arbitrary attributes.

Diez

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

Gmane