Similar Threads:
1.[Info-ingres] OpenAPI Caling a database procedure
Hi Grant et al,
I'm trying call a database procedure synchronously from an OpenAPI
application. The procedure has no parameters, all I want is the return
value. My understanding is that I set IIapi_query to say I'm executing a
database procedure. It will not do anything until the necessary
parameters (including procedure name and owner) are supplied and
filled in.
However, the code seems to hang at the initial iiapi_query() call.
I am using in order the following:
IIapi_query()
QueryParm.qy_queryType=IIAPI_QT_EXEC_PROCEDURE;
QueryParm.qy_queryText=NULL;
QueryParm.qy_parameters=TRUE;
I don't wait on gp_completed.
IIapi_setDescriptor()
setDescParm.sd_stmtHandle=QueryParm.qy_stmtHandle;
setDescParm.sd_descriptorCount=2;
I then allocate storage for two parameter descriptors for the
array setDescParm.sd_descriptor. In each element of which I
set ds_dataType = IIAPI_CHA_TYPE,
ds_nullable = FALSE,
ds_columnType = IIAPI_COL_SVCPARM
ds_columnName = NULL
I wait on gp_completed.
IIapi_putParms()
Fill in the procedure name, owner values described above, call
the procedure an wait on gp_completed.
At this point I wait on the IIapi_query to complete.
Then I call IIapi_get_QueryInfo to pick up the procedure return value.
Martin Bowes
Random Farscape Quote #26:
John - I think we have to put Grandma in a home.
Ka'Dargo - We could burn her.
John - You burn your old people!
Ka'Dargo - No, but in her case...
2.[Info-ingres] OpenAPI Weirdness
Hi Grant et al,
Sorry to bother you directly Grant, but I'm at my wits end on this one
and could use some advice. If anyone else in the newsgroup would like
to chip in 2c worth, I'd be happy too.
I've written a C program which has a subroutine full of API stuff. This
subroutine controls connecting to three databases in sequence to do
stuff. From the final database connection it reads in a lot (17511 rows)
of data to the program before disconnecting and then terminating the
API before returning to the main program.
All of which appears to work perfectly well. The data returned to the
program is exactly what is in the database.
But after the IIapi_terminate succeeds, the subroutine will return a
TRUE. Diagnostics indicates this is all happening. But the subroutine
NEVER returns to the main program. Instead it either loops? or causes
a coredump.
The code is literally:
main (...) {
if (Generate_Analysed_Data(&SayWhat)) {
printf("Generate_Analysed_Data completed OK!\n");
} else {
printf("Unexpected Error: Failed to Generate Analysed Data\n");
printf("Program Aborts\n");
exit (1);
};
} /*main*/
int Generate_Analysed_Data ( ParmDetails *buf) {
... stuff ...
/* Initialise OpenAPI */
if (!Init_API(&InitParm)) {return(FALSE);};
... Lots of stuff ...
/* In all cases we an now terminate the API connection */
printf("Terminate me!\n");
if (!Terminate_API) {
printf("Failure in API termination!\n");
ret_value=FALSE;
};
printf("Generate_Analysed_Data returns %d\n", ret_value);
return (ret_value);
} /*Generate_Analysed_Data*/
int Terminate_API (void) {
IIAPI_TERMPARM termParm;
IIapi_terminate(&termParm);
if ( termParm.tm_status != IIAPI_ST_SUCCESS ) {
printf( "Open_API::Terminate_API. Error in IIapi_terminate: %d\n",
termParm.tm_status );
};
return termParm.tm_status;
} /*Terminate_API*/
The diagnostic output is:
Terminate me!
Generate_Analysed_Data returns 1
Segmentation fault (core dumped)
I've run in api_trace mode (5) and the trace file (1.2M) is beautiful:
grep 'status =' $II_SYSTEM/ingres/files/api_trace.log| grep -v
SUCCESS
!IIapi_appCallback: request completed, status = NO_DATA
All the connects/disconnects are cool. All started statements are
closed, commits are issued etc.
I've run this on II2.5 and from an II2.6 installation using vnodes back to
the II2.5 database and the effect is the same.
Any Ideas gratefully received. I have the core dump and dbx but I have
no idea what I'm looking for or how to drive dbx....
Martin Bowes
Random Duckman Quote #20:
Ajax - By the hand of Zeus what manner of deviltry is this?
I mean... what gives?
3.[Info-ingres] OpenAPI Status Codes
4.[Info-ingres] OpenAPI error function called in wrong state
Hi Everyone,
As I'm just starting the joy of using API - why?Dont ask! Lets just say
the curiosity got the better of me.
I've managed to get a connection to the database! Yay! Well at least it
claims to have connected to the database. There is no sign of a
connection being started in iircp.log....
Now I'm struggeling to get a non select query to execute. It keeps
bitching about an API function called in the wrong state.
Anyone got any ideas?
The output from setting II_API_TRACE=5 and II_API_LOG to a suitable
file shows:
!IIapi_initAPI: initializing API.
!IIapi_initialize: INGRES API initialized, envHndl = 00000001400ED020
!IIapi_connect: connect to DBMS Server
!IIapi_connect: envHndl = 00000001400ED020, connHndl =
0000000000000000, tranHndl= 0000000000000000
!IIapi_connect: target = bowtest
!IIapi_thread(-1071947776): allocated local storage
0000000140097840
!IIapi_uiDispatch: dispatching event IIAPI_EV_CONNECT_FUNC
!Dispatch(-1071947776): SQL Conn [00000001400ED220] IDLE -->
REQ, 2 action(s)
!Dispatch(-1071947776): action[1] REMC
!Dispatch(-1071947776): action[2] CONN
!IIapi_query: starting a query
!IIapi_query: connHndl = 00000001400ED220, tranHndl =
0000000000000000, queryType = 0
!IIapi_query: queryText = drop table next_id
!IIapi_uiDispatch: dispatching event IIAPI_EV_QUERY_FUNC
!SQL Conn Evaluate: API function called in wrong state
!Dispatch(-1071947776): SQL Conn [00000001400ED220] REQ -->
REQ, 1 action(s)
!Dispatch(-1071947776): action[1] CBIF
!IIapi_appCallback: request completed, status = FAILURE
!IIapi_getErrorInfo: retrieving errors from API
!IIapi_getErrorInfo: handle = 00000001400ED220
Martin Bowes
--
Random Titus Quote #0:
Be normal and the crowd will accept you.
Be deranged, and they'll make you their leader.
<?xml version="1.0" ?><html>
<head>
<title></title>
</head>
<body>
<div align="left"><font face="Arial"><span style="font-size:10pt">Hi Everyone,</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">As I'm just starting the joy of using API - why?Dont ask! Lets just say
the curiosity got the better of me.</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I've managed to get a connection to the database! Yay! Well at least it
claims to have connected to the database. There is no sign of a
connection being started in iircp.log....</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Now I'm struggeling to get a non select query to execute. It keeps
bitching about an API function called in the wrong state.</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Anyone got any ideas?</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">The output from setting II_API_TRACE=5 and II_API_LOG to a suitable
file shows:</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_initAPI: initializing API.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_initialize: INGRES API initialized, envHndl = 00000001400ED020</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_connect: connect to DBMS Server</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_connect: envHndl = 00000001400ED020, connHndl =
0000000000000000, tranHndl= 0000000000000000</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_connect: target = bowtest</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_thread(-1071947776): allocated local storage
0000000140097840</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_uiDispatch: dispatching event IIAPI_EV_CONNECT_FUNC</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!Dispatch(-1071947776): SQL Conn [00000001400ED220] IDLE -->
REQ, 2 action(s)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!Dispatch(-1071947776): action[1] REMC</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!Dispatch(-1071947776): action[2] CONN</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_query: starting a query</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_query: connHndl = 00000001400ED220, tranHndl =
0000000000000000, queryType = 0</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_query: queryText = drop table next_id</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_uiDispatch: dispatching event IIAPI_EV_QUERY_FUNC</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"><b>!SQL Conn Evaluate: API function called in wrong state</b></span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!Dispatch(-1071947776): SQL Conn [00000001400ED220] REQ -->
REQ, 1 action(s)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!Dispatch(-1071947776): action[1] CBIF</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_appCallback: request completed, status = FAILURE</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_getErrorInfo: retrieving errors from API</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">!IIapi_getErrorInfo: handle = 00000001400ED220</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Martin Bowes</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">--</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Random Titus Quote #0:</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Be normal and the crowd will accept you.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Be deranged, and they'll make you their leader.</span></font></div>
<div align="left"></div>
</body>
</html>
5.[Info-ingres] OpenAPI Calling a database procedure
Hi.
If you are executing a procedure without params then sd_descriptorCount
should be 1. This could be the cause of the hang? The code below is what
I do within the PHP extension to support procedures without params. I
have tagged on the end the code for getting the return code from a
procedure.
queryParm.qy_genParm.gp_callback = NULL;
queryParm.qy_genParm.gp_closure = NULL;
queryParm.qy_connHandle = connHandle;
queryParm.qy_tranHandle = tranHandle;
queryParm.qy_stmtHandle = NULL;
queryParm.qy_queryType = IIAPI_QT_EXEC_PROCEDURE;
queryParm.qy_parameters = TRUE;
queryParm.qy_queryText = NULL;
IIapi_query(&queryParm);
while( queryParm.qy_genParm.gp_completed == FALSE )
IIapi_wait( &waitParm );
if (waitParm.wt_status != IIAPI_ST_SUCCESS)
{
... handle error ...
}
DescrBuffer = (IIAPI_DESCRIPTOR
*)ecalloc(sizeof(IIAPI_DESCRIPTOR),1);
setDescrParm.sd_genParm.gp_callback = NULL;
setDescrParm.sd_genParm.gp_closure = NULL;
setDescrParm.sd_stmtHandle = stmtHandle;
setDescrParm.sd_descriptorCount = 1; /* no params just
the name
of the
procedure */
setDescrParm.sd_descriptor = DescrBuffer;
setDescrParm.sd_descriptor[0].ds_dataType = IIAPI_CHA_TYPE;
setDescrParm.sd_descriptor[0].ds_length = strlen(procname);
setDescrParm.sd_descriptor[0].ds_nullable = FALSE;
setDescrParm.sd_descriptor[0].ds_precision = 0;
setDescrParm.sd_descriptor[0].ds_scale = 0;
setDescrParm.sd_descriptor[0].ds_columnType = IIAPI_COL_SVCPARM;
setDescrParm.sd_descriptor[0].ds_columnName = NULL;
IIapi_setDescriptor( &setDescrParm );
while( setDescrParm.sd_genParm.gp_completed == FALSE )
IIapi_wait( &waitParm );
if (waitParm.wt_status != IIAPI_ST_SUCCESS)
{
... handle error ...
}
DataBuffer = (IIAPI_DATAVALUE
*)calloc(sizeof(IIAPI_DATAVALUE),1);
putParmParm.pp_genParm.gp_callback = NULL;
putParmParm.pp_genParm.gp_closure = NULL;
putParmParm.pp_stmtHandle = stmtHandle;
putParmParm.pp_parmCount = setDescrParm.sd_descriptorCount;
putParmParm.pp_parmData = DataBuffer;
putParmParm.pp_moreSegments = 0;
putParmParm.pp_parmData[0].dv_null = FALSE;
putParmParm.pp_parmData[0].dv_length = strlen(procname );
putParmParm.pp_parmData[0].dv_value = procname;
IIapi_putParms( &putParmParm );
while( putParmParm.pp_genParm.gp_completed == FALSE )
IIapi_wait( &waitParm );
if (waitParm.wt_status != IIAPI_ST_SUCCESS)
{
... handle error ...
}
getDescrParm.gd_genParm.gp_callback = NULL;
getDescrParm.gd_genParm.gp_closure = NULL;
getDescrParm.gd_stmtHandle = stmtHandle;
IIapi_getDescriptor(&getDescrParm);
while( getDescrParm.gd_genParm.gp_completed == FALSE )
IIapi_wait( &waitParm );
if (waitParm.wt_status != IIAPI_ST_SUCCESS)
{
... handle error ...
}
getQInfoParm.gq_genParm.gp_callback = NULL;
getQInfoParm.gq_genParm.gp_closure = NULL;
getQInfoParm.gq_stmtHandle = queryParm.qy_stmtHandle;
IIapi_getQueryInfo( &getQInfoParm );
while( getQInfoParm.gq_genParm.gp_completed == FALSE )
IIapi_wait( &waitParm );
if (waitParm.wt_status != IIAPI_ST_SUCCESS)
{
... handle error ...
}
if ( getQInfoParm.gq_mask & IIAPI_GQ_PROCEDURE_RET )
{
/* we have a return value */
returnvalue = getQInfoParm.gq_procedureReturn;
}
Note if you want to return rows via a procedure a call to
IIapi_getQueryInfo() will destroy the row data being returned. I believe
the same is true for returning byref values in a procedure. I have not
worked out how to deal with this yet other than documenting it in big
neon letters.
> -----Original Message-----
> From: XXXX@XXXXX.COM [mailto: XXXX@XXXXX.COM ]
> Sent: Wednesday, July 13, 2005 2:53 PM
> Subject: OpenAPI Caling a database procedure
>
> Hi Grant et al,
>
> I'm trying call a database procedure synchronously from an OpenAPI
> application. The procedure has no parameters, all I want is the return
> value. My understanding is that I set IIapi_query to say I'm executing
a
> database procedure. It will not do anything until the necessary
> parameters (including procedure name and owner) are supplied and
> filled in.
>
> However, the code seems to hang at the initial iiapi_query() call.
>
> I am using in order the following:
> IIapi_query()
> QueryParm.qy_queryType=IIAPI_QT_EXEC_PROCEDURE;
> QueryParm.qy_queryText=NULL;
> QueryParm.qy_parameters=TRUE;
> I don't wait on gp_completed.
>
> IIapi_setDescriptor()
> setDescParm.sd_stmtHandle=QueryParm.qy_stmtHandle;
> setDescParm.sd_descriptorCount=2;
>
> I then allocate storage for two parameter descriptors for the
> array setDescParm.sd_descriptor. In each element of which I
> set ds_dataType = IIAPI_CHA_TYPE,
> ds_nullable = FALSE,
> ds_columnType = IIAPI_COL_SVCPARM
> ds_columnName = NULL
>
> I wait on gp_completed.
>
> IIapi_putParms()
> Fill in the procedure name, owner values described above, call
> the procedure an wait on gp_completed.
>
> At this point I wait on the IIapi_query to complete.
> Then I call IIapi_get_QueryInfo to pick up the procedure return value.
>
> Martin Bowes
> --
> Random Farscape Quote #26:
> John - I think we have to put Grandma in a home.
> Ka'Dargo - We could burn her.
> John - You burn your old people!
> Ka'Dargo - No, but in her case...
>
>
6. [Info-ingres] OpenAPI Status Codes
7. [Info-ingres] OpenAPI connect - what am I missing?
8. [Info-ingres] Tru64 UNIX Kernel parameters for Ingres 2.0