Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Dynamicaly OCIDefineByPos

Re: Dynamicaly OCIDefineByPos

From: Markus M. Mueller <markus-m.mueller_at_ubs.com>
Date: Thu, 12 Nov 1998 18:02:41 +0100
Message-ID: <364B14B1.2F2F46E@ubs.com>


The following code can give you a hint. And maybe you can solve my problem!

Regards
Markus

     1 //////////// start code fragment

/////////////////////////////////////
     2	   ...
     3	   ora_rc = OCIStmtPrepare( pOraStmt,
     4	                            pOraError,
     5	                            (text*)gszStmt,
     6	                            strlen(gszStmt),
     7	                            OCI_NTV_SYNTAX,
     8	                            OCI_DEFAULT      );
       
     9	   printf( "status after OCIStmtPrepare: " );
    10	   ORA_DispError( pOraError, ora_rc );
       
    11	   ora_rc = OCIStmtExecute( pOraService,
    12	                            pOraStmt,
    13	                            pOraError,
    14	                            0,               // iteration for non
SELECT calls
    15	                            0,
    16	                            NULL,
    17	                            NULL,
    18	                            0                );
       
    19	   printf( "status after OCIStmtExecute: " );
    20	   ORA_DispError( pOraError, ora_rc );
       
       
    21	   /*                          */
    22	   /* get statistic info       */
    23	   /*                          */
       
    24	   ora_rc = OCIAttrGet( pOraStmt, OCI_HTYPE_STMT,
    25	                        &nCols, NULL,
    26	                        OCI_ATTR_PARAM_COUNT, pOraError );
    27	   
       
    28	   ora_rc = OCIAttrGet( pOraStmt, OCI_HTYPE_STMT,
    29	                        &nRows, NULL,
    30	                        OCI_ATTR_ROW_COUNT, pOraError );
       
       
    31	   printf( "status after OCIAttrGet - OCI_ATTR_ROW_COUNT: " );
    32	   ORA_DispError( pOraError, ora_rc );
       
       
    33	   printf( "number of columns: %ld\n", nCols );
    34	   printf( "number of rows   : %ld\n", nRows );
       
    35	   if ( nCols > MAX_COL_SUPPORTED )
    36	   {
    37	      printf( "panic, max Cols supported = %ld\n",
MAX_COL_SUPPORTED );
    38	      exit(1);
    39	   }
       
       
    40	   /*                           */
    41	   /* allocate some storage     */
    42	   /*                           */
       
    43	   // allocate the bind buffers
       
    44	   for( ii=0; ii < nCols; ii++ )
    45	   {
    46	      ub4   nLen  = 0;
    47	      ub1   nType = 0;
    48	      ub4   nSize = 0;
       
    49	      // get infos about the column
       
    50	      ora_rc = OCIParamGet( pOraStmt, OCI_HTYPE_STMT, pOraError,
    51	                            &(colinfo[ii].pParamData), ii+1     
);
       
    52	      // store col type
    53	      ora_rc = OCIAttrGet( colinfo[ii].pParamData,
OCI_DTYPE_PARAM, 
    54	                           &(colinfo[ii].col_type), 0,
    55	                           OCI_ATTR_DATA_TYPE, pOraError );
       
    56	      // get required memory
    57	      ora_rc = OCIAttrGet( colinfo[ii].pParamData,
OCI_DTYPE_PARAM, 
    58	                           &(colinfo[ii].buf_len), 0,
    59	                           OCI_ATTR_DATA_SIZE, pOraError );
       
    60	      // get col name
    61	      ora_rc = OCIAttrGet( colinfo[ii].pParamData,
OCI_DTYPE_PARAM, 
    62	                           (dvoid*)&(colinfo[ii].col_name),
&nSize,
    63	                           OCI_ATTR_NAME, pOraError );
       
    64	      /*            */  
    65	      /* debug info */
    66	      /*            */
    67	//      *(pszColName+nSize)=0;
       
    68	      printf( "size = %u\n", nSize );
       
    69	      printf( "datatype=%d, colname=%s, datasize=%u ",
    70	              colinfo[ii].col_type,
    71	              colinfo[ii].col_name,
    72	              colinfo[ii].buf_len );      
       
       
    73	   	printf( "loop OCIAttrGet: %d ", ii );
    74	   	ORA_DispError( pOraError, ora_rc );
       
    75	   }
    76	   ...
    77	//////////////////////// end code fragemnt
///////////////////////////
       
       
    78	//////////////////////// start output
////////////////////////////////
    79	start...
    80	status after OCISessionBegin: OCI_SUCCESS
    81	status after ORA_ServiceSetSession: OCI_SUCCESS
    82	status after OCIStmtPrepare: OCI_SUCCESS
    83	status after OCIStmtExecute: OCI_SUCCESS
    84	status after OCIAttrGet - OCI_ATTR_ROW_COUNT: OCI_SUCCESS
    85	number of columns: 4
    86	number of rows   : 0
    87	size = 4
    88	datatype=12, colname=DGEBID, datasize=7 loop OCIAttrGet: 0
OCI_SUCCESS
    89	size = 2
    90	datatype=2, colname=ID, datasize=22 loop OCIAttrGet: 1
OCI_SUCCESS
    91	size = 4
    92	datatype=96, colname=NAMEVNAME, datasize=30 loop OCIAttrGet: 2
OCI_SUCCESS
    93	size = 5
    94	datatype=1, colname=VNAME, datasize=30 loop OCIAttrGet: 3
OCI_SUCCESS
    95	### end ###
    96	//////////////////////// end output
//////////////////////////////////



Christian Fruth wrote:
>
> Hi
>
> Here's my Problem:
> I want to write a c++-class which use
> OCI. The problem is that when an other programmer
> executes for example TOCI->Query("SELECT * FROM MYTABLE");
> my class don't know how many OCIDefineByPos it has to make.
> Also it doesn't know from which type the Cols are.
> Is there a Type like Variant ?
>
> The programmer should be possible to deside AFTER the Query
> which type he want's to use. For Example
> TOCI->FieldByName["Name"]->AsString().
> or
> TOCI->FieldByPos[5]->AsInteger().
>
> But i have no idea how to do that with OCI.
>
> Ciao
> Christian Fruth
Received on Thu Nov 12 1998 - 11:02:41 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US