473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trigger error ....

Following is a simple trigger definition:

CREATE TRIGGER TRIG_EMPLOYEE_1
AFTER UPDATE OF SALARY ON DB2ADMIN.EMPLOY EE
FOR EACH STATEMENT MODE DB2SQL
CALL DB2ADMIN.SQLSP1 0( )

This gives an error:

SQL0104N An unexpected token "CALL" was found following "ATEMENT MODE
DB2SQL ". Expected tokens may include: "RETURN ".

DB2ADMIN.SQLSP1 0( ) is an existing stored procedure.

Any pointers will be appreciated.

TIA
Raquel.

Nov 12 '05 #1
9 3195
Raquel wrote:
Following is a simple trigger definition:

CREATE TRIGGER TRIG_EMPLOYEE_1
AFTER UPDATE OF SALARY ON DB2ADMIN.EMPLOY EE
FOR EACH STATEMENT MODE DB2SQL
CALL DB2ADMIN.SQLSP1 0( )

This gives an error:

SQL0104N An unexpected token "CALL" was found following "ATEMENT MODE
DB2SQL ". Expected tokens may include: "RETURN ".

DB2ADMIN.SQLSP1 0( ) is an existing stored procedure.

Any pointers will be appreciated.


CALL statements are not yet supported in the body of a trigger. You have to
wait until Stinger (aka version 8.2) becomes available. Until then you
have to resort to UDFs, if possible, or put the logic directly into the
trigger body and not a procedure.

Alternatively, you could use the CALL_PROCEDURE function that is described
here:

http://www.ibm.com/developerworks/db...ein/index.html

But note the restrictions and implications that come with this approach!

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
Thanks Knut. You are the co-author of the above very useful article!!

Wow!! So, at last I find a feature that is readily available in BIG DB2
(DB2 for OS/390) and not in small DB2 (aka UDB for LUW).

Raquel.

Nov 12 '05 #3
Raquel wrote:
Wow!! So, at last I find a feature that is readily available in BIG DB2
(DB2 for OS/390) and not in small DB2 (aka UDB for LUW).


Yes, that's right. And that's why the gap will be closed soon.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #4
"Raquel" <ra****@nospam. com> wrote in message news:<85******* *************** ********@localh ost.talkaboutda tabases.com>...
Thanks Knut. You are the co-author of the above very useful article!!

Wow!! So, at last I find a feature that is readily available in BIG DB2
(DB2 for OS/390) and not in small DB2 (aka UDB for LUW).

Raquel.


Knut, yes this article is very helpful. We have implemented it on both
V8 and V7. The V8 version works just as intended. The only thing we
have trouble with is on the TRUNCATE stored procedure on V7. When an
invalid table name is entered, we get the following error:

SQL1131N DARI (Stored Procedure) process has been terminated
abnormally. SQLST
ATE=38503
Anything we can do to fix this problem in V7? We often get calls on
this abend which is only caused when a non-existent table name is
entered. I have no C++ skills

Thanks
Nov 12 '05 #5
Jeff wrote:
"Raquel" <ra****@nospam. com> wrote in message

news:<85******* *************** ********@localh ost.talkaboutda tabases.com>...
Thanks Knut. You are the co-author of the above very useful article!!

Wow!! So, at last I find a feature that is readily available in BIG DB2
(DB2 for OS/390) and not in small DB2 (aka UDB for LUW).

Raquel.


Knut, yes this article is very helpful. We have implemented it on both
V8 and V7. The V8 version works just as intended. The only thing we
have trouble with is on the TRUNCATE stored procedure on V7. When an
invalid table name is entered, we get the following error:

SQL1131N DARI (Stored Procedure) process has been terminated
abnormally. SQLST
ATE=38503
Anything we can do to fix this problem in V7? We often get calls on
this abend which is only caused when a non-existent table name is
entered. I have no C++ skills


