• Uncategorized

About c++ : Legacy-proc-CC-code-with-sectional-symbol§

Question Detail

I am maintaining a legacy oracle proc C/C++ code which is processing a text file and updates the DB. In the code they are preparing a SELECT statement which looks something like this

SELECT 'ERROR_ID=§' || ERROR_ID ||  '§'  || ' AND ' ...

and after executing the select statement, they are getting the data as shown below in a char array.


later they are replacing the sectional symbol(§) with single quotes as shown below


Basically they are getting the primary keys from the DB (old primary key)and and comparing the primary key which are present in the text file (new keys).
They are using simple strcmp to compare the these primary keys.

Now I am getting an issue. Even though old and new the primary keys are matching, if I look at the log file, these question marks are coming instead of single quotes.

ERROR_ID=?ASI:10? AND FORM_ID=?064956?  - old key
ERROR_ID='ASI:10' AND FORM_ID='064956'  - new key

I am guessing that, since they are using the sectional symbol(§) in the code which is a non ASCII char, it is failing.

Please suggest.

The same binary is deployed in different environments. On some of the environments, sectional symbol(§) the is getting replaced with ‘?’ marks, and on some it is working fine.
Are there any environment setting that is affecting this? If yes, what I should look for.

OS on all the environments is: SunOS 5.10

Question Answer

Your executable probably doesn’t set any locale. So your program runs with the locale set by the environment. I suggest setting the locale from inside your code for example: setlocale(LC_ALL, “C”);
before anything else runs.

I think the approach is incorrect. I think you should

  1. Read the text file, translating to wchar_t making sure you have the right locale for the text file. Whether it is a Fixed Width Character Set (Codepages in Bytes, UCS-2), Multi Byte Character Set (UTF-8, others) you will wind up with fixed width character set in wchar_t.
  2. Construct the SQL as a wstring. Now ‘§’ should correct regardless of input file.
  3. Execute the SQL.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.