Solved

how to catch an error...powerbuilder 9?

Posted on 2004-10-08
7
637 Views
Last Modified: 2013-12-26
i have this code in a button that updates the datawindow

integer rtn
rtn = dw_3.Update()
IF rtn = 1 THEN
        COMMIT USING SQLCA;
              MessageBox("Saved","Saved!")
ELSE
        MessageBox("Not Saved","Not Saved!")
        ROLLBACK USING SQLCA;
END IF

Before "Not saved" shows up i get an error because i insert a number that already exists in the id column. id is the primary key. So how can i stop this error. i do not want to show up. I want something else that i define to show up in a messagebox.

help help:)
0
Comment
Question by:stefanosn
  • 5
  • 2
7 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 12256894
you can trap the sqlca.sqlerrtext or you can define your own messages
also i hope if you accept the answer you dont give it a B grade.It doesnt cost you more to give a A.
If you feel that you have a proper solution and your answer was properly addressed to the grade should be 'A'


integer rtn
rtn = dw_3.Update()
IF rtn = 1 THEN
        COMMIT USING SQLCA;
            MessageBox("Saved","Saved!")
ELSE
       MessageBox("Not Saved",sqlca.sqlerrtext)
        ROLLBACK USING SQLCA;
END IF


or
integer rtn
string ls_message // your own cutome message
rtn = dw_3.Update()
IF rtn = 1 THEN
        COMMIT USING SQLCA;
            MessageBox("Saved","Saved!")
ELSE
       MessageBox("Not Saved",ls_message)
        ROLLBACK USING SQLCA;
END IF
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12256910
Also stefanosn  have you any good powerbuilder books for reference. It would give you a better start.
I would highly recommend
http://www.amazon.com/exec/obidos/ASIN/0672325004/ref%3Dnosim/powerbuilderlink/002-4492783-7713651
(PowerBuilder 9: Advanced Client/Server Development)
and

http://www.amazon.com/exec/obidos/tg/detail/-/020170224X/002-4492783-7713651?v=glance
(The Definitive DataWindow: Your Key to PowerBuilder Success )
0
 

Author Comment

by:stefanosn
ID: 12257047
hmm sajuks it does not seem to work none of the two examples

the box with the sql error shows up again...this happens because of the
dw_3.Update() line
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 33

Expert Comment

by:sajuks
ID: 12257086
Check the dberror event example.
Are you planning to use some class libraries ( like PFC ) in your examples.
These class libraries will help you in trapping errors
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12257106
There are some validn that needs to be checked on the front end itself.
Like whether ot not the required fields are empty or not.
The primary key updation should ideally be done by database triggers. If not you need to check the dwitemstatus as to whether its a new or data modified row.
If its a new then you need to do a select max() from the table and set the primary key value ( normally the serial number).
0
 
LVL 33

Accepted Solution

by:
sajuks earned 50 total points
ID: 12257137
Also the error which you saw was probably the PB dberror. To turn off these messages and have your own error message
you can have a return of 1 in the dberror event.

DBError
Return value
Set the return code to affect the outcome of the event:

0  Display the error message
1  Do not display the error message

Also a correction DBErrorCode  is now obsolete so use the  sqldbcode and sqlerrtext /
Obsolete functions in PowerBuilder  Information formerly provided by the DBErrorCode and DBErrorMessage functions is available in the arguments sqldbcode and sqlerrtext.
0
 

Author Comment

by:stefanosn
ID: 12257178
thank you very much sajuks

it worked!

it was the return value that has to be setted as 1
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copying WordPress Pages 5 87
How to debug Angular JS in Visual Studio 2013 2 234
Insert several multiple frames into a single mainframe 3 65
Unable to start eclipse ? 17 153
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question