Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2008, 05:30 PM   PM User | #1
jaywhy13
Regular Coder

 
Join Date: Dec 2004
Location: Jamaica
Posts: 592
Thanks: 2
Thanked 0 Times in 0 Posts
jaywhy13 is an unknown quantity at this point
Python error handling

How does one achieve this...
Say I've got a line that reads...
plpy.execute("some sql command that might throw an error");
How do I handle that error?
I've tried:
Code:
create or replace function prepare(tbl varchar, edgetbl varchar) returns integer as $$
	plpy.info ("Roads Table: " + tbl)
	plpy.info ("Edges Table: " + edgetbl)
	createstr = "CREATE TABLE " + edgetbl + " ( gid int8, n_gid int8, dist int8, foreign key (gid) references roads (gid), foreign key (n_gid) references roads (gid), primary key (gid,n_gid) )"
	try:
		plpy.execute(createstr)
	except:
		plpy.info ("The table " + edgetbl + " was already created")
	plpy.info ("Moving On")
$$ language plpythonu;
Which gave me the output:
INFO: ('Roads Table: roads',)
INFO: ('Edges Table: edges',)
WARNING: plpython: in function prepare:
DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_execute_query
INFO: ('The table edges was already created',)
INFO: ('Moving On',)
ERROR: relation "edges" already exists
CONTEXT: SQL statement "CREATE TABLE edges ( gid int8, n_gid int8, dist int8, foreign key (gid) references roads (gid), foreign key (n_gid) references roads (gid), primary key (gid,n_gid) )"

However... it does not execute the last line... so the catch is apparently not working.
__________________
I'm gonna find a way to download the internet if its the last thing I do...
Prepare to bow down to me (or my grave) and call me almighty when the algorithm is finished
jaywhy13 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:59 PM.


Advertisement
Log in to turn off these ads.