Re: Context manager for database connection

2023-08-23 Thread dn via Python-list
On 24/08/2023 06.11, dn via Python-list wrote: On 24/08/2023 03.41, Jason Friedman via Python-list wrote: with Database() as mydb: conn = mydb.get_connection() cursor = conn.get_cursor() cursor.execute("update table1 set x = 1 where y = 2") cursor.close() cursor = conn.get_cursor() cursor.execut

Re: Context manager for database connection

2023-08-23 Thread dn via Python-list
On 24/08/2023 03.41, Jason Friedman via Python-list wrote: I want to be able to write code like this: with Database() as mydb: conn = mydb.get_connection() cursor = conn.get_cursor() cursor.execute("update table1 set x = 1 where y = 2") cursor.close() cursor = conn.get_cursor() cursor.execute("u

Context manager for database connection

2023-08-23 Thread Jason Friedman via Python-list
I want to be able to write code like this: with Database() as mydb: conn = mydb.get_connection() cursor = conn.get_cursor() cursor.execute("update table1 set x = 1 where y = 2") cursor.close() cursor = conn.get_cursor() cursor.execute("update table2 set a = 1 where b = 2") cursor.close() I'd like

Re: Best practice for database connection

2023-05-31 Thread dn via Python-list
On 01/06/2023 06.45, Thomas Passin wrote: On 5/31/2023 2:10 PM, Jason Friedman wrote: I'm trying to reconcile two best practices which seem to conflict. 1) Use a _with_ clause when connecting to a database so the connection is closed in case of premature exit. class_name = 'oracle.jdbc.OracleD

Re: Best practice for database connection

2023-05-31 Thread Thomas Passin
On 5/31/2023 2:10 PM, Jason Friedman wrote: I'm trying to reconcile two best practices which seem to conflict. 1) Use a _with_ clause when connecting to a database so the connection is closed in case of premature exit. class_name = 'oracle.jdbc.OracleDriver' url = f"jdbc:oracle:thin:@//{host_na

Best practice for database connection

2023-05-31 Thread Jason Friedman
I'm trying to reconcile two best practices which seem to conflict. 1) Use a _with_ clause when connecting to a database so the connection is closed in case of premature exit. class_name = 'oracle.jdbc.OracleDriver' url = f"jdbc:oracle:thin:@//{host_name}:{port_number}/{database_name}" with jdbc.c

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sat, 21 Feb 2015 16:22:36 +0100, Peter Otten <__pete...@web.de> wrote: > >Why would you care about a few lines? You don't repeat them, do you? Put the >code into a function or a context manager and invoke it with Thanks for the suggestions that followed. -- https://mail.python.org/mailman/li

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sun, 22 Feb 2015 13:15:09 -0600, Skip Montanaro wrote: > >Sorry, I haven't paid careful attention to this thread, so perhaps >this has already been suggested, however... Can't you write your own >class which delegates to the necessary sqlite3 bits and has a context >manager with the desired be

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sun, 22 Feb 2015 19:07:03 +, Mark Lawrence wrote: > >Looks like you're correct. Knock me down with a feather, Clevor Trevor. It took me by surprise when I first encountered it too. The rationale apparently is that the context manager is strictly a transactional feature, allowing for mult

Re: try pattern for database connection with the close method

2015-02-22 Thread Skip Montanaro
On Sun, Feb 22, 2015 at 12:41 PM, Mario Figueiredo wrote: > The sqlite context manager doesn't close a database connection on > exit. It only ensures, commits and rollbacks are performed. Sorry, I haven't paid careful attention to this thread, so perhaps this has already been su

Re: try pattern for database connection with the close method

2015-02-22 Thread Mark Lawrence
grityError: raise ValueError('invalid data') except lite.DatabaseError: raise OSError('database file corrupt or not found.') The sqlite context manager doesn't close a database connection on exit. It only ensures, commits and rollbacks are performed. Where

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
ror: > raise ValueError('invalid data') >except lite.DatabaseError: > raise OSError('database file corrupt or not found.') The sqlite context manager doesn't close a database connection on exit. It only ensures, commits and rollbacks are performed. -- https://mail.python.org/mailman/listinfo/python-list

Re: try pattern for database connection with the close method

2015-02-21 Thread Peter Otten
Ian Kelly wrote: > On Sat, Feb 21, 2015 at 8:27 AM, Peter Otten <__pete...@web.de> wrote: >> Ian Kelly wrote: >> >>> On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence >>> wrote: try: with lite.connect('data.db') as db: try: db.execute(sql, parms) except l

Re: try pattern for database connection with the close method

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 8:27 AM, Peter Otten <__pete...@web.de> wrote: > Ian Kelly wrote: > >> On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence >> wrote: >>> try: >>> with lite.connect('data.db') as db: >>> try: >>> db.execute(sql, parms) >>> except lite.IntegrityError: >>>

Re: try pattern for database connection with the close method

2015-02-21 Thread Peter Otten
Ian Kelly wrote: > On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence > wrote: >> On 21/02/2015 02:42, Mario Figueiredo wrote: >>> >>> Hello all, >>> >>> I'm using the following pattern for db access that requires me to >>> close the connection as soon as it is not needed: >>> >>> import sq

Re: try pattern for database connection with the close method

2015-02-21 Thread Peter Otten
Mario Figueiredo wrote: > Hello all, > > I'm using the following pattern for db access that requires me to > close the connection as soon as it is not needed: > > import sqlite3 as lite > > try: > db = lite.connect('data.db') > except lite.DatabaseError: >

Re: try pattern for database connection with the close method

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence wrote: > On 21/02/2015 02:42, Mario Figueiredo wrote: >> >> Hello all, >> >> I'm using the following pattern for db access that requires me to >> close the connection as soon as it is not needed: >> >> import sqlite3 as lite >> >> t

Re: try pattern for database connection with the close method

2015-02-21 Thread Mark Lawrence
On 21/02/2015 02:42, Mario Figueiredo wrote: Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import sqlite3 as lite try: db = lite.connect('data.db') except lite.DatabaseErro

Re: try pattern for database connection with the close method

2015-02-20 Thread Chris Kaynor
On Fri, Feb 20, 2015 at 6:42 PM, Mario Figueiredo wrote: > import sqlite3 as lite > > try: > db = lite.connect('data.db') > except lite.DatabaseError: > raise OSError('database file corrupt or not found.') > else: > try: >

try pattern for database connection with the close method

2015-02-20 Thread Mario Figueiredo
Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import sqlite3 as lite try: db = lite.connect('data.db') except lite.DatabaseError: raise OSError('database file corrupt

Re: database connection

2011-10-07 Thread Gabriel Genellina
En Fri, 07 Oct 2011 02:18:04 -0300, masood shaik escribió: can u please tell me how we can connect to database without changing the permission of db file using sqlite3 The OS user who executes the Python script must have read (and write, usually) access to the database file - *any* OS us

database connection

2011-10-06 Thread masood shaik
Hi can u please tell me how we can connect to database without changing the permission of db file using sqlite3 -- http://mail.python.org/mailman/listinfo/python-list

Re: database connection error - postgresql

2009-03-30 Thread D'Arcy J.M. Cain
On Mon, 30 Mar 2009 13:30:18 +0530 bijoy wrote: > conn=pg.connect("secondbooks.db") > pg.InternalError: FATAL: database "secondbooks.db" does not exist > In fact i have a database called secondboo

Re: database connection error - postgresql

2009-03-30 Thread bijoy
hi, I figured out these too. Pls excuse me Thanks Bijoy On Mon, Mar 30, 2009 at 1:30 PM, bijoy wrote: > Hi, > > *code:* (only the class definiton and Database connection part) > > import pg > > __metaclass__=type > > class addbook: > >

database connection error - postgresql

2009-03-30 Thread bijoy
Hi, *code:* (only the class definiton and Database connection part) import pg __metaclass__=type class addbook: conn=pg.connect('secondbooks.db') curs=conn.cursor() *error:* conn=pg.connect("secondbooks.db") pg.InternalError: FATAL: database "secon

Re: Keeping a database connection with a Singleton?

2007-09-19 Thread exhuma.twn
On Sep 19, 4:03 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > exhuma.twn wrote: > > On Sep 19, 3:45 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > >> exhuma.twn wrote: > > [...] > > >> By the way, there is a pythonic (near) singleton: the module. So if you go > >> with option 2, just move the connecti

Re: Keeping a database connection with a Singleton?

2007-09-19 Thread Peter Otten
exhuma.twn wrote: > On Sep 19, 3:45 pm, Peter Otten <[EMAIL PROTECTED]> wrote: >> exhuma.twn wrote: > [...] >> >> By the way, there is a pythonic (near) singleton: the module. So if you go >> with option 2, just move the connection setup into a separate module that >> you can import into client co

Re: Keeping a database connection with a Singleton?

2007-09-19 Thread exhuma.twn
On Sep 19, 3:45 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > exhuma.twn wrote: [...] > > By the way, there is a pythonic (near) singleton: the module. So if you go > with option 2, just move the connection setup into a separate module that > you can import into client code. > > Peter You say "(nea

Re: Keeping a database connection with a Singleton?

2007-09-19 Thread Peter Otten
exhuma.twn wrote: > I remember reading about the Singleton pattern in python and how it's > an unpythonic pattern and all. At the time I did not need the > Singleton anyways, so I just glanced over the document. > > But, setting this aside: I have an application where I have a > connection to a d

Re: Keeping a database connection with a Singleton?

2007-09-19 Thread Jason
On Sep 19, 7:26 am, "exhuma.twn" <[EMAIL PROTECTED]> wrote: > I remember reading about the Singleton pattern in python and how it's > an unpythonic pattern and all. At the time I did not need the > Singleton anyways, so I just glanced over the document. > > But, setting this aside: I have an applic

Keeping a database connection with a Singleton?

2007-09-19 Thread exhuma.twn
I remember reading about the Singleton pattern in python and how it's an unpythonic pattern and all. At the time I did not need the Singleton anyways, so I just glanced over the document. But, setting this aside: I have an application where I have a connection to a database. At some point in the a

Re: MS SQL Database connection

2007-03-05 Thread Hitesh
On Mar 5, 4:44 am, Tim Golden <[EMAIL PROTECTED]> wrote: > Hitesh wrote: > > Hi currently I am using DNS and ODBC to connect to MS SQL database. > > Is there any other non-dns way to connect? If I want to run my script > > from different server I first have to create the DNS in win2k3. > > Here a

Re: MS SQL Database connection

2007-03-05 Thread Tim Golden
Hitesh wrote: > Hi currently I am using DNS and ODBC to connect to MS SQL database. > Is there any other non-dns way to connect? If I want to run my script > from different server I first have to create the DNS in win2k3. Here are several ways to connect to an MSSQL database w/o having to create

MS SQL Database connection

2007-03-04 Thread Hitesh
Hi currently I am using DNS and ODBC to connect to MS SQL database. Is there any other non-dns way to connect? If I want to run my script from different server I first have to create the DNS in win2k3. Thank you, hj -- http://mail.python.org/mailman/listinfo/python-list

Re: Sharing database connection from C to Python

2006-02-01 Thread Daniel Dittmar
[EMAIL PROTECTED] wrote: > I'm developing an application using the C language and Python for it's > plugins. The C program connects to a MySQL database and keeps that > connection active. Is it possible to 'share' this connection with the > Python plugins? If so, is there a "standard" way to do tha

Sharing database connection from C to Python

2006-01-30 Thread dgiagio
Hi, I'm developing an application using the C language and Python for it's plugins. The C program connects to a MySQL database and keeps that connection active. Is it possible to 'share' this connection with the Python plugins? If so, is there a "standard" way to do that? Thank you. DG -- http

Re: Pervasive Database Connection

2005-09-06 Thread Neil Hughes
On 6/9/05 08:52, Alex Le Dain wrote: > What is the best way to access a Pervasive database on another machine? Assuming you mean the Pervasive.SQL DBMS... ...depends what you're trying to do and what you're comfortable with. Pervasive can be accessed through various access methods, e.g. low-leve

Re: Pervasive Database Connection

2005-09-06 Thread [EMAIL PROTECTED]
http://www.pervasive.com/developerzone/access_methods/oledbado.asp -- http://mail.python.org/mailman/listinfo/python-list

Re: Pervasive Database Connection

2005-09-06 Thread Dave Brueck
Alex Le Dain wrote: > What is the best way to access a Pervasive database on another machine? Hi Alex, You can use ODBC / ADO to access Pervasive DBs. I found this page helpful: http://www.mayukhbose.com/python/ado/index.php -Dave -- http://mail.python.org/mailman/listinfo/python-list

Re: Pervasive Database Connection

2005-09-06 Thread [EMAIL PROTECTED]
Use the pervasive client. You'll need the SDK to actually access any data though. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pervasive Database Connection

2005-09-06 Thread Bryan Olson
Alex Le Dain wrote, in entirety: > What is the best way to access a Pervasive database on another machine? The best way, is, well ... Pervasively! Sorry. I can be kida a jerk like that. People often do get get hundreds, sometimes thousands of dollars worth of consultation from these groups, for

Pervasive Database Connection

2005-09-06 Thread Alex Le Dain
What is the best way to access a Pervasive database on another machine? cheers, Alex. -- http://mail.python.org/mailman/listinfo/python-list

Re: Database connection caching

2005-03-19 Thread lbolognini
Thanks everybody for their replies. Lorenzo -- http://mail.python.org/mailman/listinfo/python-list

Re: Database connection caching

2005-03-18 Thread Istvan Albert
[EMAIL PROTECTED] wrote: Hi all, is there an alternative way of: - create a connection object - open the connection - close the connection psycopg, a Postgresql database adapter does connection pooling automatically http://initd.org/projects/psycopg1 Most Zope database adapters also have implicit c

Re: Database connection caching

2005-03-18 Thread Simon Brunning
On 18 Mar 2005 04:52:03 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > is there an alternative way of: > > - create a connection object > - open the connection > - close the connection > > every time one has to run a query. It's actually morte like: create connection create cursor execut

Re: Database connection caching

2005-03-18 Thread Skip Montanaro
Lorenzo> is there an alternative way of: Lorenzo> - create a connection object Lorenzo> - open the connection Lorenzo> - close the connection Lorenzo> every time one has to run a query. Sure, create a Queue.Queue object and stuff a number of connections into it. When you wan

Re: Database connection caching

2005-03-18 Thread Swaroop C H
On 18 Mar 2005 04:52:03 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi all, > > is there an alternative way of: > > - create a connection object > - open the connection > - close the connection > > every time one has to run a query. Why not use cursor objects with a single connection

Database connection caching

2005-03-18 Thread lbolognini
Hi all, is there an alternative way of: - create a connection object - open the connection - close the connection every time one has to run a query. I assume that big sites do something to prevent the performance hit given by these operations, don't they? Would you kindly point me to some exam