-
Notifications
You must be signed in to change notification settings - Fork 5
TSQLite3Result
Ivan Semenkov edited this page Oct 24, 2021
·
2 revisions
TSQLite3Result class encapsulates the SQLite3 result collection.
uses
sqlite3.result;
type
TSQLite3Result = class
A new database result can be created by call its constructor.
constructor Create (AErrorsStack : PSQL3LiteErrorsStack; AStatementHandle :
psqlite3_stmt; AResCode : Integer);
uses
libpassqlite, sqlite3.errors_stack, utils.api.cstring, sqlite3.connection;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
statementHandle : psqlite3_stmt;
query : API.PAnsiStringWrapper;
connection : TSQLite3DatabaseConnection;
res : TSQLite3Result;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
query := API.CString.Create('SELECT * FROM sqlite_master;').ToUniquePAnsiChar;
res := TSQLite3Result.Create(@errors, statementHandle,
sqlite3_prepare_v3(handle, query.Value, query.Length,
SQLITE_PREPARE_NORMALIZE, @statementHandle, nil));
FreeAndNil(res);
FreeAndNil(query);
FreeAndNil(connection);
FreeAndNil(errors);
end;
It is possible to iterate for TSQLite3Result rows using in
operator. Each value would present as TSQLite3Result.TRowIterator object.
uses
sqlite3.result;
type
TSQLite3Result = class
type
TRowIterator = class
end;
uses
libpassqlite, sqlite3.errors_stack, utils.api.cstring, sqlite3.connection;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
statementHandle : psqlite3_stmt;
query : API.PAnsiStringWrapper;
connection : TSQLite3DatabaseConnection;
res : TSQLite3Result;
row : TSQLite3Result.TRowIterator;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
query := API.CString.Create('SELECT * FROM sqlite_master;').ToUniquePAnsiChar;
res := TSQLite3Result.Create(@errors, statementHandle,
sqlite3_prepare_v3(handle, query.Value, query.Length,
SQLITE_PREPARE_NORMALIZE, @statementHandle, nil));
for row in res do
;
FreeAndNil(res);
FreeAndNil(query);
FreeAndNil(connection);
FreeAndNil(errors);
end;
Retrive the iterator for first row in a TSQLite3Result.
function FirstRow : TRowIterator;
uses
libpassqlite, sqlite3.errors_stack, utils.api.cstring, sqlite3.connection;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
statementHandle : psqlite3_stmt;
query : API.PAnsiStringWrapper;
connection : TSQLite3DatabaseConnection;
res : TSQLite3Result;
row : TSQLite3Result.TRowIterator;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
query := API.CString.Create('SELECT * FROM sqlite_master;').ToUniquePAnsiChar;
res := TSQLite3Result.Create(@errors, statementHandle,
sqlite3_prepare_v3(handle, query.Value, query.Length,
SQLITE_PREPARE_NORMALIZE, @statementHandle, nil));
row := res.FirstRow;
FreeAndNil(res);
FreeAndNil(query);
FreeAndNil(connection);
FreeAndNil(errors);
end;
Return true if iterator has correct row.
function HasRow : Boolean;
uses
libpassqlite, sqlite3.errors_stack, utils.api.cstring, sqlite3.connection;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
statementHandle : psqlite3_stmt;
query : API.PAnsiStringWrapper;
connection : TSQLite3DatabaseConnection;
res : TSQLite3Result;
row : TSQLite3Result.TRowIterator;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
query := API.CString.Create('SELECT * FROM sqlite_master;').ToUniquePAnsiChar;
res := TSQLite3Result.Create(@errors, statementHandle,
sqlite3_prepare_v3(handle, query.Value, query.Length,
SQLITE_PREPARE_NORMALIZE, @statementHandle, nil));
for row in res do
begin
if row.HasRow then
;
end;
FreeAndNil(res);
FreeAndNil(query);
FreeAndNil(connection);
FreeAndNil(errors);
end;
Retrieve the next entry in a TSQLite3Result.
function NextRow : TRowIterator;
uses
libpassqlite, sqlite3.errors_stack, utils.api.cstring, sqlite3.connection;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
statementHandle : psqlite3_stmt;
query : API.PAnsiStringWrapper;
connection : TSQLite3DatabaseConnection;
res : TSQLite3Result;
row : TSQLite3Result.TRowIterator;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
query := API.CString.Create('SELECT * FROM sqlite_master;').ToUniquePAnsiChar;
res := TSQLite3Result.Create(@errors, statementHandle,
sqlite3_prepare_v3(handle, query.Value, query.Length,
SQLITE_PREPARE_NORMALIZE, @statementHandle, nil));
row := res.FirstRow;
while row.HasRow do
begin
row := row.NextRow;
end;
FreeAndNil(res);
FreeAndNil(query);
FreeAndNil(connection);
FreeAndNil(errors);
end;
Result row.
property Row : TSQLite3ResultRow;
Return TSQLite3ResultRow object.
uses
libpassqlite, sqlite3.errors_stack, utils.api.cstring, sqlite3.connection;
var
errors : TSQLite3ErrorsStack;
handle : psqlite3;
statementHandle : psqlite3_stmt;
query : API.PAnsiStringWrapper;
connection : TSQLite3DatabaseConnection;
res : TSQLite3Result;
row : TSQLite3Result.TRowIterator;
begin
errors := TSQLite3ErrorsStack.Create;
connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database',
[SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
query := API.CString.Create('SELECT * FROM sqlite_master;').ToUniquePAnsiChar;
res := TSQLite3Result.Create(@errors, statementHandle,
sqlite3_prepare_v3(handle, query.Value, query.Length,
SQLITE_PREPARE_NORMALIZE, @statementHandle, nil));
row := res.FirstRow;
while row.HasRow do
begin
row.Row;
row := row.NextRow;
end;
FreeAndNil(res);
FreeAndNil(query);
FreeAndNil(connection);
FreeAndNil(errors);
end;