Solved

how to catch an error...powerbuilder 9?

Posted on 2004-10-08
7
650 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

705 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