Davide Alberani | 3 Jan 14:32
Picon
Gravatar

problem setting charset for a postgresql db (psycopg2)

I'm probably missing something very simple. :-)
SQLObject from the SVN (but also 0.12), psycopg2 2.0.13, Python 2.5,
Postgresql 8.4.2 on a Debian sid.

Test code:
===================================================
from sqlobject import *

connection = connectionForURI('postgres://root:q1w2e3 <at> localhost/imdb?charset=UTF-8')

class TestTableName(SQLObject):
    testColName = StringCol()

TestTableName.setConnection(connection)
TestTableName.createTable(True)
===================================================


Error:
===================================================
Traceback (most recent call last):
  File "./pino", line 13, in <module>
    TestTableName.createTable(True)
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/main.py", line 1404, in createTable
    if ifNotExists and cls.tableExists(connection=conn):
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/main.py", line 1378, in tableExists
    return conn.tableExists(cls.sqlmeta.table)
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/postgres/pgconnection.py", line 191, in tableExists
    % self.sqlrepr(tableName))
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/dbconnection.py", line 392, in queryOne
    return self._runWithConnection(self._queryOne, s)
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/dbconnection.py", line 260, in _runWithConnection
    conn = self.getConnection()
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/dbconnection.py", line 271, in getConnection
    conn = self.makeConnection()
  File "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/postgres/pgconnection.py", line 139, in makeConnection
    conn.query("SET client_encoding TO %s" % dbEncoding)
AttributeError: 'psycopg2._psycopg.connection' object has no attribute 'query'
===================================================



Thanks in advance!
--
Davide Alberani <da <at> mimante.net>  [PGP KeyID: 0x465BFD47]
http://www.mimante.net/

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 3 Jan 15:15
X-Face
Picon
Favicon

Re: problem setting charset for a postgresql db (psycopg2)

On Sun, Jan 03, 2010 at 02:32:06PM +0100, Davide Alberani wrote:
>     conn.query("SET client_encoding TO %s" % dbEncoding)
> AttributeError: 'psycopg2._psycopg.connection' object has no attribute
> 'query'

   The bug has already been reported in the SF tracker. I will fix it RSN.

Oleg.
--

-- 
     Oleg Broytman            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 the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Oleg Broytman | 6 Jan 16:47
X-Face
Picon
Favicon

Re: problem setting charset for a postgresql db (psycopg2)

On Sun, Jan 03, 2010 at 02:32:06PM +0100, Davide Alberani wrote:
>   File
> "/home/da/develop/lib/python2.5/site-packages/SQLObject-0.13dev_r4066-py2.5.egg/sqlobject/postgres/pgconnection.py",
> line 139, in makeConnection
>     conn.query("SET client_encoding TO %s" % dbEncoding)
> AttributeError: 'psycopg2._psycopg.connection' object has no attribute
> 'query'

   Fixed in the revisions 4067, 4068 (branch 0.12 and the trunk.)

Oleg.
--

-- 
     Oleg Broytman            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 the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Oleg Broytman | 8 Jan 13:45
X-Face
Picon
Favicon

SQLObject 0.12.1

Hello!

I'm pleased to announce version 0.12.1, a bugfix release of branch 0.12
of SQLObject.

What is SQLObject
=================

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Where is SQLObject
==================

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.12.1

News and changes:
http://sqlobject.org/News.html

What's New
==========

News since 0.12.0
-----------------

* The cache culling algorithm was enhanced to eliminate memory leaks by
  removing references to dead objects; tested on a website that runs around
  4 million requests a day.

* Fixed a bug in col.py and dbconnection.py - if dbEncoding is None suppose
  it's 'ascii'.

* Fixed three bugs in PostgresConnection.

* Fixed a bug in FirebirdConnection.

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
--

-- 
     Oleg Broytman            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 the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Oleg Broytman | 8 Jan 13:43
X-Face
Picon
Favicon

