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

Home -> Community -> Usenet -> c.d.o.misc -> OCIBindByName & arrays of strings

OCIBindByName & arrays of strings

From: Herode <cbrun_at_geomapgis.com>
Date: 17 Mar 2006 08:38:07 -0800
Message-ID: <1142613486.974832.275440@j33g2000cwa.googlegroups.com>


One more question on OCI, and the last one I hope before i'm done with this task...

I'm trying to bind arays. It works with intergers and doubles & so on. But I can't find what to do with strings. The column for th einsert is VARCHAR2[75]. A code such as :
[code]
  char* linkedStrings[ 3 ];
  linkedStrings[ 0 ] = new char[ 2 ];
  strcpy( linkedStrings[ 0 ], "A" );
  linkedStrings[ 1 ] = new char[ 2 ];
  strcpy( linkedStrings[ 1 ], "B" );
  linkedStrings[ 2 ] = new char[ 2 ];
  strcpy( linkedStrings[ 2 ], "C" );

  ub2 eltSizes3[ 3 ];

  eltSizes3[ 0 ] = strlen( linkedStrings[ 0 ] ) + 1;
  eltSizes3[ 1 ] = strlen( linkedStrings[ 1 ] ) + 1;
  eltSizes3[ 2 ] = strlen( linkedStrings[ 2 ] ) + 1;

  OCIBind* pBindh3;
  char* name3 = ":col5";
  st = ::OCIBindByName( m_pStmt, &pBindh3, m_pErr,

                        reinterpret_cast< text* >( name3 ), strlen(
name3 ),
                        &linkedStrings, 2, SQLT_VCS,
                        NULL, (ub2*) eltSizes3, NULL,
                        0, NULL, OCI_DEFAULT );
  if ( st != OCI_SUCCESS && st != OCI_SUCCESS_WITH_INFO ) {     CString ret = GetErrorText( m_pErr );     cout << ret.GetBuffer( 0 ) << endl;
    return false;
}

  st = ::OCIStmtExecute( m_pService, m_pStmt, m_pErr, iters, 0, NULL, NULL, OCI_DEFAULT );
  if ( st != OCI_SUCCESS && st != OCI_SUCCESS_WITH_INFO ) {     CString ret = GetErrorText( m_pErr );     cout << ret.GetBuffer( 0 ) << endl;
    return false;
}

[/code]
throws an ORA-01459 error : invalid length for a variable length string

If I use the SQLT_STR instead, I have the ORA-01480 : undefined value @  not found at the end of the string (here : @ stands for an unreadable character on the output console... : 0x00 maybe ? )

If I use SQLT_CHR (removing the +1 for strlen or leaving it...), the 3 inserts are done, but the inserted values are unreadable characters.

What should I do ????????
:o( Received on Fri Mar 17 2006 - 10:38:07 CST

Original text of this message

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