I have a very long string (json string) which need to be inserted into a table. The json string contains letters, numbers, special signs and unicode. How do I insert this into a table?
I am using a “Run query” which has established a connection to my database. This is the query I am executing… “INSERT INTO my_table” + " VALUES (json_document) (‘" + response1.ToString + "’);"
This, however, gives me the error
“Run query: Incorrect syntax near ‘{“transactionDetail”:{“transactionID”:“rrt-xxx-a-eu-x-xxxx”,“transactionTimestamp”:"2023-07-14.’.”
It seems like UiPath thinks my json string is a part of the SQL INSERT syntax. Any idea how to fix this?
Create a datatable with a column json_document and use response1.ToString in an Add Data Row activity. Then use the Insert activity and pass it that datatable.
YOu would have to remove the special characters, use the below expression for it:
System.Text.RegularExpressions.Regex.Replace(yourString,“[a-z A-Z 0-9./:-]”,“”)
These are [a-z A-Z 0-9./:-+] permissible/allowed characters.
I am not sure what you mean with “show the full statement”? This is my full INSERT SQL statement “INSERT INTO my_table” + " VALUES (json_document) (‘ " + response1.ToString + " ’);"
I have purposefully made a space between the ’ and the ", hope it helps
Due to work policy, I am not allowed to show you the full response.ToString, since it is a json file with confidential information. However, think of response1 as a json string, a very, very large json string
This is my current statement which works on the first 10 INSERTS before i fails
“INSERT INTO my_table VALUES ('” + response1 + “')”
Just to check try getting a small json string and escape the characters with \ and use it
like below and see (try static query without variables) "INSERT INTO dnb_api_rawdata VALUES ('{\""transactionDetail\"":{\""transactionID\"":\""rrt-xxx-a-eu-x-xxxx\""}}')"
and as per statement I can see you are inserting only one value so only one column is present?
Yes, but the people who bought the project are paying us to deliver what they specifically ask for, it’s not my job to decide the design of the project…
I can not do that. My json string is around 18.000 characters long, I can not manually input my json string in my INSERT statement, or are you perhaps refering to something else?