Federico Di Gregorio | 1 Nov 01:17 2004

Re: MySQLdb DictCursor class

Il giorno ven, 29-10-2004 alle 22:25 -0400, Ed Leafe ha scritto:
> > def getDictCursorClass(self):
> > 		import MySQLdb.cursors as cursors
> > 		return cursors.DictCursor
> 
> 	To make the question even simpler: when you do the following in 
> psycopg:
> 
> import psycopg
> dsn = ...
> conn = psycopg.connect(dsn)
> crs = conn.cursor()
> 
> 	What is the class of 'crs' in the above? More specifically, how would 
> it be referenced if a subclass were to be defined that used that class?

in psycopg 1.1 cursors and connections can't be subclassed. in psycopg 2
you can subclass both and pass a 'factory' argument to the right
function to have the engine instantiate objects of your type instead of
the standard type. the types 'connection' and 'cursor' are in
psycopg.extensions and the methods involved are:

	psycopg.connect(dsn, ..., factory=connection_class)
	conn.cursor(factory=cursor_class)

hope this helps,
federico
John Fabiani | 2 Nov 03:35 2004

Code does not work..is this a bug?

This may be a bug?
The code works correctly from psql also pgAdminIII but not from python.  SUSE 
9.1 x86_64 , Python 2.3.3.  As you can see I'm using 1.99.10 (but it did not 
work with 1.1.15 either) Postgres 7.4.2

import psycopg
dsn= ......
conn = psycopg.connect(dsn)
crs = conn.cursor()
tablename = 'mytest'
crs.execute("SELECT cc.column_name AS fieldname, cc.data_type AS fieldtype, \
COALESCE(i.indisprimary,FALSE) AS is_pkey \
FROM information_schema.columns cc \
LEFT JOIN information_schema.key_column_usage cu \
ON (cc.table_name=cu.table_name AND cc.column_name=cu.column_name) \
LEFT JOIN pg_class cl ON(cl.relname=cu.table_name) \
LEFT JOIN pg_index i ON(cl.oid= i.indrelid) WHERE c.table_name= %s" % 
tablename)
rs=crs.fetchall()
print rs

sys:1: DeprecationWarning: Non-ASCII character '\xc2' in file newtest.py on 
line 6, but no encoding declared; see 
http://www.python.org/peps/pep-0263.html for details
[8817] initpsycopg: initializing psycopg 1.99.10
[8817] typecast_init: initializing NUMBER
[8817] typecast_new: typecast object created at 0x2a955d5900
[8817] typecast_add: object at 0x2a955d5900, values refcnt = 2
[8817] typecast_add:     adding val: 20
[8817] typecast_add:     adding val: 23
(Continue reading)

Federico Di Gregorio | 2 Nov 14:49 2004

Re: Code does not work..is this a bug?

On Mon, 2004-11-01 at 18:35 -0800, John Fabiani wrote:
> This may be a bug?
> The code works correctly from psql also pgAdminIII but not from python.  SUSE 
> 9.1 x86_64 , Python 2.3.3.  As you can see I'm using 1.99.10 (but it did not 
> work with 1.1.15 either) Postgres 7.4.2
[snip]
> sys:1: DeprecationWarning: Non-ASCII character '\xc2' in file newtest.py on 
                                                 ^^^^^^
