Pergunta

I have some legacy Pro*C code using the kind of constructs below.
This kind of pattern is found on online forums but nothing in the Oracle documentation.
In particular, Google can't find any doc about "sqhsts" on the Oracle website.

Is this pattern documented somewhere?
Is it considered a good programming practice?

/* cud (compilation unit data) array */
static const short sqlcud0[] =
{10,4130,832,0,0,
5,0,0,1,0,0,27,23,0,0,4,4,0,1,0,1,97,0,0,1,97,0,0,1,97,0,0,1,10,0,0,
36,0,0,2,30,0,4,25,0,0,1,0,0,1,0,2,97,0,0,
};

/* EXEC SQL CONNECT :user IDENTIFIED BY :pwd USING :url; */ 

{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 10;
sqlstm.arrsiz = 4;
sqlstm.sqladtp = &sqladt;
sqlstm.sqltdsp = &sqltds;
sqlstm.iters = (unsigned int )10;
sqlstm.offset = (unsigned int )5;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)256;
sqlstm.occurs = (unsigned int )0;
sqlstm.sqhstv[0] = ( void *)user;
sqlstm.sqhstl[0] = (unsigned int )0;
sqlstm.sqhsts[0] = ( int )0;
sqlstm.sqindv[0] = ( void *)0;
sqlstm.sqinds[0] = ( int )0;
sqlstm.sqharm[0] = (unsigned int )0;
sqlstm.sqadto[0] = (unsigned short )0;
sqlstm.sqtdso[0] = (unsigned short )0;
sqlstm.sqhstv[1] = ( void *)pwd;
sqlstm.sqhstl[1] = (unsigned int )0;
sqlstm.sqhsts[1] = ( int )0;
sqlstm.sqindv[1] = ( void *)0;
sqlstm.sqinds[1] = ( int )0;
sqlstm.sqharm[1] = (unsigned int )0;
sqlstm.sqadto[1] = (unsigned short )0;
sqlstm.sqtdso[1] = (unsigned short )0;
sqlstm.sqhstv[2] = ( void *)url;

(code copied from here but similar to mine)

Foi útil?

Solução

Pro*C creates low level C from statements like

EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL END DECLARE SECTION;

Which creates OCI-like descriptors of each data item you declare. Other statements (EXEC SQL ...;) where you embed sql with those bound variables are then translated to a lower level series of calls using what was encoded in the declare section. Pro*C is old. I worked on the first beta of Pro*C 25+ years ago. ...not recommended.

The code generated by Pro*C pre-compilation does not always do perfectly when compiled by modern compilers with warnings enabled. It also is not meant to be readable. If you want to learn OCI programming, you can get what is going on. Not really recommended, either, unless you want to do some special tasks.

Example task: OCI is used to create external C/C++ libraries for Oracle. It pretty much lets you work with almost anything you would want to do in oracle, at a fine grain level. Start here:

http://www.oracle.com/technetwork/database/features/oci/index.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top