1. More Help

I"m trying to put escape char in front of ",',\, ascii 0 that are in a binary file (PDF in this case). I then want to put the sequence into a mysql blob column but get a syntax error from mysql. Here is the mysql doc

If you want to insert binary data into a string column (such as a BLOB), the following characters must be represented by escape sequences:

NUL NUL byte (ASCII 0). Represent this character by `\0' (a backslash followed by an ASCII `0' character).

\ Backslash (ASCII 92). Represent this character by `
'.

' Single quote (ASCII 39). Represent this character by `\''.

" Double quote (ASCII 34). Represent this character by `\"'.

When writing application programs, any string that might contain any of these special characters must be properly escaped before the string is used as a data value in an SQL statement that is sent to the MySQL server.

Here's the code. Do you see a problem?

         	tmpString={} 
         	for j = 1 to len (outRecord[i]) do 
         		if find(outRecord[i][j], {92,39,34,0}) then --\,',", ascii 0 
         			tmpString &= 92 & outRecord[i][j] 
         		else 
         			tmpString &= outRecord[i][j] 
         		end if 
         	end for 
         	if fileControl[t][i] = 0 then 
	        	tmp &= ", \"" & tmpString & "\"" 
	        else 
	         tmp &= ", " & tmpString 
	        end if  
new topic     » topic index » view message » categorize

2. Re: More Help

The problem is that your escaped code still contains NUL bytes. A NUL must be replaced by a backslash followed by an ASCII zero. What you have is a backslash followed by the original byte (a NUL).

constant escapee = "\\'\"" & 0 
constant escaped = "\\'\"0" 
tmpString={} 
for j = 1 to len (outRecord[i]) do 
  n = find(outRecord[i][j], escapee) 
  if n != 0 then  
    tmpString &= '\\' & escaped[n] 
  else 
    tmpString &= outRecord[i][j] 
  end if 
end for 

[/quote]

new topic     » goto parent     » topic index » view message » categorize

3. Re: More Help

Thanks Derek! Don't know why I didn't see that. I looked at it for hours & hours.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu