SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Member Functions
RWDBDeleter Class Reference

Encapsulates an SQL DELETE statement. More...

#include <rw/db/deleter.h>

Public Member Functions

 RWDBDeleter ()
 
 RWDBDeleter (const RWDBDeleter &deleter)
 
void acquire (void) const
 
RWCString asString () const
 
RWCString asString (const RWDBConnection &conn) const
 
RWCString asString (bool verbose) const
 
RWCString asString (const RWDBConnection &conn, bool verbose) const
 
RWDBStatus clear ()
 
RWDBStatus::ErrorHandler errorHandler () const
 
RWDBResult execute ()
 
RWDBResult execute (const RWDBConnection &connection)
 
bool isReady () const
 
bool isValid () const
 
RWDBDeleteroperator= (const RWDBDeleter &deleter)
 
void release (void) const
 
void setErrorHandler (RWDBStatus::ErrorHandler handler)
 
RWDBStatus status () const
 
RWDBTable table () const
 
RWDBDeleterwhere (const RWDBCriterion &criterion)
 
RWDBCriterion where () const
 

Detailed Description

RWDBDeleter is an encapsulation of an SQL DELETE statement. The where() method of RWDBDeleter is used to specify a WHERE clause. The WHERE clause is encapsulated by an RWDBCriterion, which is some number of RWDBExpr instances combined with logical operators.

A DELETE statement does not normally produce results. However, the DB Interface Module recognizes that some database vendors provide triggers, which can cause results to be generated by a DELETE statement. Consequently, the execute() method of RWDBDeleter returns an RWDBResult, which is a sequence of zero or more RWDBTable objects. Applications are not obliged to request any tables from the returned object.

RWDBDeleter is designed around the Interface/Implementation paradigm. An RWDBDeleter instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation. An RWDBDeleter implementation is a base class from which a family of database-specific deleter implementations is derived.

Synopsis
#include <rw/db/deleter.h>
RWDBDeleter deleter = myTable.deleter();
See also

The encapsulated WHERE clause of an RWDBDeleter is an RWDBCriterion, which is composed of RWDBExpr instances. See RWDBCriterion, RWDBExpr, and RWDBColumn for details.

The result of execute() is an RWDBResult, which represents a sequence of zero or more RWDBTable instances. See RWDBResult and RWDBTable for details.

Example

Example 1

For this example, we delete all the red hubcaps from the autoParts table:

RWDBTable autoParts = myDbase.table("autoParts");
RWDBDeleter deleter = autoParts.deleter();
deleter.where(autoParts["name"] == "hubcap" &&
autoParts["color"] == "red");
deleter.execute();

Example 2

For this example, we delete all parts with a specific id by repeatedly using binding to a variable containing the id:

RWDBTable allParts = myDbase.table( "AllParts" );
RWDBConnection connection = myDbase.connection();
RWDBDeleter deleter = allParts.deleter();
int id = 1001;
deleter.where( allParts["id"] == RWDBBoundExpr( &id ) );
deleter.execute(connection); // delete part number
// 1001
id = 2001;
deleter.execute(connection); // delete part number 2001

Constructor & Destructor Documentation

RWDBDeleter::RWDBDeleter ( )

The default constructor creates an RWDBDeleter whose status is RWDBStatus::notInitialized. This constructor is provided as a convenience, for example, to declare an array of RWDBDeleter objects. A usable RWDBDeleter is obtained from an RWDBTable.

RWDBDeleter::RWDBDeleter ( const RWDBDeleter deleter)

Copy constructor. Self shares an implementation with deleter.

Member Function Documentation

void RWDBDeleter::acquire ( void  ) const

Attempts to acquire the internal mutex lock. If the mutex is already locked by another thread, the function blocks until the mutex is released. This function can be called from a const object.

Note
In single-threaded builds, this function evaluates to a no-op.
RWCString RWDBDeleter::asString ( ) const
inline

Returns the SQL equivalent of:

DELETE FROM table [ WHERE ...]

This method returns an SQL statement that would be produced by executing self with an implicit RWDBConnection object. An implicit RWDBConnection object inherits the time zone setting from the producer RWDBDatabase instance. Hence, the time zone setting of the producer RWDBDatabase object will be used for creating the string representations of any RWDateTime instances in self.

The behavior of this method depends upon the RWDBDatabase::verboseAsString() setting in the producer RWDBDatabase instance.

  • If verboseAsString() is false, the SQL returned is the same as that passed to the database for execution. This is the default.
  • If verboseAsString() is true, any placeholders in the returned SQL are replaced with their bound values.
Note
When the RWDBDatabase::verboseAsString() option is set to true, the SQL returned by this method may not be a valid SQL statement. However, this method's return value is not necessarily the same SQL that is sent to the database for execution. For example, if an RWDBBlob object is bound, calling this method with RWDBDatabase::verboseAsString() set to true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBDatabase::timeZone(const RWZone*) for time zone setting on RWDBDatabase.
RWCString RWDBDeleter::asString ( const RWDBConnection conn) const
inline

Returns the SQL equivalent of:

DELETE FROM table [ WHERE ...]

This method returns an SQL statement that would be produced by executing self with conn. The time zone setting of conn will be used for creating string representations of any RWDateTime instances in self.