I'll look into this - you should have told us earlier that you experience
some problems!. Can you please tell us which platform you are running on
and which DB2 FixPack-level is installed?

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #6
Hello.
Knut, yes this article is very helpful. We have implemented it on both
V8 and V7. The V8 version works just as intended. The only thing we
have trouble with is on the TRUNCATE stored procedure on V7. When an
invalid table name is entered, we get the following error:

SQL1131N DARI (Stored Procedure) process has been terminated
abnormally. SQLST
ATE=38503


This SP works fine on W2K, v7, FP11.

--- bisp2.c ---

#include <memory.h>
#include <sqlenv.h>
#include <sqlutil.h>

/* Declare function prototypes for this stored procedure library */
SQL_API_RC SQL_API_FN truncate(char *, char *, sqlint32 *);

SQL_API_RC SQL_API_FN truncate(
char fullTableName[254],
char eBuffer[1024],
sqlint32 *sql_code)
{
struct sqlchar *columnStringPo inter;
struct sqldcol columnData;
struct sqlca sqlca;
struct sqluimpt_in impInput;
struct sqluimpt_out impOutput;
char datafile[] = "nul";
char repl[] = "REPLACE INTO ";
char fileFormat[] = "DEL";
char msgfile[] = "nul";
char impStatement[254];

*sql_code = 0;
memset(eBuffer, '\0', sizeof(eBuffer) );
memset(impState ment, '\0', sizeof(impState ment));

/* need to preset the size of structure field and counts */
impInput.sizeOf Struct = SQLUIMPT_IN_SIZ E;
impOutput.sizeO fStruct = SQLUIMPT_OUT_SI ZE;
impInput.restar tcnt = impInput.commit cnt = 0;
columnData.dcol meth = 'D';
strncpy(impStat ement, repl, strlen(repl));
strncat(impStat ement, fullTableName, strlen(fullTabl eName));

columnStringPoi nter = (struct sqlchar *)malloc(strlen (impStatement)
+ sizeof (struct sqlchar));
columnStringPoi nter->length = (short)strlen(i mpStatement);
strncpy (columnStringPo inter->data, impStatement, strlen(impState ment));
/* import */
sqluimpr (datafile, NULL, &columnData, columnStringPoi nter, fileFormat,
NULL, msgfile, 0, &impInput, &impOutput, NULL, NULL, &sqlca);
*sql_code=sqlca .sqlcode;
if (*sql_code<0)
sqlaintp (eBuffer, 1024, 0, &sqlca);
return(SQLZ_DIS CONNECT_PROC);
} /* truncate */
--- end of bisp2.c ---

--- bisp2.def --
LIBRARY BISP2
EXPORTS
truncate
--- end of bisp2.def ---

--- SQL ---
CREATE PROCEDURE bi.TRUNCATE
(IN TABNAME VARCHAR(254),
OUT MSG VARCHAR(1024),
OUT SQLCODE INTEGER
)
EXTERNAL NAME 'bisp2!truncate '
LANGUAGE C
PARAMETER STYLE GENERAL
NOT DETERMINISTIC
FENCED
NO DBINFO
PROGRAM TYPE SUB;
---

Hope this help,
Mark.
Nov 12 '05 #7
Jeff wrote:
"Raquel" <ra****@nospam. com> wrote in message

news:<85******* *************** ********@localh ost.talkaboutda tabases.com>...
Thanks Knut. You are the co-author of the above very useful article!!

Wow!! So, at last I find a feature that is readily available in BIG DB2
(DB2 for OS/390) and not in small DB2 (aka UDB for LUW).

Raquel.


Knut, yes this article is very helpful. We have implemented it on both
V8 and V7. The V8 version works just as intended. The only thing we
have trouble with is on the TRUNCATE stored procedure on V7. When an
invalid table name is entered, we get the following error:

SQL1131N DARI (Stored Procedure) process has been terminated
abnormally. SQLST
ATE=38503
Anything we can do to fix this problem in V7? We often get calls on
this abend which is only caused when a non-existent table name is
entered. I have no C++ skills