SQLObject 0.11.3

Hello!

I'm pleased to announce version 0.11.3, a minor bugfix release of 0.11 branch
of SQLObject.

What is SQLObject
=================

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Where is SQLObject
==================

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.11.3

News and changes:
http://sqlobject.org/News.html

What's New
==========

News since 0.11.2
-----------------

* The cache culling algorithm was enhanced to eliminate memory leaks by
  removing references to dead objects; tested on a website that runs around
  4 million requests a day.

* Fixed a bug in col.py and dbconnection.py - if dbEncoding is None suppose
  it's 'ascii'.

* Fixed a bug in FirebirdConnection.

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
--

-- 
     Oleg Broytman            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 the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Markus Gritsch | 8 Jan 18:58
Picon
Gravatar

Re: SQLObject 0.12.1

Hmm,

I just diffed 0.12.0 with 0.12.1.  I saw the 'ascii' change and
changes in Postgres and Firebird Connection, but either I overlooked
it, or there is no change regarding the cache culling algorithm.

Are you sure it made it into the release?

Kind regards,
Markus

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Oleg Broytman | 8 Jan 22:21
X-Face
Picon
Favicon

Re: SQLObject 0.12.1

On Fri, Jan 08, 2010 at 06:58:25PM +0100, Markus Gritsch wrote:
> I just diffed 0.12.0 with 0.12.1.  I saw the 'ascii' change and
> changes in Postgres and Firebird Connection, but either I overlooked
> it, or there is no change regarding the cache culling algorithm.
> 
> Are you sure it made it into the release?

   Yes, commits 4028-4030 (branches 0.10, 0.11, and the trunk). It was at
October 9:

http://sourceforge.net/mailarchive/forum.php?thread_name=E1MwHJk-0000Rj-00%40webwareforpython.org&forum_name=sqlobject-cvs
http://sourceforge.net/mailarchive/forum.php?thread_name=E1MwHMU-0000VM-00%40webwareforpython.org&forum_name=sqlobject-cvs
http://sourceforge.net/mailarchive/forum.php?thread_name=E1MwHO6-0000XY-00%40webwareforpython.org&forum_name=sqlobject-cvs

   Aha, I see, the new algorithm was in 0.12.0 - it was released at Oct 20.
The trunk became branch 0.12. Seems I have forgotten to include the change
in the announcement.

   And I forgot to put the date in today releases. I need to write down the
checklist.

Oleg.
--

-- 
     Oleg Broytman            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 the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Oleg Broytman | 15 Jan 17:16
X-Face
Picon
Favicon

Re: PATCH: adds support for an interval timedelta column

Hello!

On Wed, May 13, 2009 at 07:11:22PM +0000, Matthew Wilson wrote:
> Hi -- I wrote some code to add a TimedeltaCol type.  I only tested it in
> postgresql.

   I applied both your patches to the trunk, commit 4088. Thank you! Sorry
it took so long.

> By the way, how do I write a converter that converts a python object one
> way for one database (sqlite) and another way for another database
> (postgres)?  Are there any examples of this already?

> +def TimedeltaConverter(value, db):
> +    
> +    return """INTERVAL '%d days %d seconds'""" % \
> +        (value.days, value.seconds)

   db is the name of the database. See StringLikeConverter for an example.

Oleg.
--

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

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
Oleg Broytman | 22 Jan 19:57
X-Face
Picon
Favicon

Re: FW: longId=True handling...

Hello! I returned to investigate the issue and found it's more complex than
I thought...