The behavior of this asString() method depends upon the RWDBDatabase::verboseAsString() setting in the producer RWDBDatabase instance.

  • If verboseAsString() is false,the SQL returned is the same as that passed to the database for execution. This is the default.
  • If verboseAsString() is true, any placeholders in the returned SQL are replaced with their bound values.
Note
When the RWDBDatabase::verboseAsString() option is set to true, the SQL returned by this method may not be a valid SQL statement. However, this method's return value is not necessarily the same SQL that is sent to the database for execution. For example, if an RWDBBlob object is bound, calling this method with RWDBDatabase::verboseAsString() set to true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBConnection::timeZone(const RWZone*) for time zone setting on RWDBConnection.
RWCString RWDBDeleter::asString ( bool  verbose) const
inline

Returns the SQL equivalent of:

DELETE FROM table [ WHERE ...]

This method returns an SQL statement that would be produced by executing self with an implicit RWDBConnection object. An implicit RWDBConnection object inherits the time zone setting from the producer RWDBDatabase instance. Hence, the time zone setting of the producer RWDBDatabase object will be used for creating the string representations of any RWDateTime instances in self.

The behavior of this method depends on the value of verbose, and is independent of the RWDBDatabase::verboseAsString() setting.

  • If verbose is false, the SQL returned is the same as that passed to the database for execution.
  • If verbose is true, any placeholders in the returned SQL are replaced with their bound values although the SQL passed to the database for execution will not be affected.
Note
The SQL returned by this method when verbose is true may not be a valid SQL statement. However, this is not necessarily the same SQL that is sent to the database for execution. For example, if an RWDBBlob object is bound, calling this method with verbose as true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBDatabase::timeZone(const RWZone*) for time zone setting on RWDBDatabase.
RWCString RWDBDeleter::asString ( const RWDBConnection conn,
bool  verbose 
) const
inline

Returns the SQL equivalent of:

DELETE FROM table [ WHERE ...]

This method returns an SQL statement that would be produced by executing self with conn. The time zone setting of conn will be used for creating string representations of any RWDateTime instances in self.

The behavior of this method depends on the value of verbose, and is independent of the RWDBDatabase::verboseAsString() setting.

  • If verbose is false, the SQL returned is the same as that passed to the database for execution.
  • If verbose is true, any placeholders in the returned SQL are replaced with their bound values although the SQL passed to the database for execution will not be affected.
Note
The SQL returned by this method when verbose is true may not be a valid SQL statement. However, this is not necessarily the same SQL that is sent to the database for execution. For example, if an RWDBBlob object is bound, calling this method with verbose as true will result in a string with blob data returned as hex numbers, such as 0x0A32F5.
See also
RWDBConnection::timeZone(const RWZone*) for time zone setting on RWDBConnection.
RWDBStatus RWDBDeleter::clear ( )

Clears self's WHERE clause and internal controls.

RWDBStatus::ErrorHandler RWDBDeleter::errorHandler ( ) const

Returns the error handler attached to self.

RWDBResult RWDBDeleter::execute ( )

Uses a default database connection to cause the SQL statement encapsulated by self to be executed.

RWDBResult RWDBDeleter::execute ( const RWDBConnection connection)

Uses the supplied connection to cause the SQL statement encapsulated by self to be executed. This function can behave asynchronously if executed using an asynchronous connection.

bool RWDBDeleter::isReady ( ) const

Returns true if the object is in ready state, indicating that accessing the object will not block. Accessing a nonready object may potentially block.

bool RWDBDeleter::isValid ( ) const

Returns true if self's status is RWDBStatus::ok, otherwise returns false. Does not return false if the previously executed statement failed. You must check the status of the RWDBResult returned from execute() instead of the status of the RWDBDeleter object.

RWDBDeleter& RWDBDeleter::operator= ( const RWDBDeleter deleter)

Assignment operator. Self shares an implementation with deleter.

void RWDBDeleter::release ( void  ) const

Releases a previously acquired mutex. This function can be called from a const object.

Note
In single-threaded builds, this function evaluates to a no-op.
void RWDBDeleter::setErrorHandler ( RWDBStatus::ErrorHandler  handler)

Installs handler as self's error handler. The supplied handler is inherited by all objects produced by self. By default, the RWDBStatus::ErrorHandler is inherited from the object that produced self; this method overrides the default.

RWDBStatus RWDBDeleter::status ( ) const

Returns the current status of self.

RWDBTable RWDBDeleter::table ( ) const

Returns the RWDBTable that produced self. Returns an RWDBTable whose status is RWDBStatus::notInitialized if self was produced with the default constructor.

RWDBDeleter& RWDBDeleter::where ( const RWDBCriterion criterion)

Specifies criterion as self's SQL WHERE clause. If self already has a WHERE clause, this method replaces it. Specifying an empty criterion clears self's WHERE clause. Notice that a deleter without a WHERE clause deletes all rows from its table. Returns a reference to self.

RWDBCriterion RWDBDeleter::where ( ) const

Returns a copy of self's RWDBCriterion, an encapsulated SQL WHERE clause. Returns an empty RWDBCriterion if self has no WHERE clause.

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.