For encodings issues, I have some manipulations before storing data into the database.
To do so I'm making use of the DUMP
and CHR
sql methods to safely keep all ma data intact when saving/retrieving them.
Here are my steps when I save information into the database :
- Getting the strings, mostly cyrillic in my case, things like
АЛЕКСЕЕВИЧ
- I convert them in c# into Windows-1252 encoding, the strings look like this
ÀËÅÊÑÅÅÂÈ×
At this point, in most cases I can register the data as is using a DBParameter
. But for some reasons there are some troublesome characters that looses information (they are all transformed into the same "?") when saving them from c# to the database. That's the case with the "×" just above.
- So when this happens, I convert them into bytes and into SQL format :
CHR(192) || CHR(203) || CHR(197) || CHR(202) || CHR(209) || CHR(197) || CHR(197) || CHR(194) || CHR(200) || CHR(215)
- Then using regex I'm replacing the part where I should usually use a
DBParameter
with the sql code I just generated. It should still be safe to injections.
There I have a working code, only for cases where I have the SQL request within my code. The complicated part is when I have a stored procedure I can't modify. I can't create a parameter that will be interpreted since that's the exact purpose of DBParameter
, to block all sql injection. I'm blank with ideas at this point.