Solved

how to catch an error...powerbuilder 9?

Posted on 2004-10-08
7
634 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

772 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