Skip to content

Commit 6f881a6

Browse files
Fix escaped codes in TDF data export
Using interim substitution character (Chr(26)) to ensure that escaped codes do not collide with existing data. Fixes #251
1 parent c6ae816 commit 6f881a6

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

Version Control.accda.src/modules/clsDbTableData.cls

+40-13
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ Public Sub ExportTableDataAsTDF(strTable As String)
9797
intCnt = 0
9898
For Each fld In rst.Fields
9999
' Format for TDF format without line breaks
100-
strText = MultiReplace(Nz(fld.Value), _
101-
"\", "\\", _
102-
vbCrLf, "{\r\n}", _
103-
vbCr, "{\r}", _
104-
vbLf, "{\n}", _
105-
vbTab, "{\t}")
106-
cData.Add strText
100+
cData.Add FormatStringForTDF(Nz(fld.Value))
107101
intCnt = intCnt + 1
108102
If intCnt < intFields Then cData.Add vbTab
109103
Next fld
@@ -191,12 +185,7 @@ Private Sub ImportTableDataTDF(strFile As String)
191185
End If
192186
Else
193187
' Perform any needed replacements
194-
strValue = MultiReplace(CStr(varLine(intCol)), _
195-
"\\", "\", _
196-
"{\r\n}", vbCrLf, _
197-
"{\r}", vbCr, _
198-
"{\n}", vbLf, _
199-
"{\t}", vbTab)
188+
strValue = FormatStringFromTDF(CStr(varLine(intCol)))
200189
If strValue <> CStr(varLine(intCol)) Then
201190
' Use replaced string value
202191
rst.Fields(varHeader(intCol)).Value = strValue
@@ -220,6 +209,44 @@ Private Sub ImportTableDataTDF(strFile As String)
220209
End Sub
221210

222211

212+
'---------------------------------------------------------------------------------------
213+
' Procedure : FormatStringForTDF
214+
' Author : Adam Waller
215+
' Date : 7/16/2021
216+
' Purpose : Replace line feeds and similar characters with escaped codes for
217+
' : representation in tab-delimited format.
218+
' : (Using Chr(26) as interim placeholder) See #251
219+
'---------------------------------------------------------------------------------------
220+
'
221+
Private Function FormatStringForTDF(strValue As String) As String
222+
FormatStringForTDF = MultiReplace(strValue, _
223+
"\", Chr$(26), _
224+
vbCrLf, "\r\n", _
225+
vbCr, "\r", _
226+
vbLf, "\n", _
227+
vbTab, "\t", _
228+
Chr$(26), "\\")
229+
End Function
230+
231+
232+
'---------------------------------------------------------------------------------------
233+
' Procedure : FormatStringFromTDF
234+
' Author : Adam Waller
235+
' Date : 7/16/2021
236+
' Purpose : Restore original characters from escaped codes.
237+
'---------------------------------------------------------------------------------------
238+
'
239+
Private Function FormatStringFromTDF(strTDFValue) As String
240+
FormatStringFromTDF = MultiReplace(strTDFValue, _
241+
"\\", Chr$(26), _
242+
"\r\n", vbCrLf, _
243+
"\r", vbCr, _
244+
"\n", vbLf, _
245+
"\t", vbTab, _
246+
Chr$(26), "\")
247+
End Function
248+
249+
223250
'---------------------------------------------------------------------------------------
224251
' Procedure : GetTableExportSql
225252
' Author : Adam Waller

0 commit comments

Comments
 (0)