disqlite3_world_common.pas
来自「DELPHI 访问SQLITE3 数据库的VCL控件」· PAS 代码 · 共 129 行
PAS
129 行
{ 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>
------------------------------------------------------------------------------ }
unit DISQLite3_World_Common;
{$I DI.inc}
interface
uses
Classes, Forms, Controls, ComCtrls, DB, StdCtrls, Mask, ExtCtrls, Grids,
DBCtrls, DBGrids,
DISQLite3Api, DISQLite3Database, DISQLite3DataSet;
type
TfrmWorld_Common = class(TForm)
StatusBar: TStatusBar;
DISQLite3Database: TDISQLite3Database;
pnlMain: TPanel;
imgFlag: TDBImage;
DataSource: TDataSource;
DBNavigator: TDBNavigator;
DISQLite3UniDirQuery: TDISqlite3UniDirQuery;
lblCountry: TLabel;
lblArea: TLabel;
lblPopulation: TLabel;
lblBackground: TLabel;
edtName: TDBEdit;
edtArea: TDBEdit;
edtPopulation: TDBEdit;
edtBackground: TDBMemo;
lblBirthRate: TLabel;
edtBirthRate: TDBEdit;
edtLifeExpectancy: TDBEdit;
lblLifeExpectancy: TLabel;
procedure FormCreate(Sender: TObject);
procedure DISQLite3UniDirQueryInitFieldDef(
const AColumn: TDISQLite3Column; const AFieldDef: TFieldDef);
end;
var
frmWorld_Common: TfrmWorld_Common;
const
SQL_CREATE_COUNTRIES =
'CREATE TABLE Countries (' + #13#10 +
'"ID" INTEGER PRIMARY KEY,' + #13#10 +
'"Name" TEXT UNIQUE,' + #13#10 +
'"Background" TEXT,' + #13#10 +
'"Area" INTEGER,' + #13#10 +
'"Population" INTEGER,' + #13#10 +
'"Birth Rate" FLOAT,' + #13#10 +
'"Life Expectancy" FLOAT,' + #13#10 +
'"Flag" BLOB' + #13#10 +
')';
APP_TITLE = 'DISQLite3 Demo - World';
implementation
uses
SysUtils;
{$R *.dfm}
const
DATABASE_NAME = '..\World.db3';
procedure TfrmWorld_Common.FormCreate(Sender: TObject);
begin
Caption := APP_TITLE;
DISQLite3Database.DatabaseName := DATABASE_NAME;
try
DISQLite3Database.Open;
except
DISQLite3Database.CreateDatabase;
DISQLite3Database.Execute16(SQL_CREATE_COUNTRIES);
end;
end;
//------------------------------------------------------------------------------
procedure TfrmWorld_Common.DISQLite3UniDirQueryInitFieldDef(
const AColumn: TDISQLite3Column;
const AFieldDef: TFieldDef);
begin
{ This event is called once for each newly created FieldDef. Use it to adjust
the FieldDefs of TDISQLite3UniDirDataSet during runtime.
AColumn provides information about the original DISQLite3 column. AFieldDef
is a pre-initialized instance of TFieldDef representing this column.
Purpose: Since DISQLite3 text fields can store unlimited, it does not not
require memo fields. TDataSet, however, needs memos to stong long text.
This event is convenient to map certain DISQLite3 columns to memo fields. }
if AColumn.ColumnName = 'Background' then
begin
AFieldDef.DataType := {$IFDEF COMPILER_10_UP}ftWideMemo{$ELSE}ftMemo{$ENDIF};
end
else
case AFieldDef.DataType of
ftLargeInt:
if AColumn.ColumnName = 'ID' then
begin
{ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
There are known problems/bugs in TClientDataSet/TDataBaseProvider
which can cause serious trouble with ftLargeInt fields. To avoid
those, we downsize ftLargeInt to ftInteger for Index Fields.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
AFieldDef.DataType := ftInteger;
end;
ftWideString:
begin
AFieldDef.Size := 64;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?