Skip Headers

# Using a Unit of Work With Custom SQL

Previous

Next

You can execute native SQL or invoke a stored procedure within a unit of work by using unit of work method `executeNonSelectingCall` or by executing a `DataModifyQuery`. This makes the unit of work begin its database transaction early and execute the call to the data immediately.

If you release the unit of work, it will roll back the database changes. If you commit the unit of work and the commit succeeds, the unit of work will commit the changes to the database.

You can execute a `DataModifyQuery` only in a unit of work or a database session. You cannot execute a `DataModifyQuery` in a client or server session directly.

You can execute a `DataReadQuery` or use session method `executeSelectingCall` in any session type because these do not modify data.

Example: Using the executeNonSelectingCall Method illustrates using `SQLCall` with the unit of work method `executeNonSelectingCall`.

Using the executeNonSelectingCall Method

    uow.executeNonSelectingCall(new SQLCall(mySqlString));

WARNING: Allowing an unverified SQL string to be passed into methods makes your application vulnerable to SQL injection attacks.