Escape double quotes in provisioning rule

Hi Everyone

I worked on a Provisioning rule for a JDBC connector to handle the grant of the roles.

The query that must be executed in our database system looks like (mandatory double quotes to enclose the role name):
grant role “Role_Name” to user User_Name

In the provisioning rule, the script is enclosed between double quotes ( " ) so I need to escape them in my different instructions.

I used a string variable to build my SQL query and I tried different ways:
image

In both cases I met an issue (yntax error line 1 at position 248 unexpected ‘+’) and my query isn’t executed.

How can I easily build my query in the rule to respect what is expected by the database system ?

Thanks in advance.

Regards

Hello @bastien_prulhiere,

I use an online java tool to properly escape my java code when writing rules. Free Online Java or .Net Escape / Unescape Tool - FreeFormatter.com

For example, if I wrote this in my editor

String sqlQuery = "grant role \"" + roleName + "\" to user " + userName;

Using the FreeFormatter site I would get back my escaped string.

String sqlQuery = \"grant role \\\"\" + roleName + \"\\\" to user \" + userName;

Hi @tyler_mairose,

Many thanks for the tool suggestion, it helps me to solve my issue.

1 Like