LiteDAC

Retrieving Data

This tutorial describes how to retrieve data from tables using the TLiteQuery and TLiteTable components.

Requirements

This walkthrough supposes that you know how to connect to server (tutorials "Connecting To SQLite Database"), how to create necessary objects on the server (tutorial "Creating Database Objects"), and how to insert data to created tables (tutorial "Inserting Data Into Tables").

General information

As we know, an original function of any database application is establishing connection to a data source and working with data contained in it. LiteDAC provides several components that can be used for data retrieving, such as TLiteQuery and TLiteTable. We will discuss data retrieving using these components.

The goal of this tutorial is to retrieve data from a table dept.

TLiteQuery

The following code demonstrates retrieving of data from the dept table using the TLiteQuery component:

[Delphi]

var
  LiteQuery: TLiteQuery;
begin
  LiteQuery := TLiteQuery.Create(nil);
  try
    // LiteConnection is either TLiteConnection already set up
    LiteQuery.Connection := LiteConnection; 

    // retrieve data
    LiteQuery.SQL.Text := 'SELECT * FROM dept';
    LiteQuery.Open;

    // shows the number of records obtained from the server
    ShowMessage(IntToStr(LiteQuery.RecordCount));
  finally
    LiteQuery.Free;
  end;
end;

[C++Builder]

{
  TLiteQuery* LiteQuery = new TLiteQuery(NULL);
  try
  {
    // LiteConnection is either TLiteConnection already set up
    LiteQuery->Connection = LiteConnection; 

    // retrieve data
    LiteQuery->SQL->Text = "SELECT * FROM dept";
    LiteQuery->Open();

    // shows the number of records obtained from the server
    ShowMessage(IntToStr(LiteQuery->RecordCount)); 
  }
  __finally
  {
    LiteQuery->Free();
  }
}

TMyTable

The following code demonstrates retrieving of data from the dept table using the TLiteTable component:

[Delphi]

var
  LiteTable: TLiteTable;
begin
  LiteTable := TLiteTable.Create(nil);
  try
    // LiteConnection is either TLiteConnection already set up
    LiteTable.Connection := LiteConnection; 

    // retrieve data
    LiteTable.TableName := 'dept';
    LiteTable.Open;

    // shows the number of records obtained from the server
    ShowMessage(IntToStr(LiteTable.RecordCount)); 
  finally
    LiteTable.Free;
  end;
end;

[C++Builder]

{
  TLiteTable* LiteTable = new TLiteTable(NULL);
  try
  {
    // LiteConnection is either TLiteConnection already set up
    LiteTable->Connection = LiteConnection; 

    // retrieve data
    LiteTable->TableName = "dept";
    LiteTable->Open();

    // shows the number of records obtained from the server
    ShowMessage(IntToStr(LiteTable->RecordCount));
  }
  __finally
  {
    LiteTable->Free();
  }
}
© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback