ade_errstatement

Land Desktop Development ARX CPP SDK

Up a level
ade_errstatement
 
 

Gets the faulty SQL statement for a given error in the stack .

struct resbuf*

ade_errstatement(

int err_index);

Returns a statement (string) and a starting position (short), or NULL

err_index Position of the error in the stack
0 = first error

The SQL statement and error position are returned in the following format.

(faulty_statement err_pos)

The faulty_statement string quotes the faulty SQL statement that caused the error. The err_pos value identifies the starting position of the error in the faulty statement. Position 1 is the first character of the statement.

The expression (ade_errstatement 2), which references the third error in the stack, could return

("xxx" 6)

where "xxx" is the faulty statement and 6 tells you that the trouble begins at the sixth character.

You must release the resbuf.

The following sample concludes by printing a faulty SQL statement to the screen.

The first step is to define a SQL query containing a faulty SQL statement which is in a resbuf. Ade_qrydefine() is then called with all required parameters. The error stack is cleared using ade_errclear() and the query is executed using ade_qryexecute(). The error stack is checked for any new errors using ade_errqty(), and if they exist a resbuf is populated with the SQL Select statement and the position that the syntactic error occured. The contents of the resbuf are displayed and all resbufs are released as required.

char* pszJoinOperator = "";     // none
char* pszBgnCondGrouping = "";  // none
char* pszNotOperator = "";      // none
char* pszCondType = "SQL";
char* pszEndCondGrouping = "";  // none

struct resbuf* pQueryConditionRb = acutBuildList(
                                     RTLB,
                                       RTSTR, "BlockGroup",
                                       RTSTR, "AMERI_ES == 0",
                                     RTLE,
                                     0 );
ade_id queryId = ade_qrydefine(
                                pszJoinOperator,
                                pszBgnCondGrouping,
                                pszNotOperator,
                                pszCondType,
                                pQueryConditionRb,
                                pszEndCondGrouping);
int returnCode = ade_errclear();
ads_real queriedObjs = ade_qryexecute();
int errorStkQnty = ade_errqty();
if (errorStkQnty > 0)
{
    struct resbuf* pErrStatementRb = ade_errstatement(0);
    if (NULL != pErrStatementRb){
        struct resbuf* rb = pErrStatementRb;
        while(NULL != rb) {
            if (rb->restype == RTSTR) {
                if (_tcslen(rb->resval.rstring) != 0)
                {
                    acutPrintf("\n\nThe faulty SQL statement is: \n\n\t\"%s\""
                        , rb->resval.rstring);

                    acutPrintf("\n\n\t\tThe syntax error has occured at character: %d"
                        , rb->rbnext->resval.rint);
                }
            }
            rb = rb->rbnext;
        }
    }
    else {
        acutPrintf(
            "\nNo error statements were returned.");
    }
    acutRelRb(pErrStatementRb);
}
else
{
    acutPrintf("\nNo errors were encountered.");
}
acutRelRb(pQueryConditionRb);