Workaround for parameterized SQL queries in the cloud
Following the Confluence Data Center-to-Cloud migration, parameterized SQL queries may fail with the following error: “Incorrect syntax near the question mark (?)”. Parameterized queries that worked in Data Center are currently not supported in Cloud. Follow the workaround to replace the parameter placeholders in queries with actual values.
Prerequisites and setup
Download the attached script and open it in a browser. The script will display the graphical user interface.
Enter the email address associated with your Confluence Cloud account and an API token generated for the same instance. Follow these steps to generate an API token:
Navigate to https://id.atlassian.com/manage-profile/security/api-tokens.
Create a new token:
Copy the generated token and use it in the authentication window opened in step 1.
After successful authentication, the following window will appear:
Change the Confluence base URL to the URL of your test instance.
Give access to the CORS Demo API by clicking corsdemo from the Error section and allowing temporary access.
Grant temporary access to the CORS Demo API by selecting Request temporary access to the demo server.
Return to the main script page and refresh it.
On refresh, it will fetch the spaces from the specified Confluence instance and show a success message, as below:
Once setup is complete, there are two ways to replace the question marks in SQL queries stored in attachments:
Step-by-step mode: Update one SQL query at a time by selecting one space, page, and attachment.
Direct input mode: Update multiple SQL queries from multiple attachments in one operation.
For bulk operations, process the queries in batches of five or ten to reduce the risk of errors.
Step-by-step mode
Select the Space, Page, and Attachment containing the SQL query.
It will show the SQL query from the attachment as below:
Now, to replace the ‘?’, fill the parameter values in the “Replacement values” box on the right side. As mentioned, you can either use comma-separated values or enter each value on a new line, as shown in the window:
Click on Save & Update Existing Attachment; it will update the SQL query with actual values in the Confluence space:
Once the success message is shown, you can verify the result in the macro configuration in the space.
Direct input mode
Use the to update the parameter values for multiple queries.
{ "space": "", "page": "", "attachment": "", "replacements": "" }You can use this code block multiple times, for each attachment from a different page.
Replace the following placeholders in the code block:
space→ actual space keypage→ actual page name in the spaceattachment→ actual attachment namereplacements→ parameter value, or comma-separated values if applicable
Once the
config.jsonfile is updated, upload it to the page. Refer to the recording below: