Обсуждение: error handling. How to?

Поиск
Список
Период
Сортировка

error handling. How to?

От
Janning Vygen
Дата:
Hi,

i try do achieve that my database checks every entry on insert and update and
returns german error messages, so my frontend knows what's wrong and can show
some reasonable error messages to the user.

i wrote a trigger who checks BEFORE every insert and updtae and returns error
messages if new values are not acceptable.

one of my problems:
if i have a value like bool or int2 and the frontend is html and just takes
the input from a textfield, the backend returns an error before executing the
trigger beacuse the values cant be parsed into the correct type.

But should not the trigger be called BEFORE inserting?
It seems not, maybe just because the NEW record has to be filled and with a
mismatching type it can't be done!?

Bad thing about it: my trigger should report every error. but it is never
executed when the type parsing fails.

I just dont want to put any error handling code in my frontend. I just want
the backend to return something like
"ERROR: errormessage1; ERROR: errormessage2;"
to return all errors on all fields.

Can anybody tell me how to make a really good and flexible error processing
with postgreSQL??

janning

Re: error handling. How to?

От
"Richard Huxton"
Дата:
From: "Janning Vygen" <vygen@planwerk6.de>

> one of my problems:
> if i have a value like bool or int2 and the frontend is html and just
takes
> the input from a textfield, the backend returns an error before executing
the
> trigger beacuse the values cant be parsed into the correct type.
>
> But should not the trigger be called BEFORE inserting?
> It seems not, maybe just because the NEW record has to be filled and with
a
> mismatching type it can't be done!?

Correct - your update/insert statement will be parsed before it gets
processed. It's only if the statement passes the checks and gets executed
that your trigger will see it.

> Bad thing about it: my trigger should report every error. but it is never
> executed when the type parsing fails.
>
> I just dont want to put any error handling code in my frontend. I just
want
> the backend to return something like
> "ERROR: errormessage1; ERROR: errormessage2;"
> to return all errors on all fields.

Data validation (making sure all values submitted are of valid types and
ranges) needs to be done before you reach the database. You should be
checking all submitted values anyway, just for security implications. Do
this in your server-side Perl/PHP/Java/C, don't just rely on javascript in
the browser.

Only allowing users to add orders for products with an existing
product-code, now that is something that can (and should) be enforced in the
database. Personally, I'd still want to trap the errors from the database
and then produce a user-friendly message in my application.

> Can anybody tell me how to make a really good and flexible error
processing
> with postgreSQL??

Examine the types of errors that can occur. You should find they fall into a
number of different classes. These classes should (hopefully) closely match
the structure of your application. Each part of your application should then
be responsible for generating its own exceptions and dealing with errors
generated by helper modules.

In your case, handle this in your object/database abstraction layer. If you
don't have one, build one - it's not usually a big issue performance-wise
and will pay you back tenfold if you need to change the underlying database
/ database system.

HTH

- Richard Huxton


Re: error handling. How to?

От
Janning Vygen
Дата:
Am Montag,  9. Juli 2001 11:36 schrieb Richard Huxton:
> Data validation (making sure all values submitted are of valid types and
> ranges) needs to be done before you reach the database. You should be
> checking all submitted values anyway, just for security implications. Do
> this in your server-side Perl/PHP/Java/C, don't just rely on javascript in
> the browser.

Hi Richard (thanks for your explanations)

thinking a few days about your words  i decided to do the error checking in a
serverside programm. So i have three components. GUI(HTML),
frontend(serverside), Database(backend)

But if i have a table like
create table (level int2 check level > 0 and level < 10);

i do the error checking two times. Once in my frontend (not GUI) and once in
my backend (database). If have to do the check in my frontend too because i
want german readable error messages and not database produced error messages.
And i have to check it in my database because frontends like pgsql wont check
it.

if i want to change the range to 12 i have to change it in two programms.
thats what i dont like.

Are there any examples to learn from. In SQL books you always get this easy
shit like "i build a cd database" huii. Nothing about how to design a whole
software with a SQL database. Error checking, How to Connect a OO Layer to a
database....

Does anybody know some in-depth examples on the web?

thanks in advance

janning

p.s: is this the correct mailing list for such questions?? or is it OT?

> Only allowing users to add orders for products with an existing
> product-code, now that is something that can (and should) be enforced in
> the database. Personally, I'd still want to trap the errors from the
> database and then produce a user-friendly message in my application.
>
> > Can anybody tell me how to make a really good and flexible error
>
> processing
>
> > with postgreSQL??
>
> Examine the types of errors that can occur. You should find they fall into
> a number of different classes. These classes should (hopefully) closely
> match the structure of your application. Each part of your application
> should then be responsible for generating its own exceptions and dealing
> with errors generated by helper modules.
>
> In your case, handle this in your object/database abstraction layer. If you
> don't have one, build one - it's not usually a big issue performance-wise
> and will pay you back tenfold if you need to change the underlying database
> / database system.
>
> HTH
>
> - Richard Huxton

--
Planwerk 6 /websolutions
Herzogstraße 86
40215 Düsseldorf

fon 0211-6015919
fax 0211-6015917
http://www.planwerk6.de

Re: error handling. How to?

