<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Replace single quote with two single quotes in a string in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236761#M85158</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18929/yaswanthmuppireddy.html" nodeid="18929"&gt;@Shu&lt;/A&gt; &lt;/P&gt;&lt;P&gt;This is the current Nifi flow&lt;/P&gt;&lt;P&gt;ConsumeKafka -&amp;gt; UpdateAttribute -&amp;gt; ReplaceText -&amp;gt; PutSQL &lt;/P&gt;&lt;P&gt;*In UpdateAttribute I am capturing kafka.topic, kafka.offset,kafka.partition, kafka.key and assigning to variables.&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;topic=${kakfa.topic}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;partition=${kakfa.partition}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;offset=${kakfa.offset}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;key=${kakfa.key}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;&lt;P&gt;*In ReplaceText processor I am replacing the flowfile content with insert statement.&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;searchvalue = (?s)(^.*$)&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;replacementvalue =  Insert into test_schema.table1(topic, partition, offset, key, value) &lt;/P&gt;&lt;P style="margin-left: 160px;"&gt;values ('${topic}','${partition}','${offset}','${key}','$1')&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;But the nifi workflow is failing since the kafka value has single quotes in it as mentioned in initial post and sql server wont allow single quotes into the varchar column unless we double the single quote. I want to add one more ReplaceText processor and search the kafka value string and replace all the single quote occurrences with two single quotes. Please let me know what should be the search value and replacement value in the Replacetext processor. Please let me know if there is a better way to handle this scenario.&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 26 Nov 2018 02:08:42 GMT</pubDate>
    <dc:creator>sudhakar_reddy</dc:creator>
    <dc:date>2018-11-26T02:08:42Z</dc:date>
    <item>
      <title>Replace single quote with two single quotes in a string</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236760#M85157</link>
      <description>&lt;P&gt;I am trying to consume data from kafka and insert into sql server. The kafka value has single quotes in it eg: "O'Keefe". PutSQL processor is failing to insert the string value into SQL server varchar column. I would like to replace the single quote with two single quotes in nifi so that I can insert the kafka value with single quote into sql server. Can you please give an example of replacetext processor how to achieve this.&lt;/P&gt;&lt;P&gt;Input: O'Keefe&lt;/P&gt;&lt;P&gt;Output: O''Keefe&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:55:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236760#M85157</guid>
      <dc:creator>sudhakar_reddy</dc:creator>
      <dc:date>2022-09-16T13:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace single quote with two single quotes in a string</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236761#M85158</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18929/yaswanthmuppireddy.html" nodeid="18929"&gt;@Shu&lt;/A&gt; &lt;/P&gt;&lt;P&gt;This is the current Nifi flow&lt;/P&gt;&lt;P&gt;ConsumeKafka -&amp;gt; UpdateAttribute -&amp;gt; ReplaceText -&amp;gt; PutSQL &lt;/P&gt;&lt;P&gt;*In UpdateAttribute I am capturing kafka.topic, kafka.offset,kafka.partition, kafka.key and assigning to variables.&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;topic=${kakfa.topic}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;partition=${kakfa.partition}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;offset=${kakfa.offset}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;key=${kakfa.key}&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;&lt;P&gt;*In ReplaceText processor I am replacing the flowfile content with insert statement.&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;searchvalue = (?s)(^.*$)&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;replacementvalue =  Insert into test_schema.table1(topic, partition, offset, key, value) &lt;/P&gt;&lt;P style="margin-left: 160px;"&gt;values ('${topic}','${partition}','${offset}','${key}','$1')&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;But the nifi workflow is failing since the kafka value has single quotes in it as mentioned in initial post and sql server wont allow single quotes into the varchar column unless we double the single quote. I want to add one more ReplaceText processor and search the kafka value string and replace all the single quote occurrences with two single quotes. Please let me know what should be the search value and replacement value in the Replacetext processor. Please let me know if there is a better way to handle this scenario.&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 02:08:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236761#M85158</guid>
      <dc:creator>sudhakar_reddy</dc:creator>
      <dc:date>2018-11-26T02:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replace single quote with two single quotes in a string</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236762#M85159</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/99475/sudhakarreddy.html" nodeid="99475" target="_blank"&gt;@Sudhakar Reddy&lt;/A&gt;
&lt;/P&gt;&lt;P&gt;Thanks for updating all details regards to the flow :).&lt;/P&gt;&lt;P&gt;Configure &lt;STRONG&gt;ReplaceText&lt;/STRONG&gt; processor as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="93377-screen-shot-2018-11-25-at-20937-pm.png" style="width: 2376px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/14344i96B1E11B8F30AFD9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="93377-screen-shot-2018-11-25-at-20937-pm.png" alt="93377-screen-shot-2018-11-25-at-20937-pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Search Value&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;(?s)(^.*$)&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Replacement Value&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;Insert into test_schema.table1(topic, partition, offset, key, value) values ('${topic}','${partition}','${offset}','${key}','${'$1':replace("'","\"")}')&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Character Set&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;UTF-8&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Maximum Buffer Size&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;10 MB //change this value as per your flowfile size   &lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Replacement Strategy&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;Regex Replace&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Evaluation Mode&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;Entire text&lt;/PRE&gt;
&lt;/DIV&gt;&lt;P&gt;In replacement value we are replacing all &lt;STRONG&gt;single quotes(') with double quotes(") in the captured group $1&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 23:27:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236762#M85159</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2019-08-17T23:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replace single quote with two single quotes in a string</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236763#M85160</link>
      <description>&lt;P&gt;Thank you Shu, it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 05:57:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236763#M85160</guid>
      <dc:creator>sudhakar_reddy</dc:creator>
      <dc:date>2018-11-26T05:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Replace single quote with two single quotes in a string</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236764#M85161</link>
      <description>&lt;P&gt;NO!  if you are trying to escape input to generate a sql query you should never roll your own sanitization unless you fully trust the input. &lt;/P&gt;&lt;P&gt;THIS IS VULNERABLE TO SQL INJECTION!&lt;/P&gt;&lt;P&gt;You should be using the '?' parameter substitution in your putsql stage.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 01:29:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Replace-single-quote-with-two-single-quotes-in-a-string/m-p/236764#M85161</guid>
      <dc:creator>david_miller</dc:creator>
      <dc:date>2018-11-27T01:29:38Z</dc:date>
    </item>
  </channel>
</rss>

