{"id":206,"date":"2015-10-25T07:21:17","date_gmt":"2015-10-25T06:21:17","guid":{"rendered":"http:\/\/www.riedmann.it\/blog\/?p=206"},"modified":"2015-10-25T07:29:13","modified_gmt":"2015-10-25T06:29:13","slug":"escaping-double-quotes-in-vulcan-net","status":"publish","type":"post","link":"https:\/\/blog.riedmann.it\/?p=206","title":{"rendered":"Escaping double quotes in Vulcan.NET"},"content":{"rendered":"<p>Trying to optimize building SQL insert and update strings, the following VO code:<\/p>\n<blockquote><p>cTable + &#8216;&#8221;&#8216; + cFieldName + &#8216;&#8221;&#8216;<\/p><\/blockquote>\n<p>in Vulcan.NET works as follows<\/p>\n<blockquote><p>cTable + &#8220;.&#8221; + chr( 34 ) + cFieldName + chr( 34 )<\/p><\/blockquote>\n<p>But of course is not very performant. Better is the following code:<\/p>\n<blockquote><p>string.Format( e&#8221;{0}.\\&#8221;{1}\\&#8221;&#8221;, cTable, aValues[nI,1] )<\/p><\/blockquote>\n<p>Please note the &#8220;e&#8221; character before the string &#8211; it enables escaping the double quotes with the backslash.<\/p>\n<p>The entire method for building an append statement ist the following:<\/p>\n<blockquote><p>\n        static method CreateInsertString( cTable as string, oFieldValues as List&lt;BaseField&gt; ) as string<br \/>\n            &nbsp;local oField as BaseField<br \/>\n            &nbsp;local oStatement as StringBuilder<br \/>\n            &nbsp;local oValues as StringBuilder<br \/>\n            &nbsp;local cStatement as string<br \/>\n            &nbsp;local cValues as string<br \/>\n            &nbsp;local nLen as int<br \/>\n            &nbsp;local nI as int<br \/>\n            &nbsp;local cField as string<br \/>\n            &nbsp;local uValue as usual<br \/>\n            &nbsp;local cValue as string<\/p>\n<p>            &nbsp;cStatement := string.Format( &#8220;insert into {0} ( &#8220;, cTable )<br \/>\n            &nbsp;oStatement := StringBuilder{ cStatement, 512 }<br \/>\n            &nbsp;oStatement:Append( &#8221; values ( &#8221; )<br \/>\n            &nbsp;oValues             := StringBuilder{ 512 }<br \/>\n            &nbsp;nLen\t\t\t\t:= oFieldValues:Count &#8211; 1<br \/>\n\t        &nbsp;&nbsp;for nI := 0 upto nLen<br \/>\n                &nbsp;&nbsp;oField := oFieldValues:Item[nI]<br \/>\n    \t        &nbsp;&nbsp;cValue := FirebirdHelper.ConvertValueToStatement( oField:Value )<br \/>\n    \t        &nbsp;&nbsp;if nI < nLen<br \/>\n                    &nbsp;&nbsp;&nbsp;oStatement:AppendFormat( &#8220;{0}, &#8220;, oField:Name )<br \/>\n                    &nbsp;&nbsp;&nbsp;oValues:AppendFormat( &#8220;{0}, &#8220;, cValue )<br \/>\n    \t        &nbsp;&nbsp;else<br \/>\n                    &nbsp;&nbsp;&nbsp;oStatement:AppendFormat( &#8220;{0}) &#8220;, oField:Name )<br \/>\n                    &nbsp;&nbsp;&nbsp;oValues:AppendFormat( &#8220;{0}) &#8220;, cValue )<br \/>\n    \t        &nbsp;&nbsp;endif<br \/>\n            &nbsp;next<br \/>\n            &nbsp;oStatement:Append( oValues )<br \/>\n\t    &nbsp;cStatement\t\t:= oStatement:ToString()<\/p>\n<p>            &nbsp;return cStatement\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Trying to optimize building SQL insert and update strings, the following VO code: cTable + &#8216;&#8221;&#8216; + cFieldName + &#8216;&#8221;&#8216; in Vulcan.NET works as follows cTable + &#8220;.&#8221; + chr( 34 ) + cFieldName + chr( 34 ) But of course is not very performant. Better is the following code: string.Format( e&#8221;{0}.\\&#8221;{1}\\&#8221;&#8221;, cTable, aValues[nI,1] ) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-206","post","type-post","status-publish","format-standard","hentry","category-vulcan-net-programming"],"_links":{"self":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=206"}],"version-history":[{"count":4,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/206\/revisions"}],"predecessor-version":[{"id":210,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/206\/revisions\/210"}],"wp:attachment":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}