Autoinc paradox fields - programmatic creation - HELP
sim...@magicnet.net (Frank Postava) wrote thusly:
Quote
>Hey Delphites....
>Using the example for the CreateTable method of the TTable component, I
>can't figure out how to create an autoincrement paradox field. When a
>table is opened, the FieldDef.Datatype for an autoinc field is ftInteger.
> Using ftInteger to create simply makes an Integer field!
>Nay Ideas????
>Thanks In Advance
>Frank...
I had the same question last month and the answer I got from Michael
Salem (a nice fellow across the pond in merry old England) quoted me
section 6 of the Delphi FAQ that answers this specific question. The
following expands on that and shows how to also create a memo field
and detect an existing data base.
{}PROCEDURE TCreate.Build_DB_AddrBook;
{+O
---------------------------------------------------------------------------
Purpose - Create programmatically the AddrBook database and
indexes.
Revised - 1996.0306 (KSB) Wrote initial version.
---------------------------------------------------------------------------}
VAR
lw : WORD;
BEGIN
WITH query1 DO BEGIN
DatabaseName := 'ADDRESSES'; {alias}
WITH SQL DO BEGIN
Clear; {create a paradox table (thus
the .DB extension)}
Add('CREATE TABLE "ADDRBOOL.DB" (');
Add('UniqueKey AUTOINC,'); {use an autoincrement key}
Add('LastName CHAR(80),');
Add('FirstName CHAR(30),');
Add('MiddleName CHAR(30),');
Add('Title CHAR(80),');
Add('ThePosition CHAR(80),'); {"Position" is a SQL keyword,
thus "ThePosition" - Delphi's SQL burps otherwise}
<snip - other fields - snip>
Add('EntryDate DATE,');
Add('Notes BLOB(240),');
{a blob is recognized as a Paradox memo.
the BLOB(240) specifies that 240 characters
of the memo are to be stored in the DB file,
the remainder if any to be stored in the MB file.}
Add('PRIMARY KEY(UniqueKey))');
TRY
ExecSQL; {Execute the SQL statement}
EXCEPT
{
If the database already exists the errorCount is 2 with the
following values:
category 51
errorcode 13057
subcode 1
nativecode 0
message [0] "File already exists."
[1] name_and_path_of_file
ON E:EDBEngineError DO BEGIN
lw := E.errorCount;
FOR lw := 0 TO E.errorCount-1 DO BEGIN
WITH E.errors[lw] DO BEGIN
MessageDlg('AddrBook Creation error:'#$0D
+' category:'+IntToStr(category)+#$0D
+' code:'+IntToStr(errorCode)+#$0D
+' subCode:'+IntToStr(subCode)+#$0D
+' nativeCode: '+IntToStr(nativeError)+#$0D
+message,
mtWarning,[mbOk,mbCancel],0);
END {WITH};
END {FOR};
END {ON};
END {TRY};
Clear;
Add('CREATE INDEX NameAsKey ON "ADDRBOOL.DB" (LastName,
FirstName, MiddleName, Organization)');
ExecSQL;
Clear;
<snip - removed code for other secondary indexes -snip>
END {WITH};
END {WITH};
{}END {Build_DB_AddrBook};
Good Luck.
Keith S. Brown
Information Technology Office
NASA/JSC - Houston