Escaping Data with PgSqlLoader
Posted: Wed 17 Apr 2013 01:13
I recently upgraded to 6.6.217 and have found that the escaping of CrLf no longer work properly. Here is what I used to do.
When I read the data back, it would read perfectly. Now it will fail with 'literal newline found in data'. I have found that if I change from protocol 2 to 3 and then change to binary mode, I can write the data properly without doing any escaping. I would still like to know how to escape the data properly with protocol 2.
I have tried changing to \n\r and \012\015 but these are written into the data as is instead of being written as CrLf. I also tries various combinations trying E'string' but to no avail.
I do have a test program that will show off this issue if you would like it.
Code: Select all
loader.Connection = conn
loader.CreateColumns()
loader.Open()
ret = Me.TextBox1.Text
ret = ret.Replace("'", "''") ' ' -> ''
ret = ret.Replace("\", "\\") ' \ -> \\
ret = ret.Replace(vbLf, "\" & vbLf) ' Lf -> \Lf
ret = ret.Replace(vbCr, "\" & vbCr) ' Cr -> \Cr
ret = ret.Replace(vbCrLf, "\" & vbCr & "\" & vbLf) ' CrLf -> \Cr\Lf
pg_escape_string = ret
loader.SetValue("field1", pg_escape_string)
loader.NextRow()
loader.Close()
I have tried changing to \n\r and \012\015 but these are written into the data as is instead of being written as CrLf. I also tries various combinations trying E'string' but to no avail.
I do have a test program that will show off this issue if you would like it.