Databases & SQL

Parameterized SQL and transactions

Run the right scope, separate values from SQL and understand commit, rollback and grid edits.

In this guideBefore you start · PremiumChoose what to executeFill in query parametersWhen the grid writes to the databaseTry a change and return to the original value

Before you start · Premium#

This guide covers tools included in Code Weaver Premium. Sign in to your account in the IDE and check that Premium is active. Without Premium you can still browse, search, edit and save your files.

Database: schema, SQL worksheet and results in one workspace.Code Weaver · Windows

Choose what to execute#

Ctrl+Enter runs a selection or the statement at the cursor; Ctrl+Shift+Enter runs the worksheet. Statements run in order and stop at the first error. SQL Block sends a complete procedural body without splitting on semicolons.

Fill in query parameters#

Use parameter fields to provide values without concatenating them into the SQL text. SQL strings and comments are not interpreted as parameter fields. Dialog values and credentials are not saved in history, while literals written into SQL remain in the query text.

  1. Write named parameters such as :id in the SQL worksheet.
  2. Run and complete the dialog with text, number, boolean or NULL.
  3. Check the connection and result before further operations.
SQL · Example
SELECT id, name
FROM products
WHERE id = :id;

When the grid writes to the database#

The editable grid requires a base table with a primary key. Changes are prepared, shown as SQL and confirmed; original values and keys are checked again before writing. If a row changed on the server, the operation is rejected instead of blindly overwriting it.

An explicit transaction retains control over COMMIT; grid changes use a savepoint where applicable. Oracle preserves the worksheet transaction; MySQL/MariaDB requires InnoDB tables. Views, non-comparable LOBs or truncated cells may require manual SQL.

Try a change and return to the original value#

Prerequisites: Premium, a test SQLite copy with an editable table and synthetic row, and no other tools writing concurrently. This exercise uses DML rather than schema changes; keep a copy of the file before starting.

  1. Run a parameterized SELECT for the chosen row and record its original value.
  2. In the same connection, execute BEGIN TRANSACTION; as a separate statement, then run an UPDATE limited to that row.
  3. Repeat the SELECT in the same connection and check the temporary value. Choose ROLLBACK in the SQL toolbar to discard uncommitted changes.
  4. Run the SELECT again and compare with the original value. If instead you want to confirm a reviewed change, COMMIT makes it final for that transaction.
Open original image ↗