Escaping double quotes in Vulcan.NET
2015
Trying to optimize building SQL insert and update strings, the following VO code:
cTable + ‘”‘ + cFieldName + ‘”‘
in Vulcan.NET works as follows
cTable + “.” + chr( 34 ) + cFieldName + chr( 34 )
But of course is not very performant. Better is the following code:
string.Format( e”{0}.\”{1}\””, cTable, aValues[nI,1] )
Please note the “e” character before the string – it enables escaping the double quotes with the backslash.
The entire method for building an append statement ist the following:
static method CreateInsertString( cTable as string, oFieldValues as List<BaseField> ) as string
local oField as BaseField
local oStatement as StringBuilder
local oValues as StringBuilder
local cStatement as string
local cValues as string
local nLen as int
local nI as int
local cField as string
local uValue as usual
local cValue as stringcStatement := string.Format( “insert into {0} ( “, cTable )
oStatement := StringBuilder{ cStatement, 512 }
oStatement:Append( ” values ( ” )
oValues := StringBuilder{ 512 }
nLen := oFieldValues:Count – 1
for nI := 0 upto nLen
oField := oFieldValues:Item[nI]
cValue := FirebirdHelper.ConvertValueToStatement( oField:Value )
if nI < nLen
oStatement:AppendFormat( “{0}, “, oField:Name )
oValues:AppendFormat( “{0}, “, cValue )
else
oStatement:AppendFormat( “{0}) “, oField:Name )
oValues:AppendFormat( “{0}) “, cValue )
endif
next
oStatement:Append( oValues )
cStatement := oStatement:ToString()return cStatement