Solved

how to catch an error...powerbuilder 9?

Posted on 2004-10-08
7
630 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now