Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to catch an error...powerbuilder 9?

Posted on 2004-10-08
7
Medium Priority
?
667 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

604 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