⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disqlite3_profile.dpr

📁 DELPHI 访问SQLITE3 数据库的VCL控件
💻 DPR
字号:
{ DISQLite3 example project showing how to profile SQL execution times using
  the build-in sqlite3_profile function.

  !!! Important: This project requires the full version of DISQLite3 since
  !!!            it uses some functions not available in DISQLite Personal.

  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_Profile;

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

{$IFDEF DISQLite3_Personal}
!!! This project requires functionality unavailable in DISQLite3 Personal. !!!
!!! To compile, download DISQLite3 Pro from www.yunqa.de/delphi/           !!!
{$ENDIF DISQLite3_Personal}

{$APPTYPE CONSOLE}

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

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

procedure Profile_Callback(
  UserData: Pointer;
  const SQL: PAnsiChar;
  elapseTime: Int64);
begin
  WriteLn;
  WriteLn('Elapsed Time: ', elapseTime / 1000000000: 0: 4, ' seconds for SQL statement:');
  WriteLn(SQL);
end;

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

var
  Stmt: TDISQLite3StatementHandle;
begin
  try
    Open_Demo_Database;
    try
      { Register a profile callback function. The sqlite3_profile function is
        not available with the DISQLite3 Personal edition! Instead, compile this
        example project with the DISQLite3 Standard edition available from the
        DISQLite3 Internet site. }
      sqlite3_profile(DB, Profile_Callback, nil); // Compile Error? Read First Comment Above!

      { Prepare an SQL statment to select duplicate entries. If the table is not
        indexed, this query can take a while to execute! An appropriate index
        can for example be created with "CREATE INDEX i ON RandomTable (RandomInt);" }
      sqlite3_check(sqlite3_prepare(
        DB,
        'SELECT RandomInt, COUNT() FROM RandomTable GROUP BY RandomInt HAVING COUNT() > 1;',
        -1, // Length of SQL statement, pass -1 to autodetect
        @Stmt, // Variable which takes the prepared SQL statement
        nil), // Variable to store beginning of next SQL statement or nil if not needed.
        DB);

      if Assigned(Stmt) then
        try
          WritePreparedStatement(DB, Stmt);
        finally
          sqlite3_finalize(Stmt);
        end;

    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -