This repository was archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
TSQLite3ErrorsStack
Ivan Semenkov edited this page Jan 31, 2021
·
1 revision
TSQLite3ErrorsStack collect database errors.
uses
sqlite3.errors_stack;
type
TSQL3LiteErrorsStack = class({$IFDEF FPC}specialize{$ENDIF}
TListErrorsStack<String>)
If macro {$USE_OPTIONAL}
is defined, then all methods return a TOptionalValue wrapper, otherwise String.
uses
utils.optional;
type
TOptionalValue = {$IFDEF FPC}specialize{$ENDIF} TOptional<String>;
For non-existent values, returns a empty TOptionalValue if defined or an EErrorNotExists is thrown.
type
{$IFNDEF USE_OPTIONAL}
EErrorNotExists = class(Exception);
{$ENDIF}
A new errors stack can be created by call its constructor.
constructor Create;
uses
utils.errors_stack;
var
errors : TSQL3LiteErrorsStack;
begin
errors := TSQL3LiteErrorsStack.Create;
FreeAndNil(errors);
end;
Push error to stack.
procedure Push (AError : String);
procedure Push (AError : TSQLite3Code);
procedure Push (AErrorCode : Integer);
uses
utils.errors_stack;
var
errors : TSQL3LiteErrorsStack;
begin
errors := TSQL3LiteErrorsStack.Create;
errors.Push(SQLITE_ERROR);
FreeAndNil(errors);
end;
Return top error and remove it from stack.
function Pop : {$IFNDEF USE_OPTIONAL}String{$ELSE}TOptionalError{$ENDIF};
If errors stack not contains values then returns empty TOptionalValue or raise EErrorNotExists.
uses
utils.errors_stack;
var
errors : TSQL3LiteErrorsStack;
begin
errors := TSQL3LiteErrorsStack.Create;
writeln(errors.Pop);
FreeAndNil(errors);
end;
Return stack count elements.
function Count : LongInt;
uses
utils.errors_stack;
var
errors : TSQL3LiteErrorsStack;
begin
errors := TSQL3LiteErrorsStack.Create;
writeln(errors.Count);
FreeAndNil(errors);
end;
It is possible to iterate for TSQLite3ErrorsStack values using in
operator. Each value would present as String.
uses
utils.errors_stack;
var
errors : TSQL3LiteErrorsStack;
value : String;
begin
errors := TSQL3LiteErrorsStack.Create;
for value in errors do
;
FreeAndNil(errors);
end;