Table25onpage119,Table26onpage120,and Table27onpage121 specifythe datatypesforthestatement,condition,and connectioninformationitemsthatyou canrequestbyusingtheGETDIAGNOSTICSstatement.Youmust declareeach target hostvariablewith adatatype thatiscompatiblewiththedatatypeofthe requesteditem.
EXEC SQL BEGIN DECLARE SECTION;
long row_count, num_condns, i;
long ret_sqlcode, row_num;
char ret_sqlstate[6];
...
EXEC SQL END DECLARE SECTION;
...
EXEC SQL
INSERT INTO DSN8910.ACT
(ACTNO, ACTKWD, ACTDESC)
VALUES (:hva1, :hva2, :hva3)
FOR 10 ROWS
NOT ATOMIC CONTINUE ON SQLEXCEPTION;
EXEC SQL GET DIAGNOSTICS
:row_count = ROW_COUNT, :num_condns = NUMBER;
printf("Number of rows inserted = %d\n", row_count);
for (i=1; i<=num_condns; i++) {
EXEC SQL GET DIAGNOSTICS CONDITION :i
:ret_sqlcode = DB2_RETURNED_SQLCODE,
:ret_sqlstate = RETURNED_SQLSTATE,
:row_num = DB2_ROW_NUMBER;
printf("SQLCODE = %d, SQLSTATE = %s, ROW NUMBER = %d\n",
ret_sqlcode, ret_sqlstate, row_num);
}
Figure11.UsingGETDIAGNOSTICStoreturnthenumberofrowsandconditionsreturned andconditioninformation
Table25.DatatypesforGETDIAGNOSTICSitemsthatreturnstatementinformation
Item Description Datatype
DB2_GET_DIAGNOSTICS _DIAGNOSTICS
AfteraGETDIAGNOSTICSstatement,if anyerrororwarningoccurred,thisitem containsallofthediagnosticsasasingle string.
VARCHAR(32672)
DB2_LAST_ROW Afteramultiple-rowFETCHstatement,
thisitemcontainsavalueof+100ifthe lastrowinthetableisintherowsetthat wasreturned.
INTEGER
DB2_NUMBER_PARAMETER _MARKERS
AfteraPREPAREstatement,thisitem containsthenumberofparameter markersinthepreparedstatement.
INTEGER
DB2_NUMBER_RESULT_SETS AfteraCALLstatementthatinvokesa storedprocedure,thisitemcontainsthe numberofresultsetsthatarereturnedby theprocedure.
INTEGER
DB2_NUMBER_ROWS AfteranOPENorFETCHstatementfor
whichthesizeoftheresulttableis known,thisitemcontainsthenumberof rowsintheresulttable.AfteraPREPARE statement,thisitemcontainstheestimated numberofrowsintheresulttableforthe preparedstatement.ForSENSITIVE DYNAMICcursors,thisitemcontainsthe approximatenumberofrows.
DECIMAL(31,0)
DB2_RETURN_STATUS AfteraCALLstatementthatinvokesan SQLprocedure,thisitemcontainsthe returnstatusiftheprocedurecontainsa RETURNstatement.
INTEGER
DB2_SQL_ATTR _CURSOR_HOLD
AfteranALLOCATEorOPENstatement, thisitemindicateswhetherthecursorcan beheldopenacrossmultipleunitsof work(YorN).
CHAR(1)
DB2_SQL_ATTR _CURSOR_ROWSET
AfteranALLOCATEorOPENstatement, thisitemindicateswhetherthecursorcan userowsetpositioning(YorN).
CHAR(1)
DB2_SQL_ATTR
_CURSOR_SCROLLABLE
AfteranALLOCATEorOPENstatement, thisitemindicateswhetherthecursoris scrollable(YorN).
CHAR(1)
DB2_SQL_ATTR
_CURSOR_SENSITIVITY
AfteranALLOCATEorOPENstatement, thisitemindicateswhetherthecursor showsupdatesmadebyotherprocesses (sensitivityIorS).
CHAR(1)
DB2_SQL_ATTR _CURSOR_TYPE
AfteranALLOCATEorOPENstatement, thisitemindicateswhetherthecursoris forward(F),declaredstatic(Sfor INSENSITIVEorSENSITIVESTATIC,or dynamic(DforSENSITIVEDYNAMIC).
CHAR(1)
MORE AfteranySQLstatement,thisitem
indicateswhethersomeconditionsitems werediscardedbecauseofinsufficient storage(YorN).
CHAR(1)
|
|
|
|
|
|
|
|
|
Table25.DatatypesforGETDIAGNOSTICSitemsthatreturnstatementinformation (continued)
Item Description Datatype
NUMBER AfteranySQLstatement,thisitem
containsthenumberofconditionitems.If nowarningorerroroccurred,orifno previousSQLstatementhasbeen
executed,thenumberthatisreturnedis1.
INTEGER
ROW_COUNT Afteraninsert,update,delete,orfetch, thisitemcontainsthenumberofrowsthat aredeleted,inserted,updated,orfetched.
AfterPREPARE,thisitemcontainsthe estimatednumberofresultrowsinthe preparedstatement.AfterTRUNCATE,it contains-1.
DECIMAL(31,0)
Table26.DatatypesforGETDIAGNOSTICSitemsthatreturnconditioninformation
Item Description Datatype
CATALOG_NAME Thisitemcontainstheservernameofthe tablethatownsaconstraintthatcausedan error,orthatcausedanaccessruleorcheck violation.
VARCHAR(128)
CONDITION_NUMBER Thisitemcontainsthenumberofthe condition.
INTEGER
CURSOR_NAME Thisitemcontainsthenameofacursorin aninvalidcursorstate.
VARCHAR(128)
DB2_ERROR_CODE1 Thisitemcontainsaninternalerrorcode. INTEGER DB2_ERROR_CODE2 Thisitemcontainsaninternalerrorcode. INTEGER DB2_ERROR_CODE3 Thisitemcontainsaninternalerrorcode. INTEGER DB2_ERROR_CODE4 Thisitemcontainsaninternalerrorcode. INTEGER DB2_INTERNAL
_ERROR_POINTER
Forsomeerrors,thisitemcontainsa negativevaluethatisaninternalerror pointer.
INTEGER
DB2_MESSAGE_ID ThisitemcontainsthemessageIDthat correspondstothemessagethatiscontained intheMESSAGE_TEXTdiagnosticitem.
CHAR(10)
DB2_MODULE_DETECTING _ERROR
AfteranySQLstatement,thisitemindicates whichmoduledetectedtheerror.
CHAR(8)
DB2_ORDINAL_TOKEN_n AfteranySQLstatement,thisitemcontains thenthtoken,wherenisavaluefrom1to 100.
VARCHAR(515)
DB2_REASON_CODE AfteranySQLstatement,thisitemcontains thereasoncodeforerrorsthathaveareason codetokeninthemessagetext.
INTEGER
DB2_RETURNED_SQLCODE AfteranySQLstatement,thisitemcontains theSQLCODEforthecondition.
INTEGER
DB2_ROW_NUMBER AfteranySQLstatementthatinvolves multiplerows,thisitemcontainstherow numberonwhichDB2detectedthe condition.
DECIMAL(31,0)
|
|
Table26.DatatypesforGETDIAGNOSTICSitemsthatreturnconditioninformation (continued)
Item Description Datatype
DB2_TOKEN_COUNT AfteranySQLstatement,thisitemcontains thenumberoftokensavailableforthe condition.
INTEGER
MESSAGE_TEXT AfteranySQLstatement,thisitemcontains themessagetextassociatedwiththe SQLCODE.
VARCHAR(32672)
RETURNED_SQLSTATE AfteranySQLstatement,thisitemcontains theSQLSTATEforthecondition.
CHAR(5)
SERVER_NAME AfteraCONNECT,DISCONNECT,orSET
CONNECTIONstatement,thisitemcontains thenameoftheserverspecifiedinthe statement.
VARCHAR(128)
Table27.DatatypesforGETDIAGNOSTICSitemsthatreturnconnectioninformation
Item Description Datatype
DB2_AUTHENTICATION_TYPE Thisitemcontainstheauthenticationtype(S, C,D,E,orblank).Formoreinformation aboutthevaluesfor
DB2_AUTHENTICATION_TYPE,seethe topic“GETDIAGNOSTICS”inDB2SQL Reference.
CHAR(1)
DB2_AUTHORIZATION_ID ThisitemcontainstheauthorizationIDthat isusedbytheconnectedserver.
VARCHAR(128)
DB2_CONNECTION_STATE Thisitemindicateswhethertheconnectionis unconnected(-1),local(0),orremote(1).
INTEGER
DB2_CONNECTION_STATUS Thisitemindicateswhetherupdatescanbe committedforthecurrentunitofwork(1for Yes,2forNo).
INTEGER
DB2_ENCRYPTION_TYPE Thisitemcontainsoneofthefollowing valuesthatindicatesthelevelofencryption fortheconnection:
A Onlytheauthenticationtokens (authidandpassword)are encrypted
D Allofthedatafortheconnectionis encrypted
CHAR(1)
DB2_SERVER_CLASS_NAME AfteraCONNECTorSETCONNECTION statement,thisitemcontainstheDB2server classname.
VARCHAR(128)
DB2_PRODUCT_ID ThisitemcontainstheDB2product
signature.
VARCHAR(8)