> line 6, but no encoding declared; see 
> Traceback (most recent call last):
>   File "newtest.py", line 6, in ?
>     crs.execute("SELECT cc.column_name AS fieldname,cc.data_type AS 
> fieldtype, \
> psycopg.ProgrammingError: relation " cc" does not exist
                                      ^^^

note the space before cc and the warning issued by python. for some
reason you have a spurious character in your query.

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
                             Best friends are often failed lovers. -- Me
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
(Continue reading)

John Fabiani | 2 Nov 17:40 2004

Re: Code does not work..is this a bug?

On Tuesday 02 November 2004 05:49, Federico Di Gregorio wrote:

> > line 6, but no encoding declared; see
> > Traceback (most recent call last):
> >   File "newtest.py", line 6, in ?
> >     crs.execute("SELECT cc.column_name AS fieldname,cc.data_type AS
> > fieldtype, \
> > psycopg.ProgrammingError: relation " cc" does not exist
>
>                                       ^^^
>
> note the space before cc and the warning issued by python. for some
> reason you have a spurious character in your query.

OK but I have three different editors and none of them show that space.  I 
also checked using vi (no space).  Please check my example code on your 
system.  Just change the DSN and the table name it should work on anything 
7.4.x.  BTW I take the select code below and paste directly into the psql 
command line and it works.  Assume for the moment that I have the spacing 
correct is there anyway to get around the error?

import psycopg
dsn= 'host=192.168.1.211 dbname=testpg user=johnf password=jfabiani '
#conn=PgSQL.connect(dsn='192.168.1.211',user='johnf',password='jfabiani',database='testpg')
conn = psycopg.connect(dsn)
crs = conn.cursor()
tablename = 'mytest'
crs.execute("SELECT c.column_name AS fieldname, c.data_type AS 
fieldtype,i.indisprimary AS is_pkey FROM information_schema.columns c LEFT 
JOIN information_schema.key_column_usage cu ON (c.table_name=cu.table_name 
(Continue reading)

Stian Søiland | 2 Nov 18:21 2004
Picon

Re: Code does not work..is this a bug?

On 2004-11-02 17:40:39, John Fabiani wrote:

> OK but I have three different editors and none of them show that space.  I 

Just delete line 6 and rewrite it by hand, not cut-and-paste.  Looks
like you have some unicode character in your source code.

>>> print '\xc2'
Â

Thats ^ + A

--

-- 
Stian Søiland               Work toward win-win situation. Win-lose
Trondheim, Norway           is where you win and the other lose.
http://www.soiland.no/      Lose-lose and lose-win are left as an
                            exercise to the reader.  [Limoncelli/Hogan]
                            Og dette er en ekstra linje 
John Fabiani | 2 Nov 18:34 2004

Re: Code does not work..is this a bug?

On Tuesday 02 November 2004 09:21, you wrote:
> On 2004-11-02 17:40:39, John Fabiani wrote:
> > OK but I have three different editors and none of them show that space. 
> > I
>
> Just delete line 6 and rewrite it by hand, not cut-and-paste.  Looks
> like you have some unicode character in your source code.
>
> >>> print '\xc2'
>
> Â
>
> Thats ^ + A

Thanks it ever occurred to me that I had somesort of hidden char in the code. 
Although that's exactly what the error message said.  That fixed it...  

John
Culley Harrelson | 5 Nov 01:58 2004
Picon

freebsd port problems

I just tried to install psycopg from the freebsd port.  I have these
versions installed:

py23-mx-base-2.0.5          =  up-to-date with port
py23-psycopg-1.1.15         >  succeeds port (port has 1.1.9_1)
python-2.3.4_2              >  succeeds port (port has 2.3.3_5)

When I try to import psycopg I get:

Traceback (most recent call last):
  File "test.py", line 1, in ?
    import psycopg
ImportError: /usr/local/lib/python2.3/site-packages/psycopgmodule.so:
Undefined symbol "pthread_mutex_unlock"

Is this saying that I have python complied inproperly?

culley
dick | 5 Nov 09:51 2004
Picon

unexpected EOF on client connection

Hi list,

I am using psycopg (1.1.15) with Python 2.3.3 and Postgresql 7.4 in a fairly 
big application. In that application I am (also) manipulating the database. 
(Alter table etc.) The coding is working properly, but sometimes the 
connection to the database breaks and the application hangs. I have 
experienced this on several machines. The weird thing is that after a break 
in my application pgAdmin3 is hanging also. This would indicate a problem in 
Postgresql, but I don't know. When I look in Postgresql.log I get the 
following message:

LOG:  unexpected EOF on client connection

but it doesn't specify a time and date, so I THINK this indicates my problem, 
but I am not sure. (I do not see any other errors in the log)

Does this indicate an error in psycopg? Or is there something else going on? 
How can I find out what is happening? (client crash, server problem?)
--

-- 
Cheers

Dick Kniep
Lindix BV
Terje Elde | 5 Nov 12:29 2004
Picon

Re: freebsd port problems

On Thu, Nov 04, 2004 at 04:58:10PM -0800, Culley Harrelson wrote:
> Is this saying that I have python complied inproperly?

Hi,

Sounds like it.

Run 'make config' in the port, and make sure threads are enabled.
Recompile/reinstall, and you should be fine.

Terje
Culley Harrelson | 5 Nov 20:18 2004
Picon

Re: freebsd port problems

Unfortunately mod_python 2.7.8 requires threads to be disabled.  This
must be a freebsd issue.  I have mod_pythong 2.7.8 + psycopg 1.1.15
working on my development system (OS X).  That will teach me to start
development before making sure I can even install the software in
production!  But this doesn't really belong on this list-- off to talk
to the mod_python guys...

culley

> Sounds like it.
> 
> Run 'make config' in the port, and make sure threads are enabled.
> Recompile/reinstall, and you should be fine.
> 
> Terje
> 
>

Gmane