Menu

Best way to bind to char[x] datatypes

OTL
2002-11-12
2024-03-26
  • Nobody/Anonymous

    Using Oracle, we are doing some simple selects from a table that has CHAR[x] fields.  We are using null-terminated char* strings and have run into some snags reconciling differences in padding between the two datatypes.

    As an example, say we have a field SOME_FIELD in SOME_TABLE defined to be CHAR[3].  Given the following statement:

    SELECT * FROM SOME_TB
    WHERE SOME_FIELD=:var<char[4]>

    Even saying one value of SOME_FIELD is "AB ", sending an unpadded "AB" will match no fields in the database.  Since OCI can handle the difference without padding, I'm confident that the OTL can also.  I just dont know how.  What is the cleanest way other users have found to deal with this problem? 

     
    • Sergei Kuchin

      Sergei Kuchin - 2002-11-13

      This will do the trick:

      SELECT * FROM SOME_TB
      WHERE SOME_FIELD=
         RPAD(:var<char[4]>,
                    VSIZE(SOME_FIELD),
                     '  ')

      OTL should have had a "padded char[xxx]" type, say, charz[XXX], but it doesn't in reality, because of low demand. Also, it's more difficult to implement  the "fixed size string" semantic in C++ itself, since all string comparisons are "variable-length" based.

       
    • Nobody/Anonymous

      Thanks Sergei, this will do just fine!

       
  • Wojtek123

    Wojtek123 - 2024-03-26

    Hi,
    I have the same problem with fixed-length field CHAR[x] used in WHERE clause. Unfortunately I cannot modify SQL statement. Would it be possible to fix this in OTL? You mentioned that there is a problem with implementing this. What kind of problem is it? Maybe I could fix it if you would give me some hint how to do this?

     

Log in to post a comment.