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 -> Re: Preparing unicode SQL statements in OCI

Re: Preparing unicode SQL statements in OCI

From: Michael J. Skarpelos <mskarpelos_at_nquire.com>
Date: 25 Oct 2001 16:11:56 -0700
Message-ID: <abfca438.0110251511.576378b@posting.google.com>


After poking around the documentation some more and running some small test programs, I think I've figured out the solution. It's a two step process:

  1. Convert the SQL statement in unicode to an array of OCIWchar. (Do this in C/C++ using simple type casting inside a for loop that walks the unicode string).
  2. Call the routine OCIWideCharToMultiByte() supplying the array of OCIWchar from step 1 above as the source. Note that you can calculate the size of multi-byte destination buffer by walking the array of OCIWchar inside a for loop and calling OCIWideCharMultiByteLen() on each character. Also, remember to count the null terminator. I forgot to do this and stomped over memory causing an access violation.

  The resulting multi-byte encoding of the SQL statement can be supplied to OCIStmtPrepare().

Michael Skarpelos

mskarpelos_at_nquire.com (Michael J. Skarpelos) wrote in message news:<abfca438.0110151653.158be90e_at_posting.google.com>...
> The OCI 8i (8.1.5) documentation shows how bind unicode input
> variables and define unicode output variables, but what if the SQL
> statement itself is in unicode (for example, to access unicode column
> names or table names, or to specify unicode character literals in the
> WHERE and HAVING clauses)? Is there a way to prepare such a unicode
> SQL statement? I would have expected a flag parameter to
> OCIStmtPrepare() indicating unicode SQL text, but unfortunately it
> doesn't seem to be that simple.
>
> Michael Skarpelos
Received on Thu Oct 25 2001 - 18:11:56 CDT

Original text of this message

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