On Thu, Jun 11, 2009 at 10:11:27AM -0400, Joe Lanese wrote:
> This issue seems to be caused by a change in SQLObject.
> The change in behaviour seems to be due to a change made in SQLObject in
> main.py, where the ?idName? attribute was taken out of a list of unshared
> attributes.  This caused the sqlmeta class to share the idName value with
> its containing class, so they both end up with ?id? even when longID is set
> to true in your own class.  If you add it back in:
> _unshared_attributes = ['table', 'columns', 'childName', 'idName']
> then it should work as before...however, I'm not sure if this will cause
> other problems (so far it seems to work).
> 
> By the way, here is a link to a change that seems to have triggered this
> change in behaviour:
> http://www.mail-archive.com/sqlobject-discuss <at> lists.sourceforge.net/msg02159.html

   In essence, the problem is in class sqlmeta, method setClass:

        if cls.idName is None:
            cls.idName = cls.style.idForTable(cls.table)

   The method poises the class so in any class inherited from sqlmeta idName
will be already set and the test fails.
   Adding idName to the list of unshared attributes resets idName to None
but that prevents proper inheritance of idName.
   To explain all this with code - with current SQLObject the following
code

class sqlmeta(sqlmeta):
    idName = 'ddd'

class Test1(SQLObject):
    class sqlmeta(sqlmeta):
        style = MixedCaseStyle(longID=True)

Test1.createTable()

print Test1.sqlmeta.idName

class Test2(SQLObject):
    class sqlmeta:
        style = MixedCaseStyle(longID=True)

Test2.createTable()

print Test2.sqlmeta.idName

   prints 'ddd' and 'id'; the first idName is right and the second one is
wrong (it must be 'Test2ID').
   The same code running with idName added to the list of unshared attributes
prints 'Test1ID' and 'Test2ID'; the first one is wrong (it must be 'ddd')
and the second one is right.
   Probably the correct way of fixing it is to add idName (and 'style'
because setClass tests and sets it too) to the list of unshared attributes
but make sqlmeta.__classinit__ to recognize inherited attributes and do not
reset them. I will think of it...

Oleg.
--

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

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
Sophana K | 25 Jan 18:34
Picon

Re: This transaction has already gone through ROLLBACK

Hi

I still haven't resolved my rollback assert problem which happens
about once per month.
But I have gathered some tracebacks.
In all cases, it looks like Transaction.__getattr__ gets called at
places I don't understand.
Maybe tracebacks are corrupted?
If someone has a clue where to look at, it would be nice.
I don't understand very well what is the function of the
Transaction.__getattr__ method.

Thanks for your help.

File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 866, in doInTransaction
   conn = old_conn.transaction()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 398, in transaction
   return Transaction(self)
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 681, in __init__
   self._connection = dbConnection.getConnection()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 281, in getConnection
   self._poolLock.release()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 764, in __getattr__
   self.assertActive()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 688, in assertActive
   assert not self._obsolete, "This transaction has already gone
through ROLLBACK; begin another transaction"
AssertionError: This transaction has already gone through ROLLBACK;
begin another transaction

Here getattr is called in self._poolLock.release() inside a DBAPI
method: getConnection
self is a DBAPI instance.
I don't see why the Transaction.__getattr__ gets called.

File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 878, in doInTransaction
   conn.commit(close=True)
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 729, in commit
   if self._dbConnection.debug:
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 764, in __getattr__
   self.assertActive()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.3-py2.5.egg/sqlobject/dbconnection.py",
line 688, in assertActive
   assert not self._obsolete, "This transaction has already gone
through ROLLBACK; begin another transaction"
AssertionError: This transaction has already gone through ROLLBACK;
begin another transaction

here getattr is called in self._dbConnection.debug
self is a Transaction. Maybe _dbConnection doesn't exist anymore?

File "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py",
line 856, in doInTransaction
   conn = old_conn.transaction()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py",
line 754, in __getattr__
   self.assertActive()
 File "/usr/lib/python2.5/site-packages/SQLObject-0.10.2-py2.5.egg/sqlobject/dbconnection.py",
line 678, in assertActive
   assert not self._obsolete, "This transaction has already gone
through ROLLBACK; begin another transaction"
AssertionError: This transaction has already gone through ROLLBACK;
begin another transaction

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev

Gmane