От
Дата:
> Am Montag,  9. Juli 2001 11:36 schrieb Richard Huxton:

> thinking a few days about your words  i decided to do the error
> checking in a  serverside programm. So i have three components.
> GUI(HTML),
> frontend(serverside), Database(backend)
>
> But if i have a table like
> create table (level int2 check level > 0 and level < 10);
>
> i do the error checking two times. Once in my frontend (not GUI) and
> once in  my backend (database). If have to do the check in my frontend
> too because i  want german readable error messages and not database
> produced error messages.  And i have to check it in my database because
> frontends like pgsql wont check  it.
>
> if i want to change the range to 12 i have to change it in two
> programms.  thats what i dont like.

Agreed - if you need to make the same change twice you're going to forget one of them sooner or later.

What I've taken to doing is trying to abstract my data definitions into a config file and running that through Perl or
amacro processor to generate both SQL and either PHP or Perl structures and accessor functions. One of these days I'll
getaround to making my tools general purpose and post them up for use. 

Makes you more disciplined since you need to build little upgrade scripts to update your database structure. Means you
(wellme anyway) think about what changes mean to your structure rather than just ALTER TABLE ADD COLUMN. 

Actually - run a few searches on Google/Freshmeat - there might be something that suits you there.

> Are there any examples to learn from. In SQL books you always get this
> easy  shit like "i build a cd database" huii. Nothing about how to
> design a whole  software with a SQL database. Error checking, How to
> Connect a OO Layer to a  database....
>
> Does anybody know some in-depth examples on the web?

Afraid not - I've always felt good real-world examples of development (including where you realised you've gone wrong
andneed to rework something) would be useful. 

> p.s: is this the correct mailing list for such questions?? or is it OT?

I'm interested in people's responses - how PG gets used in the real world is useful information.

- Richard Huxton


Acceptable topics on -general WAS Re: error handling. How to?

От
GH
Дата:
[/me bows before all and begs forgiveness for the non-snippage. /me felt
that it was better than referring to the other (potentially deleted)
thread]

Acceptable topics of discussion on -general.

I would say anything that involves the installation, use, general
development, and tuning  of; and issues with; and advocacy for
PostgreSQL are acceptable and welcomed topics of discussion.
[/me takes it upon himself to proclaim that OT threads are acceptable
so long as they are not unreasonably long and are at least vaguely
relevant to PostgreSQL in /some/ way.]

Generally speaking, you should survive unscathed unless you have serious
doubts about what you are posting. Unacceptable are such things as
flamebait, discussion of how MySQL is (/me giggles mercilessly at
the insanity) 'better', OS wars (e.g. 'Linux kisses the feet of
FreeBSD') [/me begs forgiveness despite the reality], and other
gratuitous dribble.

Viva le PostgreSQL.

/me says 'So long suckas!' and returns to MUDing amid quotes from South
Park episodes.

Enjoy.

Oh, yeah, I welcome support and counterarguments (so I can
freely shoot them down as naive and false *smile*).

gh

On Tue, Jul 10, 2001 at 08:09:08PM +0100, some SMTP stream spewed forth:
> > Am Montag,  9. Juli 2001 11:36 schrieb Richard Huxton:
>
> > thinking a few days about your words  i decided to do the error
> > checking in a  serverside programm. So i have three components.
> > GUI(HTML),
> > frontend(serverside), Database(backend)
> >
> > But if i have a table like
> > create table (level int2 check level > 0 and level < 10);
> >
> > i do the error checking two times. Once in my frontend (not GUI) and
> > once in  my backend (database). If have to do the check in my frontend
> > too because i  want german readable error messages and not database
> > produced error messages.  And i have to check it in my database because
> > frontends like pgsql wont check  it.
> >
> > if i want to change the range to 12 i have to change it in two
> > programms.  thats what i dont like.
>
> Agreed - if you need to make the same change twice you're going to forget one of them sooner or later.
>
> What I've taken to doing is trying to abstract my data definitions into a config file and running that through Perl
ora macro processor to generate both SQL and either PHP or Perl structures and accessor functions. One of these days
I'llget around to making my tools general purpose and post them up for use. 
>
> Makes you more disciplined since you need to build little upgrade scripts to update your database structure. Means
you(well me anyway) think about what changes mean to your structure rather than just ALTER TABLE ADD COLUMN. 
>
> Actually - run a few searches on Google/Freshmeat - there might be something that suits you there.
>
> > Are there any examples to learn from. In SQL books you always get this
> > easy  shit like "i build a cd database" huii. Nothing about how to
> > design a whole  software with a SQL database. Error checking, How to
> > Connect a OO Layer to a  database....
> >
> > Does anybody know some in-depth examples on the web?
>
> Afraid not - I've always felt good real-world examples of development (including where you realised you've gone wrong
andneed to rework something) would be useful. 
>
> > p.s: is this the correct mailing list for such questions?? or is it OT?
>
> I'm interested in people's responses - how PG gets used in the real world is useful information.
>
> - Richard Huxton

--
> What, no one sings along with Ricky Martin anymore?
My kid sister does (but then, she prefers pico to vi ...)
    -- Suresh Ramasubramanian, alt.sysadmin.recovery