Found the problem... The PARAMETER STYLE SQL that is available in V8 expects
a different set of parameters than the PARAMETER STYLE DB2SQL that you
(most probably) used in the V7 procedures. For the V7 procedures, you need
to provide an array (or pointer) for the null indicators and not separate
arguments. The separate arguments result in too many parameters expected
on the stack (which aren't provided by DB2) so that the last one, which
happens to be the error message text is an invalid parameter. When it is
dereferenced to write the error message, you get a segmentation violation
(signal 11). DB2 detects that and signals the abend.

Ok, so much for the problem description... The fix is not difficult. Just
change the function code as shown below. I marked the corrections
everywhere - please remove the marks before using this.

#if defined(__cplus plus)
extern "C"
#endif
SQL_API_RC SQL_API_FN truncate_table(
/* fully qualified table name */
SQLUDF_VARCHAR *schemaName, SQLUDF_VARCHAR *tableName,
/* null indicators */
!! here we need a single parameter for the NULL indicator array
SQLUDF_NULLIND nulls[2],
SQLUDF_TRAIL_AR GS)
{
int rc = 0;
struct sqldcol dataDescriptor;
unsigned char actionBuffer[sizeof(struct sqlchar) + 20+130+1+130+1];
struct sqlchar *pAction = (struct sqlchar *)actionBuffer;
struct sqluimpt_in inputInfo;
struct sqluimpt_out outputInfo;

!! we define the macros to make the code more readable when dealing with the
!! null indicators
#define SCHEMA_NAME_IND 0
#define TABLE_NAME_IND 1

EXEC SQL INCLUDE SQLCA;

EXEC SQL BEGIN DECLARE SECTION;
char hSchemaName[129] = { '\0' };
char hTableName[129] = { '\0' };
sqlint32 count = 0;
EXEC SQL END DECLARE SECTION;

/* get default schema name if parameter was NULL */
!! change the test for a NULL in the schema name
if (SQLUDF_NULL(&n ulls[SCHEMA_NAME_IND])) {
EXEC SQL
VALUES CURRENT SCHEMA
INTO :hSchemaName;
if (SQLCODE) {
memcpy(SQLUDF_S TATE, sqlca.sqlstate, SQLUDF_SQLSTATE _LEN);
memcpy(SQLUDF_M SGTX, sqlca.sqlerrmc, sqlca.sqlerrml) ;
goto cleanup;
}
}
else {
/* unquote given schema name */
rc = UnquoteName(sch emaName, hSchemaName, sizeof hSchemaName);
if (rc) {
char errMsg[131 + 50];
memcpy(SQLUDF_S TATE, "38000", SQLUDF_SQLSTATE _LEN);
sprintf(errMsg, "Invalid schema name '%s'.", schemaName);
memcpy(SQLUDF_M SGTX, errMsg, SQLUDF_MSGTEXT_ LEN);
goto cleanup;
}
}

/* check and unquote table name */
!! change the test for a NULL in the table name
if (SQLUDF_NULL(&n ulls[TABLE_NAME_IND])) {
memcpy(SQLUDF_S TATE, "38001", SQLUDF_SQLSTATE _LEN);
strcpy(SQLUDF_M SGTX, "No table name specified.");
goto cleanup;
}

Everything following the above snippet can remain as before.

p.s: I'll take care of updating the article.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #8
Knut, we are unix aix 5.1.0 UDB is v7.2 fp 9.

On a side note and I see where you are part of the Information
Integrator Development. Before datajoiner support runs out in the next
couple of months we are in the process of going to information
integrator. It says nicknames are not supported for stored procedures
in II, while they were in datajoiner. We have nicknames to a couple of
Oracle stored procedures. Any suggestions for a work around for this?

Thanks for all your help.
Knut Stolze <st****@de.ibm. com> wrote in message news:<ce******* ***@fsuj29.rz.u ni-jena.de>...
Jeff wrote:
"Raquel" <ra****@nospam. com> wrote in message

news:<85******* *************** ********@localh ost.talkaboutda tabases.com>...
Thanks Knut. You are the co-author of the above very useful article!!

Wow!! So, at last I find a feature that is readily available in BIG DB2
(DB2 for OS/390) and not in small DB2 (aka UDB for LUW).

Raquel.


Knut, yes this article is very helpful. We have implemented it on both
V8 and V7. The V8 version works just as intended. The only thing we
have trouble with is on the TRUNCATE stored procedure on V7. When an
invalid table name is entered, we get the following error:

SQL1131N DARI (Stored Procedure) process has been terminated
abnormally. SQLST
ATE=38503
Anything we can do to fix this problem in V7? We often get calls on
this abend which is only caused when a non-existent table name is
entered. I have no C++ skills


I'll look into this - you should have told us earlier that you experience
some problems!. Can you please tell us which platform you are running on
and which DB2 FixPack-level is installed?

Nov 12 '05 #9
Jeff wrote:
Knut, we are unix aix 5.1.0 UDB is v7.2 fp 9.
Good, then I was using the same platform, just on FP7. ;-)

You saw my other post from today? It should solve your problem.
On a side note and I see where you are part of the Information
Integrator Development. Before datajoiner support runs out in the next
couple of months we are in the process of going to information
integrator. It says nicknames are not supported for stored procedures
in II, while they were in datajoiner. We have nicknames to a couple of
Oracle stored procedures. Any suggestions for a work around for this?


Sorry, not my area of expertise. Would be using "passthru" an option for
you?

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1736
by: Michael Teja via SQLMonster.com | last post by:
I made a trigger for delete just like this. " CREATE TRIGGER ON . FOR DELETE AS Declare @severity int, @IdNmbr nvarchar(10) Set @Severity = 0
1
4328
by: Jen S | last post by:
I feel like I'm missing something obvious here, but I'm stumped... I have a stored procedure with code that looks like: INSERT INTO MyTableA ( ...fields... ) VALUES (...values...) IF (@@ERROR <> 0) BEGIN ROLLBACK TRANSACTION; RAISERROR('An error occurred in the stored proc.', 16, 1);
0
7131
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE TRIGGER statement.) I've also defined a SQL stored proc, and the trigger is set to call this SP. I've posted the simplified source below. I can...
4
4170
by: Alexander Pope | last post by:
I am using db2 udb v8.2 AIX I have created trigger, however I am not confident it meets industry standards. If I make it fail, I cant tell from the message where it is failing. what can I add to trap the errors properly? CREATE TRIGGER myschema.t1_upd_t AFTER UPDATE OF dt ON myschema.t1 REFERENCING NEW AS N
12
4741
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN (N.act_recov_date IS NOT NULL) BEGIN ATOMIC select count(*) into v_n from is3.flushes
5
3287
by: Bob Stearns | last post by:
I have two (actually many) dates in a table I want to validate on insertion. The following works in the case of only one WHEN clause but fails with two (or more), with the (improper? inappropriate?) error message: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: CREATE TRIGGER IS3.date_later_001i NO C;BEGIN-OF-STATEMENT;<space> which is...
3
4937
by: ChrisN | last post by:
Hello all, I have a quick question. I'm using a C# object to commit new rows to a database. In the database I have an INSERT Trigger watching values come in. If the record to be committed fails the trigger's test, the trigger rolls back the INSERT command and no changes are made to the database. As far as my object is concerned, the...
2
2047
by: Juan Jose Costello Levien | last post by:
Hello, I am trying to use a trigger function I wrote in C. Basically what I want to do is to audit a table when a row is inserted into another table by copying the row to the new table. It compiles Ok and I created a shared library trigger.so. But when I load it into pgAdmin it tells me 'An error had occured'. To address that I put here...
5
2632
by: Bruno Rafael Moreira de Barros | last post by:
function test1() { trigger_error('My error'); } application.php //code... test1(); //code...
11
7851
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG' does not exist drop table log_errors_tab;
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.