You've already forked lazarus-ccr
tvplanit: Fix creation of MS-Access database file for demo of flex datastore-
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6512 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -0,0 +1,10 @@
|
|||||||
|
Copy one of these two empty Access database file to the parent folder.
|
||||||
|
|
||||||
|
If you copied "data.mdb" then you must activate the define MDB in the head of
|
||||||
|
unit "Unit".
|
||||||
|
|
||||||
|
If you copied "data.accdb" then you must activate the define ACCDB.
|
||||||
|
|
||||||
|
Don't activate both!
|
||||||
|
|
||||||
|
Note: On 32-bit systems the ACCDB format has issues.
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="11"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<General>
|
<General>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
@ -17,9 +17,10 @@
|
|||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<FormatVersion Value="2"/>
|
||||||
<FormatVersion Value="1"/>
|
<Modes Count="1">
|
||||||
</local>
|
<Mode0 Name="default"/>
|
||||||
|
</Modes>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="4">
|
<RequiredPackages Count="4">
|
||||||
<Item1>
|
<Item1>
|
||||||
@ -58,7 +59,6 @@
|
|||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<IncludeFiles Value="$(ProjOutDir);dbase"/>
|
<IncludeFiles Value="$(ProjOutDir);dbase"/>
|
||||||
<OtherUnitFiles Value="dbase"/>
|
|
||||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Linking>
|
<Linking>
|
||||||
@ -73,7 +73,7 @@
|
|||||||
</Linking>
|
</Linking>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<Exceptions Count="3">
|
<Exceptions Count="4">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Name Value="EAbort"/>
|
<Name Value="EAbort"/>
|
||||||
</Item1>
|
</Item1>
|
||||||
@ -83,6 +83,9 @@
|
|||||||
<Item3>
|
<Item3>
|
||||||
<Name Value="EFOpenError"/>
|
<Name Value="EFOpenError"/>
|
||||||
</Item3>
|
</Item3>
|
||||||
|
<Item4>
|
||||||
|
<Name Value="EODBCException"/>
|
||||||
|
</Item4>
|
||||||
</Exceptions>
|
</Exceptions>
|
||||||
</Debugging>
|
</Debugging>
|
||||||
</CONFIG>
|
</CONFIG>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="9"/>
|
<Version Value="11"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<General>
|
<General>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
@ -9,11 +9,7 @@
|
|||||||
<Title Value="CreateAccessDB"/>
|
<Title Value="CreateAccessDB"/>
|
||||||
<ResourceType Value="res"/>
|
<ResourceType Value="res"/>
|
||||||
<UseXPManifest Value="True"/>
|
<UseXPManifest Value="True"/>
|
||||||
<Icon Value="0"/>
|
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
|
||||||
<StringTable ProductVersion=""/>
|
|
||||||
</VersionInfo>
|
|
||||||
<BuildModes Count="1">
|
<BuildModes Count="1">
|
||||||
<Item1 Name="Default" Default="True"/>
|
<Item1 Name="Default" Default="True"/>
|
||||||
</BuildModes>
|
</BuildModes>
|
||||||
@ -21,17 +17,21 @@
|
|||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<FormatVersion Value="2"/>
|
||||||
<FormatVersion Value="1"/>
|
<Modes Count="1">
|
||||||
</local>
|
<Mode0 Name="default"/>
|
||||||
|
</Modes>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="2">
|
<RequiredPackages Count="3">
|
||||||
<Item1>
|
<Item1>
|
||||||
<PackageName Value="SQLDBLaz"/>
|
<PackageName Value="FCL"/>
|
||||||
</Item1>
|
</Item1>
|
||||||
<Item2>
|
<Item2>
|
||||||
<PackageName Value="LCL"/>
|
<PackageName Value="SQLDBLaz"/>
|
||||||
</Item2>
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item3>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="2">
|
<Units Count="2">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
@ -39,7 +39,7 @@
|
|||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
</Unit0>
|
</Unit0>
|
||||||
<Unit1>
|
<Unit1>
|
||||||
<Filename Value="..\..\..\odbcdatastore\camain.pas"/>
|
<Filename Value="camain.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<ComponentName Value="Form1"/>
|
<ComponentName Value="Form1"/>
|
||||||
<HasResources Value="True"/>
|
<HasResources Value="True"/>
|
||||||
|
@ -7,8 +7,8 @@ uses
|
|||||||
cthreads,
|
cthreads,
|
||||||
{$ENDIF}{$ENDIF}
|
{$ENDIF}{$ENDIF}
|
||||||
Interfaces, // this includes the LCL widgetset
|
Interfaces, // this includes the LCL widgetset
|
||||||
Forms, caMain
|
Forms,
|
||||||
{ you can add units after this };
|
caMain;
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 262
|
Left = 413
|
||||||
Height = 285
|
Height = 285
|
||||||
Top = 155
|
Top = 171
|
||||||
Width = 400
|
Width = 400
|
||||||
AutoSize = True
|
AutoSize = True
|
||||||
Caption = 'Access database creator'
|
Caption = 'Access database creator'
|
||||||
@ -9,7 +9,7 @@ object Form1: TForm1
|
|||||||
ClientWidth = 400
|
ClientWidth = 400
|
||||||
Constraints.MinWidth = 400
|
Constraints.MinWidth = 400
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
LCLVersion = '1.6.4.0'
|
LCLVersion = '1.9.0.0'
|
||||||
object StatusBar1: TStatusBar
|
object StatusBar1: TStatusBar
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 23
|
Height = 23
|
||||||
@ -103,28 +103,13 @@ object Form1: TForm1
|
|||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
Text = '.\data.mdb'
|
Text = '.\data.mdb'
|
||||||
end
|
end
|
||||||
object Label1: TLabel
|
|
||||||
AnchorSideLeft.Control = FileNameEdit
|
|
||||||
AnchorSideTop.Control = FileNameEdit
|
|
||||||
AnchorSideTop.Side = asrBottom
|
|
||||||
AnchorSideRight.Control = FileNameEdit
|
|
||||||
AnchorSideRight.Side = asrBottom
|
|
||||||
Left = 16
|
|
||||||
Height = 30
|
|
||||||
Top = 47
|
|
||||||
Width = 368
|
|
||||||
Anchors = [akTop, akLeft, akRight]
|
|
||||||
BorderSpacing.Top = 8
|
|
||||||
Caption = 'Use extension .mdb for old Access 97/2000 file format,'#13#10'.accdb for new Access 2007+ file format.'
|
|
||||||
ParentColor = False
|
|
||||||
end
|
|
||||||
object CbCreateVPFields: TCheckBox
|
object CbCreateVPFields: TCheckBox
|
||||||
AnchorSideLeft.Control = FileNameEdit
|
AnchorSideLeft.Control = FileNameEdit
|
||||||
AnchorSideTop.Control = Label1
|
AnchorSideTop.Control = RgFormat
|
||||||
AnchorSideTop.Side = asrBottom
|
AnchorSideTop.Side = asrBottom
|
||||||
Left = 16
|
Left = 16
|
||||||
Height = 19
|
Height = 19
|
||||||
Top = 85
|
Top = 125
|
||||||
Width = 140
|
Width = 140
|
||||||
BorderSpacing.Top = 8
|
BorderSpacing.Top = 8
|
||||||
BorderSpacing.Bottom = 16
|
BorderSpacing.Bottom = 16
|
||||||
@ -133,13 +118,42 @@ object Form1: TForm1
|
|||||||
State = cbChecked
|
State = cbChecked
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
|
object RgFormat: TRadioGroup
|
||||||
|
AnchorSideLeft.Control = FileNameEdit
|
||||||
|
AnchorSideTop.Control = FileNameEdit
|
||||||
|
AnchorSideTop.Side = asrBottom
|
||||||
|
Left = 16
|
||||||
|
Height = 62
|
||||||
|
Top = 55
|
||||||
|
Width = 267
|
||||||
|
AutoFill = True
|
||||||
|
AutoSize = True
|
||||||
|
BorderSpacing.Top = 16
|
||||||
|
Caption = 'Access database format'
|
||||||
|
ChildSizing.LeftRightSpacing = 16
|
||||||
|
ChildSizing.TopBottomSpacing = 2
|
||||||
|
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||||
|
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||||
|
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||||
|
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||||
|
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||||
|
ChildSizing.ControlsPerLine = 1
|
||||||
|
ClientHeight = 42
|
||||||
|
ClientWidth = 263
|
||||||
|
ItemIndex = 0
|
||||||
|
Items.Strings = (
|
||||||
|
'.mdb (Access 97, 2000, 2003), 32 bit only'
|
||||||
|
'.accdb (Access 2007+), 32 bit and 64 bit'
|
||||||
|
)
|
||||||
|
OnClick = RgFormatClick
|
||||||
|
TabOrder = 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
object ODBCConnection1: TODBCConnection
|
object ODBCConnection1: TODBCConnection
|
||||||
Connected = False
|
Connected = False
|
||||||
LoginPrompt = False
|
LoginPrompt = False
|
||||||
KeepConnection = False
|
KeepConnection = False
|
||||||
Transaction = SQLTransaction1
|
Transaction = SQLTransaction1
|
||||||
Options = []
|
|
||||||
left = 48
|
left = 48
|
||||||
top = 168
|
top = 168
|
||||||
end
|
end
|
||||||
@ -147,7 +161,6 @@ object Form1: TForm1
|
|||||||
Active = False
|
Active = False
|
||||||
Action = caCommit
|
Action = caCommit
|
||||||
Database = ODBCConnection1
|
Database = ODBCConnection1
|
||||||
Options = []
|
|
||||||
left = 152
|
left = 152
|
||||||
top = 168
|
top = 168
|
||||||
end
|
end
|
||||||
|
@ -18,17 +18,19 @@ type
|
|||||||
BtnClose: TButton;
|
BtnClose: TButton;
|
||||||
CbCreateVPFields: TCheckBox;
|
CbCreateVPFields: TCheckBox;
|
||||||
FileNameEdit: TFileNameEdit;
|
FileNameEdit: TFileNameEdit;
|
||||||
Label1: TLabel;
|
|
||||||
ODBCConnection1: TODBCConnection;
|
ODBCConnection1: TODBCConnection;
|
||||||
Panel1: TPanel;
|
Panel1: TPanel;
|
||||||
Panel2: TPanel;
|
Panel2: TPanel;
|
||||||
|
RgFormat: TRadioGroup;
|
||||||
SQLTransaction1: TSQLTransaction;
|
SQLTransaction1: TSQLTransaction;
|
||||||
StatusBar1: TStatusBar;
|
StatusBar1: TStatusBar;
|
||||||
procedure BtnCreateDBClick(Sender: TObject);
|
procedure BtnCreateDBClick(Sender: TObject);
|
||||||
procedure BtnCloseClick(Sender: TObject);
|
procedure BtnCloseClick(Sender: TObject);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure RgFormatClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
function CreateAccessDatabase(DatabaseFile: string): boolean;
|
function CreateAccessDatabase(ADatabaseFile: string;
|
||||||
|
out AErrorMsg: String): boolean;
|
||||||
procedure CreateContactsTable;
|
procedure CreateContactsTable;
|
||||||
procedure CreateEventsTable;
|
procedure CreateEventsTable;
|
||||||
procedure CreateResourceTable;
|
procedure CreateResourceTable;
|
||||||
@ -48,7 +50,16 @@ implementation
|
|||||||
uses
|
uses
|
||||||
LCLType, LazFileUtils;
|
LCLType, LazFileUtils;
|
||||||
|
|
||||||
Const
|
const
|
||||||
|
DB_DRIVERS: array[0..1] of String = (
|
||||||
|
'Microsoft Access Driver (*.mdb)',
|
||||||
|
'Microsoft Access Driver (*.mdb, *.accdb)'
|
||||||
|
);
|
||||||
|
EXT: array[0..1] of String = (
|
||||||
|
'.mdb',
|
||||||
|
'.accdb'
|
||||||
|
);
|
||||||
|
|
||||||
ODBC_ADD_DSN = 1;
|
ODBC_ADD_DSN = 1;
|
||||||
ODBC_CONFIG_DSN = 2;
|
ODBC_CONFIG_DSN = 2;
|
||||||
ODBC_REMOVE_DSN = 3;
|
ODBC_REMOVE_DSN = 3;
|
||||||
@ -69,26 +80,34 @@ function SQLInstallerError(iError: integer; pfErrorCode: PInteger;
|
|||||||
procedure TForm1.BtnCreateDBClick(Sender: TObject);
|
procedure TForm1.BtnCreateDBClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
fn: String;
|
fn: String;
|
||||||
|
errMsg: String;
|
||||||
begin
|
begin
|
||||||
if FileNameEdit.FileName = '' then
|
if FileNameEdit.FileName = '' then
|
||||||
exit;
|
exit;
|
||||||
fn := ExpandFileNameUTF8(FilenameEdit.FileName);
|
|
||||||
|
fn := ChangeFileExt(FilenameEdit.FileName, EXT[RgFormat.ItemIndex]);
|
||||||
|
fn := ExpandFileNameUTF8(fn);
|
||||||
if FileExistsUTF8(fn) then
|
if FileExistsUTF8(fn) then
|
||||||
DeleteFileUTF8(fn);
|
DeleteFileUTF8(fn);
|
||||||
|
|
||||||
// Create empty database file
|
// Create empty database file
|
||||||
CreateAccessDatabase(fn);
|
if CreateAccessDatabase(fn, errMsg) then
|
||||||
StatusMsg('Database file created');
|
StatusMsg('Database file created')
|
||||||
|
else begin
|
||||||
|
MessageDlg('Database file could not be created:' + LineEnding + errMsg,
|
||||||
|
mtError, [mbOK], 0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
if CbCreateVPFields.Checked then begin
|
if CbCreateVPFields.Checked then begin
|
||||||
//connection
|
//connection
|
||||||
ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb, *.accdb)';
|
ODBCConnection1.Driver := DB_DRIVERS[RgFormat.ItemIndex];
|
||||||
ODBCConnection1.Params.Add('DBQ=' + fn);
|
ODBCConnection1.Params.Add('DBQ=' + fn);
|
||||||
ODBCConnection1.Params.Add('Locale Identifier=1031');
|
// ODBCConnection1.Params.Add('Locale Identifier=1031');
|
||||||
ODBCConnection1.Params.Add('ExtendedAnsiSQL=1');
|
// ODBCConnection1.Params.Add('ExtendedAnsiSQL=1');
|
||||||
ODBCConnection1.Params.Add('CHARSET=ansi');
|
// ODBCConnection1.Params.Add('CHARSET=ansi');
|
||||||
ODBCConnection1.Connected := True;
|
|
||||||
ODBCConnection1.KeepConnection := True;
|
ODBCConnection1.KeepConnection := True;
|
||||||
|
ODBCConnection1.Connected := True;
|
||||||
|
|
||||||
//transaction
|
//transaction
|
||||||
SQLTransaction1.DataBase := ODBCConnection1;
|
SQLTransaction1.DataBase := ODBCConnection1;
|
||||||
@ -113,55 +132,64 @@ begin
|
|||||||
Close;
|
Close;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TForm1.CreateAccessDatabase(DatabaseFile: string): boolean;
|
function TForm1.CreateAccessDatabase(ADatabaseFile: string;
|
||||||
|
out AErrorMsg: String): boolean;
|
||||||
var
|
var
|
||||||
dbType: string;
|
dbType: string;
|
||||||
driver: string;
|
driver: string;
|
||||||
ErrorCode, ResizeErrorMessage: integer;
|
ErrorCode, ResizeErrorMessage: integer;
|
||||||
ErrorMessage: PChar;
|
ErrorMessage: PChar;
|
||||||
retCode: integer;
|
retCode: integer;
|
||||||
|
L: TStrings;
|
||||||
begin
|
begin
|
||||||
driver := 'Microsoft Access Driver (*.mdb, *.accdb)';
|
Result := false;
|
||||||
|
AErrorMsg := '';
|
||||||
|
|
||||||
{ With this driver,
|
driver := DB_DRIVERS[rgFormat.ItemIndex];
|
||||||
|
|
||||||
|
{ With the new accdb driver,
|
||||||
CREATE_DB/CREATE_DBV12 will create an .accdb format database;
|
CREATE_DB/CREATE_DBV12 will create an .accdb format database;
|
||||||
CREATE_DBV4 will create an mdb
|
CREATE_DBV4 will create an mdb
|
||||||
http://stackoverflow.com/questions/9205633/how-do-i-specify-the-odbc-access-driver-format-when-creating-the-database
|
http://stackoverflow.com/questions/9205633/how-do-i-specify-the-odbc-access-driver-format-when-creating-the-database
|
||||||
}
|
}
|
||||||
|
|
||||||
case Lowercase(ExtractFileExt(DatabaseFile)) of
|
case rgFormat.ItemIndex of
|
||||||
'', '.', '.mdb':
|
0 : dbtype := 'CREATE_DB="' + ADatabaseFile + '"';
|
||||||
dbType := 'CREATE_DBV4="' + DatabaseFile + '"';
|
1 : case Lowercase(ExtractFileExt(ADatabaseFile)) of
|
||||||
'.accdb':
|
'', '.', '.mdb': dbType := 'CREATE_DBV4="' + ADatabaseFile + '"';
|
||||||
dbtype := 'CREATE_DBV12="' + DatabaseFile + '"';
|
'.accdb' : dbtype := 'CREATE_DBV12="' + ADatabaseFile + '"';
|
||||||
else
|
else
|
||||||
raise Exception.CreateFmt('File format "%s" not supported.', [ExtractFileExt(DatabaseFile)]);
|
raise Exception.CreateFmt('File format "%s" not supported.', [ExtractFileExt(ADatabaseFile)]);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// DBPChar := 'CREATE_DBV4="' + DatabaseFile + '"';
|
|
||||||
retCode := SQLConfigDataSource(Hwnd(nil), ODBC_ADD_DSN, PChar(driver), PChar(dbType));
|
retCode := SQLConfigDataSource(Hwnd(nil), ODBC_ADD_DSN, PChar(driver), PChar(dbType));
|
||||||
if retCode <> 0 then
|
// returns 1 in case of success, 0 in case of failure
|
||||||
|
if retCode <> 0 then begin
|
||||||
|
if not FileExists(ADatabaseFile) then
|
||||||
|
AErrorMsg := 'Successful creation reported, but file not found.'
|
||||||
|
else
|
||||||
|
Result := true
|
||||||
|
end else
|
||||||
begin
|
begin
|
||||||
//try alternate driver
|
|
||||||
driver := 'Microsoft Access Driver (*.mdb)';
|
|
||||||
dbType := 'CREATE_DB="' + DatabaseFile + '"';
|
|
||||||
retCode := SQLConfigDataSource(Hwnd(nil), ODBC_ADD_DSN, PChar(driver), PChar(dbType));
|
|
||||||
end;
|
|
||||||
if retCode = 0 then
|
|
||||||
result := true
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
result := false;
|
|
||||||
ErrorCode := 0;
|
ErrorCode := 0;
|
||||||
ResizeErrorMessage := 0;
|
ResizeErrorMessage := 0;
|
||||||
// todo: verify how the DLL is called - use pointers?; has not been tested.
|
// todo: verify how the DLL is called - use pointers?; has not been tested.
|
||||||
GetMem(ErrorMessage, 512);
|
GetMem(ErrorMessage, 512);
|
||||||
try
|
try
|
||||||
SQLInstallerError(1, @ErrorCode, ErrorMessage, SizeOf(ErrorMessage), @ResizeErrorMessage);
|
SQLInstallerError(1, @ErrorCode, ErrorMessage, SizeOf(ErrorMessage), @ResizeErrorMessage);
|
||||||
|
L := TStringList.Create;
|
||||||
|
try
|
||||||
|
L.Delimiter := ';';
|
||||||
|
L.StrictDelimiter := true;
|
||||||
|
L.DelimitedText := ErrorMessage;
|
||||||
|
AErrorMsg := L.Text;
|
||||||
|
finally
|
||||||
|
L.Free;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
FreeMem(ErrorMessage);
|
FreeMem(ErrorMessage);
|
||||||
end;
|
end;
|
||||||
raise Exception.CreateFmt('Error creating Access database: %s', [ErrorMessage]);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -321,6 +349,12 @@ begin
|
|||||||
FilenameEdit.ButtonWidth := FilenameEdit.Height;
|
FilenameEdit.ButtonWidth := FilenameEdit.Height;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.RgFormatClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if FilenameEdit.Filename <> '' then
|
||||||
|
FilenameEdit.FileName := ChangeFileExt(FileNameEdit.FileName, EXT[RgFormat.ItemIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.StatusMsg(const AText: String);
|
procedure TForm1.StatusMsg(const AText: String);
|
||||||
begin
|
begin
|
||||||
Statusbar1.SimpleText := AText;
|
Statusbar1.SimpleText := AText;
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
Use the program CreateAccessDB to create an empty access databank, or one
|
||||||
|
which already contains the empty VisualPlanIt tables.
|
||||||
|
|
||||||
|
The database file can be created in two versions
|
||||||
|
|
||||||
|
* an *.mdb file of the old Access 97-2003. 32-bit only
|
||||||
|
* an *.accdb file for the newer Access 2007+ versions, 32 bit or 64 bit.
|
||||||
|
|
||||||
|
Note: On Win 10 the accdb driver is not installed by default. Install the
|
||||||
|
AccessDatabaseEngine (free Microsoft download):
|
||||||
|
|
||||||
|
* Office 2010: https://www.microsoft.com/en-us/download/details.aspx?id=13255
|
||||||
|
* Office 2007: https://www.microsoft.com/en-us/download/confirmation.aspx?id=23734
|
||||||
|
|
||||||
|
Note: At the time of this writing the program does not run without error,
|
||||||
|
reason unknown. However, before the error appears, the database file already
|
||||||
|
has been successfully created.
|
||||||
|
|
||||||
|
---------
|
||||||
|
|
||||||
|
The VisualPlanIt test program in the parent folder requires the database file
|
||||||
|
to be named either data.mdb or data.accdb. Copy the created mdb or accdb files
|
||||||
|
into the parent folder.
|
@ -8,7 +8,7 @@ object Form1: TForm1
|
|||||||
ClientWidth = 980
|
ClientWidth = 980
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnDestroy = FormDestroy
|
OnDestroy = FormDestroy
|
||||||
LCLVersion = '1.6.4.0'
|
LCLVersion = '1.9.0.0'
|
||||||
object Panel1: TPanel
|
object Panel1: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 33
|
Height = 33
|
||||||
@ -162,7 +162,6 @@ object Form1: TForm1
|
|||||||
Align = alBottom
|
Align = alBottom
|
||||||
TabStop = True
|
TabStop = True
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
KBNavigation = True
|
|
||||||
DateLabelFormat = 'mmmm yyyy'
|
DateLabelFormat = 'mmmm yyyy'
|
||||||
DayHeadAttributes.Font.Height = -13
|
DayHeadAttributes.Font.Height = -13
|
||||||
DayHeadAttributes.Font.Name = 'Tahoma'
|
DayHeadAttributes.Font.Name = 'Tahoma'
|
||||||
@ -171,6 +170,7 @@ object Form1: TForm1
|
|||||||
DrawingStyle = dsFlat
|
DrawingStyle = dsFlat
|
||||||
EventDayStyle = []
|
EventDayStyle = []
|
||||||
HeadAttributes.Color = clBtnFace
|
HeadAttributes.Color = clBtnFace
|
||||||
|
KBNavigation = True
|
||||||
OffDayColor = clSilver
|
OffDayColor = clSilver
|
||||||
SelectedDayColor = clRed
|
SelectedDayColor = clRed
|
||||||
ShowEvents = True
|
ShowEvents = True
|
||||||
@ -357,7 +357,7 @@ object Form1: TForm1
|
|||||||
top = 168
|
top = 168
|
||||||
end
|
end
|
||||||
object VpResourceEditDialog1: TVpResourceEditDialog
|
object VpResourceEditDialog1: TVpResourceEditDialog
|
||||||
Version = 'v1.05'
|
Version = 'v1.12'
|
||||||
DataStore = VpFlexDataStore1
|
DataStore = VpFlexDataStore1
|
||||||
Options = []
|
Options = []
|
||||||
Placement.Position = mpCenter
|
Placement.Position = mpCenter
|
||||||
@ -401,6 +401,7 @@ object Form1: TForm1
|
|||||||
DataSources.ContactsDataSource = DsContacts
|
DataSources.ContactsDataSource = DsContacts
|
||||||
DataSources.TasksDataSource = DsTasks
|
DataSources.TasksDataSource = DsTasks
|
||||||
ResourceID = 0
|
ResourceID = 0
|
||||||
|
OnCreateTable = VpFlexDataStore1CreateTable
|
||||||
left = 136
|
left = 136
|
||||||
top = 101
|
top = 101
|
||||||
ResourceFieldMappings = (
|
ResourceFieldMappings = (
|
||||||
@ -1294,15 +1295,14 @@ object Form1: TForm1
|
|||||||
''
|
''
|
||||||
)
|
)
|
||||||
Transaction = SQLTransaction1
|
Transaction = SQLTransaction1
|
||||||
Options = []
|
|
||||||
Driver = 'Microsoft Access Driver (*.mdb)'
|
Driver = 'Microsoft Access Driver (*.mdb)'
|
||||||
left = 136
|
left = 136
|
||||||
top = 304
|
top = 304
|
||||||
end
|
end
|
||||||
object SQLTransaction1: TSQLTransaction
|
object SQLTransaction1: TSQLTransaction
|
||||||
Active = False
|
Active = False
|
||||||
|
Action = caCommitRetaining
|
||||||
Database = ODBCConnection1
|
Database = ODBCConnection1
|
||||||
Options = []
|
|
||||||
left = 136
|
left = 136
|
||||||
top = 368
|
top = 368
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,10 @@ unit Unit1;
|
|||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
// Select one of these
|
||||||
|
{$DEFINE MDB}
|
||||||
|
{.$DEFINE ACCDB}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -68,8 +72,13 @@ type
|
|||||||
procedure QryGridAfterInsert(DataSet: TDataSet);
|
procedure QryGridAfterInsert(DataSet: TDataSet);
|
||||||
procedure QryGridAfterEdit(DataSet: TDataSet);
|
procedure QryGridAfterEdit(DataSet: TDataSet);
|
||||||
procedure TabControl1Change(Sender: TObject);
|
procedure TabControl1Change(Sender: TObject);
|
||||||
|
procedure VpFlexDataStore1CreateTable(Sender: TObject; TableName: String);
|
||||||
private
|
private
|
||||||
{ private declarations }
|
{ private declarations }
|
||||||
|
procedure CreateContactsTable;
|
||||||
|
procedure CreateEventsTable;
|
||||||
|
procedure CreateResourceTable;
|
||||||
|
procedure CreateTasksTable;
|
||||||
public
|
public
|
||||||
{ public declarations }
|
{ public declarations }
|
||||||
end;
|
end;
|
||||||
@ -82,9 +91,18 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LazFileUtils;
|
LazFileUtils,
|
||||||
|
VpConst;
|
||||||
|
|
||||||
|
|
||||||
|
const
|
||||||
|
{$IFDEF MDB}
|
||||||
|
DB_NAME = '.\data.mdb'; // Access 97 file format
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF ACCDB}
|
||||||
|
DB_NAME = '.\data.accdb'; // Access 2007+ file format
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
// Adds a new resource
|
// Adds a new resource
|
||||||
@ -125,22 +143,175 @@ begin
|
|||||||
QryAllTasks.Open;
|
QryAllTasks.Open;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CreateContactsTable;
|
||||||
|
begin
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE TABLE Contacts ('+
|
||||||
|
'RecordID COUNTER, ' +
|
||||||
|
'ResourceID INTEGER,' +
|
||||||
|
'FirstName VARCHAR(50) ,'+
|
||||||
|
'LastName VARCHAR(50) , '+
|
||||||
|
'Birthdate DATE, '+
|
||||||
|
'Anniversary DATE, '+
|
||||||
|
'Title VARCHAR(50), '+
|
||||||
|
'Company VARCHAR(50), '+
|
||||||
|
'Department VARCHAR(50), '+
|
||||||
|
'Job_Position VARCHAR(30), '+
|
||||||
|
'AddressType1 INTEGER, '+
|
||||||
|
'Address1 VARCHAR(100), '+
|
||||||
|
'City1 VARCHAR(50), '+
|
||||||
|
'State1 VARCHAR(25), '+
|
||||||
|
'Zip1 VARCHAR(10), '+
|
||||||
|
'Country1 VARCHAR(25), '+
|
||||||
|
'AddressType2 INTEGER, '+
|
||||||
|
'Address2 VARCHAR(100), '+
|
||||||
|
'City2 VARCHAR(50), '+
|
||||||
|
'State2 VARCHAR(25), '+
|
||||||
|
'Zip2 VARCHAR(10), '+
|
||||||
|
'Country2 VARCHAR(25), '+
|
||||||
|
'Notes VARCHAR, '+
|
||||||
|
'EMail1 VARCHAR(100), '+
|
||||||
|
'EMail2 VARCHAR(100), '+
|
||||||
|
'EMail3 VARCHAR(100), '+
|
||||||
|
'EMailType1 INTEGER, '+
|
||||||
|
'EMailType2 INTEGER, '+
|
||||||
|
'EMailType3 INTEGER, '+
|
||||||
|
'Phone1 VARCHAR(25), '+
|
||||||
|
'Phone2 VARCHAR(25), '+
|
||||||
|
'Phone3 VARCHAR(25), '+
|
||||||
|
'Phone4 VARCHAR(25), '+
|
||||||
|
'Phone5 VARCHAR(25), '+
|
||||||
|
'PhoneType1 INTEGER, '+
|
||||||
|
'PhoneType2 INTEGER, '+
|
||||||
|
'PhoneType3 INTEGER, '+
|
||||||
|
'PhoneType4 INTEGER, '+
|
||||||
|
'PhoneType5 INTEGER, '+
|
||||||
|
'Website1 VARCHAR(100), '+
|
||||||
|
'Website2 VARCHAR(100), '+
|
||||||
|
'WebsiteType1 INTEGER, '+
|
||||||
|
'WebsiteType2 INTEGER, '+
|
||||||
|
'Category INTEGER, '+
|
||||||
|
'Custom1 VARCHAR(100), '+
|
||||||
|
'Custom2 VARCHAR(100),'+
|
||||||
|
'Custom3 VARCHAR(100), '+
|
||||||
|
'Custom4 VARCHAR(100) )'
|
||||||
|
);
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE UNIQUE INDEX piCRecordID ON Contacts(RecordID) WITH PRIMARY');
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX siCResourceID ON Contacts(ResourceID)');
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX siCName ON Contacts(LastName, FirstName)' );
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX siCCompany ON Contacts(Company)');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CreateEventsTable;
|
||||||
|
begin
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE TABLE Events ('+
|
||||||
|
'RecordID COUNTER, ' +
|
||||||
|
'ResourceID INTEGER, '+
|
||||||
|
'StartTime DATETIME, '+
|
||||||
|
'EndTime DATETIME, '+
|
||||||
|
'Description VARCHAR(255), '+
|
||||||
|
'Location VARCHAR(255), '+
|
||||||
|
'Notes VARCHAR, ' +
|
||||||
|
'Category INTEGER, '+
|
||||||
|
'AllDayEvent LOGICAL, '+
|
||||||
|
'DingPath VARCHAR(255), '+
|
||||||
|
'AlarmSet LOGICAL, '+
|
||||||
|
'AlarmAdvance INTEGER, '+
|
||||||
|
'AlarmAdvanceType INTEGER, '+
|
||||||
|
'SnoozeTime DATETIME, '+
|
||||||
|
'RepeatCode INTEGER, '+
|
||||||
|
'RepeatRangeEnd DATETIME, '+
|
||||||
|
'CustomInterval INTEGER)'
|
||||||
|
);
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE UNIQUE INDEX piERecordID ON Events(RecordID) WITH PRIMARY');
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX EResourceID ON Events(ResourceID)');
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX EStartTime ON Events(StartTime)');
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX EEndTime ON Events(EndTime)');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CreateResourceTable;
|
||||||
|
begin
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE TABLE Resources ( '+
|
||||||
|
'ResourceID COUNTER, ' +
|
||||||
|
'Description VARCHAR(255), '+
|
||||||
|
'Notes VARCHAR, '+ // 1024 --> -
|
||||||
|
'ImageIndex INTEGER, '+
|
||||||
|
'ResourceActive LOGICAL, '+ // BOOL --> LOGICAL
|
||||||
|
'UserField0 VARCHAR(100), '+
|
||||||
|
'UserField1 VARCHAR(100), '+
|
||||||
|
'UserField2 VARCHAR(100), '+
|
||||||
|
'UserField3 VARCHAR(100), '+
|
||||||
|
'UserField4 VARCHAR(100), '+
|
||||||
|
'UserField5 VARCHAR(100), '+
|
||||||
|
'UserField6 VARCHAR(100), '+
|
||||||
|
'UserField7 VARCHAR(100), '+
|
||||||
|
'UserField8 VARCHAR(100), '+
|
||||||
|
'UserField9 VARCHAR(100) )'
|
||||||
|
);
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE UNIQUE INDEX piRResourceID ON Resources(ResourceID) WITH PRIMARY'
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.CreateTasksTable;
|
||||||
|
begin
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE TABLE Tasks ('+
|
||||||
|
'RecordID COUNTER, ' +
|
||||||
|
'ResourceID INTEGER, '+
|
||||||
|
'Complete LOGICAL, '+
|
||||||
|
'Description VARCHAR(255), '+
|
||||||
|
'Details VARCHAR, '+
|
||||||
|
'CreatedOn DATETIME, '+
|
||||||
|
'Priority INTEGER, '+
|
||||||
|
'Category INTEGER, '+
|
||||||
|
'CompletedOn DATETIME, '+
|
||||||
|
'DueDate DATETIME)'
|
||||||
|
);
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE UNIQUE INDEX piTRecordID ON Tasks(RecordID) WITH PRIMARY'
|
||||||
|
);
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX siTDueDate ON Tasks(DueDate)'
|
||||||
|
);
|
||||||
|
ODBCConnection1.ExecuteDirect(
|
||||||
|
'CREATE INDEX siTCompletedOn ON Tasks(CompletedOn)'
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
// Setting up the database connection and the datastore. Preselect a resource
|
// Setting up the database connection and the datastore. Preselect a resource
|
||||||
// in the resource combo.
|
// in the resource combo.
|
||||||
procedure TForm1.FormCreate(Sender: TObject);
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if not FileExists('data.mdb') then begin
|
if not FileExists(DB_NAME) then begin
|
||||||
MessageDlg('Database file "data.mdb" does not exist. ' + LineEnding +
|
MessageDlg('Database file "' + DB_NAME + '" does not exist. ' + LineEnding +
|
||||||
'Please run "CreateAccessDB" to create an empty Access database file.',
|
'Please run "CreateAccessDB" to create an empty Access database file.' + LineEnding +
|
||||||
|
'Or copy an empty database file, data.mdb or data.accdb, from the '+
|
||||||
|
'folder "empty_db" to the current directory.',
|
||||||
mtError, [mbOK], 0);
|
mtError, [mbOK], 0);
|
||||||
Close;exit;
|
Close;exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
try
|
try
|
||||||
// Connection
|
// Connection
|
||||||
|
{$IFDEF MDB}
|
||||||
ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb)';
|
ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb)';
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF ACCDB}
|
||||||
|
ODBCConnection1.Driver := 'Microsoft Access Driver (*.mdb, *.accdb)';
|
||||||
|
{$ENDIF}
|
||||||
ODBCConnection1.Params.Clear;
|
ODBCConnection1.Params.Clear;
|
||||||
ODBCConnection1.Params.Add('DBQ=.\data.mdb');
|
ODBCConnection1.Params.Add('DBQ=' + DB_NAME);
|
||||||
ODBCConnection1.Connected := true;
|
ODBCConnection1.Connected := true;
|
||||||
ODBCConnection1.KeepConnection := true;
|
ODBCConnection1.KeepConnection := true;
|
||||||
|
|
||||||
@ -227,5 +398,14 @@ begin
|
|||||||
Grid.Columns[i].Width := 100;;
|
Grid.Columns[i].Width := 100;;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.VpFlexDataStore1CreateTable(Sender: TObject; TableName: String
|
||||||
|
);
|
||||||
|
begin
|
||||||
|
if TableName = ResourceTableName then CreateResourceTable;
|
||||||
|
if TableName = ContactsTableName then CreateContactsTable;
|
||||||
|
if TableName = EventsTableName then CreateEventsTable;
|
||||||
|
if TableName = TasksTableName then CreateTasksTable;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user