disqlite3_show_table.dpr

来自「DELPHI 访问SQLITE3 数据库的VCL控件」· DPR 代码 · 共 86 行

DPR
86
字号
{ DISQLite3 example project showing how retrieve data from a table and write it
  to the console. It uses plain DISQLite3 API calls.

  This demo uses the table created by the Create_Table demo. Compile and execute
  the Create_Table demo at least once before running the project.

  Visit the DISQLite3 Internet site for latest information and updates:

    http://www.yunqa.de/delphi/

  Copyright (c) 2005-2007 Ralf Junker, The Delphi Inspiration <delphi@yunqa.de>

------------------------------------------------------------------------------ }

program DISQLite3_Show_Table;

{$I DI.inc}
{$I DISQLite3.inc}

{$APPTYPE CONSOLE}

uses
  SysUtils,
  DISQLite3Api,
  DISQLite3_Demos_Common in '..\DISQLite3_Common_Units\DISQLite3_Demos_Common.pas';

//------------------------------------------------------------------------------

{ This is the callback function triggered for each row in the table.
  We use it to write all fields of a record to the console. }
function WriteRowCallback(UserData: Pointer; ColumnCount: Integer; ColumnValues, ColumnNames: PPAnsiCharArray): Integer;
var
  i: Integer;
begin
  for i := 0 to ColumnCount - 1 do
    begin
      if i > 0 then Write(' | ');
      Write(ColumnValues[i]);
    end;
  WriteLn;
  Result := 0; // Return 0 to retrieve the next record, 1 to abort.
end;

//------------------------------------------------------------------------------

begin
  try
    Open_Demo_Database;
    try
      { sqlite3_exec can trigger a callback function for each record returned
        by an SQL statement. We use this callback function to write all fields
        to the console. }

      WriteLn('Plain table, no sorting:');
      WriteLn;
      { Error? Compile and run the Create_Table demo to set up the required tables. }
      sqlite3_check(sqlite3_exec(DB,
        'SELECT * from People;',
        WriteRowCallback, // <- Callback function!
        nil, nil),
        DB);

      WriteLn;
      WriteLn('Table sorted by LastName, then by FirstName:');
      WriteLn;
      sqlite3_check(sqlite3_exec(DB,
        'SELECT * from People ORDER BY LastName, FirstName;',
        WriteRowCallback, // <- Callback function!
        nil, nil),
        DB);

    finally
      Close_Demo_Database;
    end;

  except
    on e: Exception do
      WriteLn(e.Message);
  end;

  WriteLn;
  WriteLn('Done - Press ENTER to Exit');
  ReadLn;
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?