hi, there. i have this question which might sound quite stupid to some
people, but here we go anyway.
i have written a python program which interacts with a postgresql
database. what it does is simply drops an existing database called
'mytempdb'.
the code looks like below;
link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout =
subprocess.PIPE, shell = True)
link.communicate(password)
link.wait()
where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename"
and
filename is the name of the file which contains a single SQL command
which is "drop database mytempdb".
the program works fine as long as a correct password is supplied,
however, i have a problem if the password is incorrect since this
exception is *not* handled within the scope of my program, instead,
what is does is showing some error messages in the prompt. so my
program, without knowing whether an errors has taken place or not, goes
on to execute the next task.
any clue? please let me know if you think the problem is not well
addressed. =)
thanks. have a nice one. 7 2175
damacy wrote:
hi, there. i have this question which might sound quite stupid to some
people, but here we go anyway.
i have written a python program which interacts with a postgresql
database. what it does is simply drops an existing database called
'mytempdb'.
the code looks like below;
link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout =
subprocess.PIPE, shell = True)
link.communicate(password)
link.wait()
where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename"
and
filename is the name of the file which contains a single SQL command
which is "drop database mytempdb".
the program works fine as long as a correct password is supplied,
however, i have a problem if the password is incorrect since this
exception is *not* handled within the scope of my program, instead,
what is does is showing some error messages in the prompt. so my
program, without knowing whether an errors has taken place or not, goes
on to execute the next task.
any clue? please let me know if you think the problem is not well
addressed. =)
thanks. have a nice one.
Hi, damacy,
Maybe I'm not understanding your code 100%, but have you tried catching
the return value of the psql process that you're launching? Just a
thought...
--hiaips
hiaips wrote:
damacy wrote:
hi, there. i have this question which might sound quite stupid to some
people, but here we go anyway.
i have written a python program which interacts with a postgresql
database. what it does is simply drops an existing database called
'mytempdb'.
the code looks like below;
link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout =
subprocess.PIPE, shell = True)
link.communicate(password)
link.wait()
where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename"
and
filename is the name of the file which contains a single SQL command
which is "drop database mytempdb".
the program works fine as long as a correct password is supplied,
however, i have a problem if the password is incorrect since this
exception is *not* handled within the scope of my program, instead,
what is does is showing some error messages in the prompt. so my
program, without knowing whether an errors has taken place or not, goes
on to execute the next task.
any clue? please let me know if you think the problem is not well
addressed. =)
thanks. have a nice one.
Hi, damacy,
Maybe I'm not understanding your code 100%, but have you tried catching
the return value of the psql process that you're launching? Just a
thought...
--hiaips
hi, hiaips. thanks for your reply.
are you talking about a try-except block? yes, i used that in case the
psql process might throw an exception if there is any. but
unfortunately, it does not do so.
yes, i'll have a read. thanks. =)
hiaips wrote:
Another option would be to use the psycopg module to connect to
postgres from within your Python code. See http://www.initd.org/projects/psycopg1 for more information.
--hiaips
"damacy" <we****@gmail.comwrote:
>hi, there. i have this question which might sound quite stupid to some people, but here we go anyway.
i have written a python program which interacts with a postgresql database. what it does is simply drops an existing database called 'mytempdb'.
the code looks like below;
link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, shell = True) link.communicate(password) link.wait()
where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename" and filename is the name of the file which contains a single SQL command which is "drop database mytempdb".
hiaips is right. The right way to do this is to use a Postgres module.
psycopg is my favorite, but there are several alternatives.
import psycopg
db = psycopg.connect(
"dbname=template1 user=postgres password=%s" % password )
c = db.cursor()
c.execute( "drop database mytempdb;" )
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
thanks. i started to use psycopg.
however, i have this error message and i don't quite get what it means.
it says "DROP DATABASE cannot run inside a transaction block".
does anyone have a clue?
Tim Roberts wrote:
"damacy" <we****@gmail.comwrote:
hi, there. i have this question which might sound quite stupid to some
people, but here we go anyway.
i have written a python program which interacts with a postgresql
database. what it does is simply drops an existing database called
'mytempdb'.
the code looks like below;
link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout =
subprocess.PIPE, shell = True)
link.communicate(password)
link.wait()
where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename"
and
filename is the name of the file which contains a single SQL command
which is "drop database mytempdb".
hiaips is right. The right way to do this is to use a Postgres module.
psycopg is my favorite, but there are several alternatives.
import psycopg
db = psycopg.connect(
"dbname=template1 user=postgres password=%s" % password )
c = db.cursor()
c.execute( "drop database mytempdb;" )
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
oh, fixed when i set isolation level to 0.
thanks anyway!
damacy wrote:
thanks. i started to use psycopg.
however, i have this error message and i don't quite get what it means.
it says "DROP DATABASE cannot run inside a transaction block".
does anyone have a clue?
Tim Roberts wrote:
"damacy" <we****@gmail.comwrote:
>hi, there. i have this question which might sound quite stupid to some
>people, but here we go anyway.
>
>i have written a python program which interacts with a postgresql
>database. what it does is simply drops an existing database called
>'mytempdb'.
>
>the code looks like below;
>
>link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout =
>subprocess.PIPE, shell = True)
>link.communicate(password)
>link.wait()
>
>where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename"
>and
>filename is the name of the file which contains a single SQL command
>which is "drop database mytempdb".
hiaips is right. The right way to do this is to use a Postgres module.
psycopg is my favorite, but there are several alternatives.
import psycopg
db = psycopg.connect(
"dbname=template1 user=postgres password=%s" % password )
c = db.cursor()
c.execute( "drop database mytempdb;" )
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Zunbeltz Izaola |
last post by:
Hi!
I am planning a program and I need some advice about what tool to use.
Basically my program will deal with a object A. A is a list like
object with same attributtes and a list of objects...
|
by: dcrespo |
last post by:
Hi all,
How can I get a raised exception from other thread that is in an
imported module?
For example:
---------------
programA.py
---------------
|
by: craig |
last post by:
I am wondering if there are some best practices for determining a strategy
for using try/catch blocks within an application.
My current thoughts are:
1. The code the initiates any high-level...
|
by: Michele Petrazzo |
last post by:
Hi list, I have a strange error on my software on win 2k/xp and debian
3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython:
python, on a piece of code doesn't raise a KeyError on a dict (that
don't...
|
by: Paul Rubin |
last post by:
I'd like to suggest adding a builtin abstract class to Python called
AsynchronousException, which would be a subclass of Exception. The
only asynchronous exception I can think of right now is...
|
by: 63q2o4i02 |
last post by:
Hi, I'm interested in using python to start writing a CAD program for
electrical design. I just got done reading Steven Rubin's book, I've
used "real" EDA tools, and I have an MSEE, so I know what...
|
by: Petr Jakes |
last post by:
I am a little bit confused by all possibilities for exceptions handling
in Python (probably because I am not skilled enough??) I did try to
search trough this list and reading Python tutorial about...
|
by: yinglcs |
last post by:
I read the document here about exception handling in python:
http://www.diveintopython.org/file_handling/index.html
Can you please tell me how can I catch all exception in python?
like this in...
|
by: eliben |
last post by:
Python provides a quite good and feature-complete exception handling
mechanism for its programmers. This is good. But exceptions, like any
complex construct, are difficult to use correctly,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |