----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, July 20, 2004 10:02 PM Subject: [sqlite] How to handle slashes (\) in text columns
> I'm using the TCL binding of SQLITE and was trying to figure out how to > enter various characters into a text column. To enter a slash, all I > normally would do is to append another slash to it. However, this only > works fine if the slash is not the last character in the field. Consider > the following: > > % db eval "insert into t1 values('\')" > % <-- no character > > % db eval "insert into t1 values('\\')" > % \\ <-- slash did not escape!! > > % db eval "insert into t1 values('\\TEST')" > % \TEST <-- returns as expected > > % db eval "insert into t1 values('TEST\\')" > % TEST\\ <-- slash did not escape!! > > % db eval "insert into t1 values('\\TEST\\')" > % \\TEST\\ <-- now not even the first slash was escaped!! > > In short, what I'm asking is how can I insert text with one slash at the > end? I'm rather rusty on Tcl, but I think that this is what tcl'ers refer to as quoting hell. The short answer is that you need 4 slashes, e.g. db eval "insert into t1 values('\\\\')" The reason goes something like this - the first pass of the quoted stuff expands variables and does the slash escaping which leaves us with 2 slashes. The eval then causes the slash escaping to happen again. There may be better ways to handle this ?. I did a quick search but didn't come up with any conclusive. You could ask this question on comp.lang.tcl and see if they have a cleaner suggestion if no-one else here replies. Lawrence --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.721 / Virus Database: 477 - Release Date: 16/07/04