Hi Breck
After a lot of discussion with SQL Anywhere Support and PowerBuilder Support we reached the conclusion that we were pretty much on our own - I still feel that when using a data control like PowerBuilder and disabling Bind variables - there should be a way in the connection to turn off escape processing in the interface. Otherwise you may find "\" entered by users in text fields (or hidden in RichText) being translated without much visibility.
With that in mind, on your suggestion, and the sample code from Victor Reinhart who also ran into this, we have coded the following which we plan to put in the datawindow sql preview event. We've just started testing - I would appreciate any comment.
====================================================
// Datawindow SQL Preview Event
// Fix (Escape) SQL Anywhere Escape: it changes \\ to \ for any text when DisableBind=1
integer li_rc
string ls_sqlsyntax, ls_sql
// If database is SQL Anywhere and we are doing an Insert or Update
// Then Escape the Escape Character
IF gs_db='SA' AND Request=PreviewFunctionUpdate! AND &
(SQLType=PreviewDelete! OR SQLType=PreviewUpdate! OR SQLType=PreviewInsert!) THEN
IF Pos(sqlsyntax,'\')>0 THEN
ls_sql=f_globalreplace(sqlsyntax,'\','\\')
li_rc=SetSQLPreview(ls_sql)
END IF
END IF
RETURN AncestorReturnValue
======================================================
I've created a simple function for global replace f_globalreplace which should work to handle replacement in PB much like the SA version you mentioned - this is a simplified version of the pfc string object function.
// Global Function f_globalreplace
//////////////////////////////////////////////////////////////////////////////
//
// Function: of_GlobalReplace
//
// Access: public
//
// Arguments:
// as_Source The string being searched.
// as_Old The old string being replaced.
// as_New The new string.
//
// Returns: string
// as_Source with all occurrences of as_Old replaced with as_New.
// If any argument's value is NULL, function returns NULL.
//
// Description: Replace all occurrences of one string inside another with
// a new string.
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 5.0 Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
/*
* Open Source PowerBuilder Foundation Class Libraries
*
* Copyright (c) 2004-2005, All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted in accordance with the GNU Lesser General
* Public License Version 2.1, February 1999
*
* http://www.gnu.org/copyleft/lesser.html
*
*/
//
//////////////////////////////////////////////////////////////////////////////
Long ll_Start
Long ll_OldLen
Long ll_NewLen
String ls_Source
//Check parameters
If IsNull(as_source) or IsNull(as_old) or IsNull(as_new) Then
string ls_null
SetNull(ls_null)
Return ls_null
End If
//Get the string lengths
ll_OldLen = Len(as_Old)
ll_NewLen = Len(as_New)
ls_source = as_source
//Search for the first occurrence of as_Old
ll_Start = Pos(ls_Source, as_Old)
Do While ll_Start > 0
// replace as_Old with as_New
as_Source = Replace(as_Source, ll_Start, ll_OldLen, as_New)
ls_source = as_source
// find the next occurrence of as_Old
ll_Start = Pos(ls_Source, as_Old, (ll_Start + ll_NewLen))
Loop
Return as_Source