special character("\")

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
tqtrung
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 15.09.2006, 03:13

special character("\")

Post by tqtrung »

Hi!!!
I am using Delphi 7.0 with your ZComponent to connect PostgreSQL.
When I query table has 1 field which have data : '\\th-svr01\soft' so I receive '\th-svr01・t'.
is there any body show me to fix this bug ?

ps: I insert into that table by UTF8string.


Thanks a lot
chris_had
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 30.11.2006, 12:48

Post by chris_had »

Hi tqtrung,

Although I have not directly used Postgress, I do have the same problem on MS SQL and MySQL.

The problem you are experiencing is common to many SQL databases, and it relates to the fact that the backslash character ('\') is normally a reserved character within their dbms.

There are a number of solutions to resolving it, but the one I use is to insert two backslashes which gets interpreted as one backslash by the SQL database.

For example, you could use the Delphi function AnsiReplaceStr() to replace all instances of '\' with '\\'. This will work for any string that contains one or more '\' chars. It even works for network paths, as it will swap '\\' to be '\\\\'.

When you insert two backslashes into a Database String field, this is commonly interpreted as a single backslash.

MyString := AnsiReplaceStr(MyString, '\', '\\');

For more information, you can check the DelphiBasics website:
http://www.delphibasics.co.uk/RTL.asp?N ... ReplaceStr

I hope that helps,
Chris
Post Reply