Skip to content

TSQLite3ErrorsStack

Ivan Semenkov edited this page Jan 31, 2021 · 1 revision

Table of contents

About

TSQLite3ErrorsStack collect database errors.

uses
  sqlite3.errors_stack;
  
type
  TSQL3LiteErrorsStack = class({$IFDEF FPC}specialize{$ENDIF}
    TListErrorsStack<String>)

TOptionalValue

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}

Create

A new errors stack can be created by call its constructor.

constructor Create;
Example
uses
  utils.errors_stack;

var
  errors : TSQL3LiteErrorsStack;
  
begin
  errors := TSQL3LiteErrorsStack.Create;

  FreeAndNil(errors);
end;

Push

Push error to stack.

procedure Push (AError : String);
procedure Push (AError : TSQLite3Code);
procedure Push (AErrorCode : Integer);
Example
uses
  utils.errors_stack;

var
  errors : TSQL3LiteErrorsStack;
  
begin
  errors := TSQL3LiteErrorsStack.Create;
  errors.Push(SQLITE_ERROR);

  FreeAndNil(errors);
end;

Pop

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.

Example
uses
  utils.errors_stack;

var
  errors : TSQL3LiteErrorsStack;
  
begin
  errors := TSQL3LiteErrorsStack.Create;
  writeln(errors.Pop);

  FreeAndNil(errors);
end;

Count

Return stack count elements.

function Count : LongInt;
Example
uses
  utils.errors_stack;

var
  errors : TSQL3LiteErrorsStack;
  
begin
  errors := TSQL3LiteErrorsStack.Create;
  writeln(errors.Count);

  FreeAndNil(errors);
end;

Iterate

It is possible to iterate for TSQLite3ErrorsStack values using in operator. Each value would present as String.

Example
uses
  utils.errors_stack;

var
  errors : TSQL3LiteErrorsStack;
  value : String;
  
begin
  errors := TSQL3LiteErrorsStack.Create;
  for value in errors do
    ;

  FreeAndNil(errors);
end;