-
Notifications
You must be signed in to change notification settings - Fork 5
TSQLite3Delete
TSQLite3Delete class encapsulates the SQLite3 database delete query.
uses
sqlite3.delete;
type
TSQLite3Delete = class
A new delete query can be created by call its constructor.
constructor Create (AErrorsStack : PSQL3LiteErrorsStack; ADBHandle :
ppsqlite3; ATableName : String);
uses
libpassqlite, sqlite3.errors_stack, sqlite3.connection, sqlite3.delete;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
connection : TSQLite3DatabaseConnection;
delete : TSQLite3Delete;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := TSQLite3Delete.Create(@errors, @handle, 'table_name');
FreeAndNil(delete);
FreeAndNil(connection);
FreeAndNil(errors);
end;
Or use TSQLite3Builder object.
function Delete : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete;
FreeAndNil(builder);
end;
There are several comparison operators which can used in where clause.
TWhereComparisonOperator = (
Equal comparison operator.
COMPARISON_EQUAL, { = }
Not equal comparison operator.
COMPARISON_NOT_EQUAL, { <> }
Less comparison operator.
COMPARISON_LESS, { < }
Greater comparison operator.
COMPARISON_GREATER, { > }
Less or equal comparison operator.
COMPARISON_LESS_OR_EQUAL, { <= }
Greater or equal comparison operator.
COMPARISON_GREATER_OR_EQUAL, { >= }
Not comparison operator.
COMPARISON_NOT { IS NOT }
);
If a WHERE clause is specified, the WHERE expression is evaluated for each row in the input data as a boolean expression. Only rows for which the WHERE clause expression evaluates to true are included from the dataset before continuing. Rows are excluded from the result if the WHERE clause evaluates to either false or NULL. Details on SQLite C/C++ API page.
function Where (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : String) : TSQLite3Delete;
function Where (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : Integer) : TSQLite3Delete;
function Where (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : Double) : TSQLite3Delete;
For equal comparison operator there are present short form.
function Where (AColumnName : String; AValue : String) : TSQLite3Delete;
function Where (AColumnName : String; AValue : Integer) : TSQLite3Delete;
function Where (AColumnName : String; AValue : Double) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', COMPARISON_GREATER, 2);
FreeAndNil(builder);
end;
It is a short form of where clause with value equal NULL
.
function WhereNull (AColumnName : String) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.WhereNull('value');
FreeAndNil(builder);
end;
It is a short form of where clause with value not equal NULL
.
function WhereNotNull (AColumnName : String) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.WhereNotNull('value');
FreeAndNil(builder);
end;
Adds AND WHERE
clause to query.
function AndWhere (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : String) : TSQLite3Delete;
function AndWhere (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : Integer) : TSQLite3Delete;
function AndWhere (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : Double) : TSQLite3Delete;
For equal comparison operator there are present short form.
function AndWhere (AColumnName : String; AValue : String) : TSQLite3Delete;
function AndWhere (AColumnName : String; AValue : Integer) : TSQLite3Delete;
function AndWhere (AColumnName : String; AValue : Double) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', 2)
.AndWhere('id', COMPARISON_GREATER, 5);
FreeAndNil(builder);
end;
It is a short form of where clause with value equal NULL
.
function AndWhereNull (AColumnName : String) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', 2)
.AndWhereNull('value');
FreeAndNil(builder);
end;
It is a short form of where clause with value not equal NULL
.
function AndWhereNotNull (AColumnName : String) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', 2)
.AndWhereNotNull('value');
FreeAndNil(builder);
end;
Adds OR WHERE
clause to query.
function OrWhere (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : String) : TSQLite3Delete;
function OrWhere (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : Integer) : TSQLite3Delete;
function OrWhere (AColumnName : String; AComparison :
TWhereComparisonOperator; AValue : Double) : TSQLite3Delete;
For equal comparison operator there are present short form.
function OrWhere (AColumnName : String; AValue : String) : TSQLite3Delete;
function OrWhere (AColumnName : String; AValue : Integer) : TSQLite3Delete;
function OrWhere (AColumnName : String; AValue : Double) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', 2)
.OrWhere('id', COMPARISON_GREATER, 54);
FreeAndNil(builder);
end;
It is a short form of where clause with value equal NULL
.
function OrWhereNull (AColumnName : String) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', 2)
.OrWhereNull('value');
FreeAndNil(builder);
end;
It is a short form of where clause with value not equal NULL
.
function OrWhereNotNull (AColumnName : String) : TSQLite3Delete;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
delete : TSQLite3Delete;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
delete := builder.Table('table_name').Delete
.Where('id', 2)
.OrWhereNotNull('value');
FreeAndNil(builder);
end;
Run query and return number of deleted columns.
function Get : Integer;
uses
sqlite3.builder, sqlite3.table, sqlite3.delete;
var
builder : TSQLite3Builder;
begin
builder := TSQLite3Builder.Create('database', [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
builder.Table('table_name').Delete
.Where('id', 2)
.OrWhereNotNull('value')
.Get;
FreeAndNil(builder);
end;