Re: [PDO-Users]pdo/pgdb insert
pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Wed, 21 Jan 2004 12:53:15 -0500
| Newsgroups | gmane.comp.python.db.pdo.user |
|---|---|
| Message-ID | <002301c3e047$729800d0$8401a8c0@letterbox1> |
Ok, that makes sense, so pgdb is not in autocommit mode.
Hrm, I think we'll add a method at the connect object level
to toggle whether to autocommit (as your mod does), and another
method to allow for explicit commits.
I'll make the changes to the new version, and backport to the version
on the site and do a minor update to 1.2.2 - that way people don't
have to wait until ver 1.3 (which we are still working on) to have
a solution to this issue.
----- Original Message -----
From: <pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
To: <pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>;
<pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>;
<pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Sent: Wednesday, January 21, 2004 10:09 AM
Subject: Re: [PDO-Users]pdo/pgdb insert
> Hi,
>
> I did abit more testing and it seems it is just not calling
> commit() after an update/insert. I changed these 2 classes
> in pdo.py by just adding a commit line and it works. The
> affected rows is still 'None' because pgdb doesn't return
> the affected rows when executing a statement..
> This is just a temporary fix and I guess it would cause
> incompatibility with other db's now.
>
> #class 1
> class ParamExecute:
> def __init__(self, parent, Statement, Params):
> self.__cursor = parent.db.cursor()
> try:
> self.affected_rows =
> self.__cursor.execute(Statement, Params)
> parent.db.commit() #line added
> except:
> raise pdo_param_execute_error,
> "Paramater-enabled Execute Error: Database specific Error:"
> + str(sys.exc_type) + "\n" + str(sys.exc_value)
> self.affected_rows = 0
>
>
> #class 2 changed
>
> class SimpleExecute:
> def __init__(self, parent, Statement):
> self.__cursor = parent.db.cursor()
> try:
> self.affected_rows =
> self.__cursor.execute(Statement)
> parent.db.commit() #line added
> except:
> raise pdo_simple_execute_error, "Simple Execute
> Error: Database specific Error:" + str(sys.exc_type) + "\n"
> + str(sys.exc_value)
> self.affected_rows = 0
>
> Cheers,
> Eugene.
>
> On Wed, 21 Jan 2004 08:49:45 +0200
> pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org wrote:
> > Hi,
> >
> > Thanks very much for the help!!
> > Here is the script I'm using, I'm running python 2.3 and
> > postgresql 7.3.3 compiled with gcc 3.2. For testing it
> > uses
> > a table called 'users' in db 'vv'(username=postgres,
> > password=postgres) with 2 fields('username' and
> > 'password'). There is one record('root', 'root')
> > - Another question, is there any way to get the error
> > number and message when a exception is raised..
> >
> > Here is the class file with test statements.
> >
> > # script start
> >
> > import pgdb
> > import pdo
> > import sys
> >
> >
> > class database:
> >
> > host='localhost'
> > username='postgres'
> > password='postgres'
> > db='vv'
> >
> > def connect(self):
> > try:
> >
>
self.dbConnection=pdo.connect("Module=pgdb;user="+self.username+";passwd="+s
elf.password+";db="+self.db)
> > except pdo.pdo_connection_error:
> > print "Couldn't connect to
> > database"
> >
> >
> >
> > def query(self, statement, param):
> > try:
> >
> result=self.dbConnection.open(statement,
> > param)
> > return result
> > except pdo.pdo_resultset_error:
> > print "Couldn't get resultset"
> >
> >
> > def update(self, statement, param):
> > try:
> >
> >
> result=self.dbConnection.execute(statement,
> > param)
> > return result
> > except pdo.pdo_param_execute_error:
> > print "Couldn't update: "
> >
> >
> > def close(self):
> > self.dbConnection.close()
> >
> >
> > if __name__=="__main__":
> > db=database()
> > db.connect()
> > username="root"
> > password="root"
> > statement="select * from users where username=%s
> > and password=%s"
> > result=db.query(statement, [username, password])
> > print result.row_count() # this works with
> > printing 1
> >
> > statement="insert into users values ('B', 'B')"
> > print db.update(statement, line).affected_rows #
> > this doesn't raise exception and returns None
> > db.close()
> >
> > #ends script
> >
> >
> > Thanks again!!!
> > Eugene.
> > On Tue, 20 Jan 2004 11:10:56 -0500
> > pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org wrote:
> > > We'll look into this today - can you give us some more
> > > info
> > > so that we can reproduce your setup as much as
> > possible?
> > >
> > > ~Jon Franz
> > > NeuroKode Labs, LLC
> > >
> > > ----- Original Message -----
> > > From: <pythondbo-users-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> > > To: <pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> > > Sent: Tuesday, January 20, 2004 7:16 AM
> > > Subject: [PDO-Users]pdo/pgdb insert
> > >
> > >
> > > > Hi,
> > > >
> > > > I'm sitting with a problem where I can select but not
> > > > insert/update to a postgresql database using pdo.
> > Here
> > > is
> > > > the statement:
> > > > result=self.dbConnection.execute("insert into users
> > > values
> > > > ('B', 'B')")
> > > > It doesn't raise an exception and if I check
> > > > result.affected_rows it is 'None'
> > > > If I execute the statement on the psql command line
> > it
> > > > works fine and inserts..
> > > >
> > > > Thanks for the help...
> > > > Eugene
> > > >
> > > > ___________________________________________
> > > > Look Good, Feel Good www.healthiest.co.za
> > > >
> > > >
> > > >
> > > >
> > -------------------------------------------------------
> > > > The SF.Net email is sponsored by EclipseCon 2004
> > > > Premiere Conference on Open Tools Development and
> > > Integration
> > > > See the breadth of Eclipse activity. February 3-5 in
> > > Anaheim, CA.
> > > > http://www.eclipsecon.org/osdn
> > > > _______________________________________________
> > > > Pythondbo-users mailing list
> > > > Pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> > > >
> > >
> >
> https://lists.sourceforge.net/lists/listinfo/pythondbo-users
> > > >
> > >
> > >
> > > -------------------------------------------------------
> > > The SF.Net email is sponsored by EclipseCon 2004
> > > Premiere Conference on Open Tools Development and
> > > Integration
> > > See the breadth of Eclipse activity. February 3-5 in
> > > Anaheim, CA.
> > > http://www.eclipsecon.org/osdn
> > > _______________________________________________
> > > Pythondbo-users mailing list
> > > Pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> > >
> >
> https://lists.sourceforge.net/lists/listinfo/pythondbo-users
> >
> > ___________________________________________
> > Look Good, Feel Good www.healthiest.co.za
> >
> >
> >
> > -------------------------------------------------------
> > The SF.Net email is sponsored by EclipseCon 2004
> > Premiere Conference on Open Tools Development and
> > Integration
> > See the breadth of Eclipse activity. February 3-5 in
> > Anaheim, CA.
> > http://www.eclipsecon.org/osdn
> > _______________________________________________
> > Pythondbo-users mailing list
> > Pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> >
> https://lists.sourceforge.net/lists/listinfo/pythondbo-users
>
> ______________________________________________________________
> http://www.webmail.co.za the South African FREE email service
>
>
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration
> See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
> http://www.eclipsecon.org/osdn
> _______________________________________________
> Pythondbo-users mailing list
> Pythondbo-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/pythondbo-users
>
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn