BDE Help needed with Field Definitions - Any BDE Guru's out there? 
Author Message
 BDE Help needed with Field Definitions - Any BDE Guru's out there?

I'm trying to get the field information from a table using the
DbiOpenFieldList (or as a second choice, DbiGetFieldDesc) function. I
have succeeded with DbiGetFieldDesc except getting the NAME of the
TYPE of the field (I think it passes the INDEX of the type in FLDTYPE
but how do I get the actual NAME of that type?) These functions
provide the size and precision of numeric fields in tables (can't get
that thru the TTable.FieldDefs object.)

I have looked at the BDE32 help file (no delphi help for
DbiOpenFieldList! Go figure...) but no luck.

Anyone want to jump into this challenge? I could really use the help.

Bill



Wed, 18 Jun 1902 08:00:00 GMT  
 BDE Help needed with Field Definitions - Any BDE Guru's out there?

Quote:
>I'm trying to get the field information from a table using the
>DbiOpenFieldList (or as a second choice, DbiGetFieldDesc) function. I
>have succeeded with DbiGetFieldDesc except getting the NAME of the
>TYPE of the field (I think it passes the INDEX of the type in FLDTYPE
>but how do I get the actual NAME of that type?) These functions
>provide the size and precision of numeric fields in tables (can't get
>that thru the TTable.FieldDefs object.)

>I have looked at the BDE32 help file (no Delphi help for
>DbiOpenFieldList! Go figure...) but no luck.

>Anyone want to jump into this challenge? I could really use the help.

Want to get the actual scale and precision values for the field? Use the
function DbiGetCursorProps and DbiGetFieldDescs. The DbiGetFieldDescs fills
a FLDDesc structure with the field definitions. The iUnits2 field of this
structure gives the precision for fields (the field width) and the field
iUnits1 the scale (the number of decimal places for numeric fields, zero
for other field types).

Below is a routine from a component I am working on. The "FieldDefs" token
is a TCollection descendent into which the field definitions are stored in
memory. I am storing the field name, field type (BDE type, not the Delphi
type), field subtype, precision, and scale. I needed this information to
generate the SQL to recreate the table. This requires accurate precision
and scale values which, as you have seen, are not provided by TFieldDef
objects.

  procedure TBDETableTool.ParseDataset;
  var
    i: Integer;
    curProp: CURProps;
    pfldDes, pCurFld: pFLDDesc;
    MemSize: Integer;
  begin
    FieldDefs.Clear;
    DbiGetCursorProps(FTable.Handle, curProp);
    MemSize := curProp.iFields * SizeOf(FLDDesc);
    pfldDes := AllocMem(MemSize);
    try
      pCurFld := pfldDes;
      DbiGetFieldDescs(FTable.Handle, pfldDes);
      i := 0;
      while (i < curProp.iFields) do begin
        FieldDefs.Add(pCurFld^.szName, pCurFld^.iFldType, ftString,
          pCurFld^.iSubType, pCurFld^.iUnits2, pCurFld^.iUnits1);
        inc(pCurFld);
        inc(i);
      end;
    finally
      FreeMem(pfldDes, MemSize);
    end;
  end;

PS. This is just an adaptation of the example in the BDE help for the
DbiGetFieldDescs function.

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx



Wed, 18 Jun 1902 08:00:00 GMT  
 BDE Help needed with Field Definitions - Any BDE Guru's out there?
Steve,

This gets me all the info I need except the FLDTYPE -> "NAME" (szName
I think...) as described in my message. I need to display the field
TYPE in my application (CHAR, STRING, ALPHA, INTEGER, etc...) The
FldDesc structure only returns the INDEX id of the field name
(obviously there is SOME kind of human understanding of this  INDEX
value...like ALPHA, CHAR, etc. I suspect this is an enumerated type of
some sort...) There is poor documentation on the DbiOpenFieldList
(which allows you to get this info WITHOUT having to open the table
first...a nice feature!) but I don't know how to typecast the hDBICur
as a pFldDesc record and use it, along with NOT understanding how to
decipher this INDEX of the field type issue.

Any other thoughts?


Quote:


>>I'm trying to get the field information from a table using the
>>DbiOpenFieldList (or as a second choice, DbiGetFieldDesc) function. I
>>have succeeded with DbiGetFieldDesc except getting the NAME of the
>>TYPE of the field (I think it passes the INDEX of the type in FLDTYPE
>>but how do I get the actual NAME of that type?) These functions
>>provide the size and precision of numeric fields in tables (can't get
>>that thru the TTable.FieldDefs object.)

>>I have looked at the BDE32 help file (no Delphi help for
>>DbiOpenFieldList! Go figure...) but no luck.

>>Anyone want to jump into this challenge? I could really use the help.

>Want to get the actual scale and precision values for the field? Use the
>function DbiGetCursorProps and DbiGetFieldDescs. The DbiGetFieldDescs fills
>a FLDDesc structure with the field definitions. The iUnits2 field of this
>structure gives the precision for fields (the field width) and the field
>iUnits1 the scale (the number of decimal places for numeric fields, zero
>for other field types).

>Below is a routine from a component I am working on. The "FieldDefs" token
>is a TCollection descendent into which the field definitions are stored in
>memory. I am storing the field name, field type (BDE type, not the Delphi
>type), field subtype, precision, and scale. I needed this information to
>generate the SQL to recreate the table. This requires accurate precision
>and scale values which, as you have seen, are not provided by TFieldDef
>objects.

>  procedure TBDETableTool.ParseDataset;
>  var
>    i: Integer;
>    curProp: CURProps;
>    pfldDes, pCurFld: pFLDDesc;
>    MemSize: Integer;
>  begin
>    FieldDefs.Clear;
>    DbiGetCursorProps(FTable.Handle, curProp);
>    MemSize := curProp.iFields * SizeOf(FLDDesc);
>    pfldDes := AllocMem(MemSize);
>    try
>      pCurFld := pfldDes;
>      DbiGetFieldDescs(FTable.Handle, pfldDes);
>      i := 0;
>      while (i < curProp.iFields) do begin
>        FieldDefs.Add(pCurFld^.szName, pCurFld^.iFldType, ftString,
>          pCurFld^.iSubType, pCurFld^.iUnits2, pCurFld^.iUnits1);
>        inc(pCurFld);
>        inc(i);
>      end;
>    finally
>      FreeMem(pfldDes, MemSize);
>    end;
>  end;

>PS. This is just an adaptation of the example in the BDE help for the
>DbiGetFieldDescs function.

>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>Steve Koterski              "Health nuts are going to feel stupid someday,
>Felton, CA                  lying in hospitals dying of nothing."
>                                                              -- Redd Foxx



Wed, 18 Jun 1902 08:00:00 GMT  
 BDE Help needed with Field Definitions - Any BDE Guru's out there?

Quote:
>This gets me all the info I need except the FLDTYPE -> "NAME" (szName
>I think...) as described in my message. I need to display the field
>TYPE in my application (CHAR, STRING, ALPHA, INTEGER, etc...) The
>FldDesc structure only returns the INDEX id of the field name
>(obviously there is SOME kind of human understanding of this  INDEX
>value...like ALPHA, CHAR, etc. I suspect this is an enumerated type of
>some sort...) There is poor documentation on the DbiOpenFieldList
>(which allows you to get this info WITHOUT having to open the table
>first...a nice feature!) but I don't know how to typecast the hDBICur
>as a pFldDesc record and use it, along with NOT understanding how to
>decipher this INDEX of the field type issue.

<... reply by both newsgroup and e-mail ...>

I think the function DbiOpenFieldTypesList would help you in this. At the
end of this reply is a unit (a work in progress) that includes a component
named TFieldTypesTable. This component encapsulates the field types list
and makes its information accessible as a TTable.

The XLTEDTYPE and XLTEDSUBTYPE fields returned by DbiOpenFieldTypesList are
of particular interest to you. The first is the field's type and the second
the subtype. These fields correspond to the iFldType and iSubType fields of
the FLDDesc structure. Using the values from the FLDDesc structure and
methods of TTable, you can either filter the TFieldTypesTable result set or
just move the record pointer to the record corresponding to the data type.
Read the NAME field of TFieldTypesTable using the Fields property or
FieldByName to get the textual representation of the field type. Note that
this data type notation is specific to table types. For instance, a string
field is called "Alpha" for Paradox tables and "CHARACTER" for dBASE. But
the value of the XLTEDTYPE field is the same in both cases: 1.

To use the TFieldTypesTable component, you have to use the name of the BDE
driver for the target table as the value for the
TFieldTypesTable.DriverType property. Set this property after calling the
constructor for the class but before activating the instantiated
TFieldTypesTable object. The property's value would be "PARADOX" for
Paradox tables, "DBASE" for dBASE tables, and so on. One way to get a list
of these driver names is with the API function DbiOpenDriverList
(encapsulated in the included component TDriversTable; use its
GetDriverList method to fill a string list object with the driver names).

// ------------- Begin included unit -----------------------------------

{
  Includes the components:

  TUsersTable
  TLockTable
  TDriversTable
  TTableTypesTable
  TFieldTypesTable

Quote:
}

unit BDESystem;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, DB, DBTables, BDE;

type
  TUsersTable = class(TTable)
  private
    { Private declarations }
  protected
    { Protected declarations }
    function CreateHandle: HDBICur; override;
  public
    { Public declarations }
  published
    { Published declarations }
  end;

  TLockTable = class(TTable)
  private
    { Private declarations }
    FTableHandle: HDBICur;
  protected
    { Protected declarations }
    function CreateHandle: HDBICur; override;
  public
    { Public declarations }
    property TableHandle: HDBICur read FTableHandle write FTableHandle;
  published
    { Published declarations }
  end;

  TDriversTable = class(TTable)
  private
    { Private declarations }
  protected
    { Protected declarations }
    function CreateHandle: HDBICur; override;
  public
    { Public declarations }
    procedure GetDriverList(List: TStrings);
  published
    { Published declarations }
  end;

  TTableTypesTable = class(TTable)
  private
    { Private declarations }
    FDriverType: String;
  protected
    { Protected declarations }
    function CreateHandle: HDBICur; override;
  public
    { Public declarations }
  published
    { Published declarations }
    property DriverType: String read FDriverType write FDriverType;
  end;

  TFieldTypesTable = class(TTable)
  private
    { Private declarations }
    FTableHandle: HDBICur;
    FDriverType: String;
  protected
    { Protected declarations }
    function CreateHandle: HDBICur; override;
  public
    { Public declarations }
    property TableHandle: HDBICur read FTableHandle write FTableHandle;
    property DriverType: String read FDriverType write FDriverType;
  published
    { Published declarations }
  end;

implementation

{ TUsersTable }

function TUsersTable.CreateHandle: HDBICur;
begin
  Result := nil;
  DbiOpenUserList(Result);
end;

{ TUsersTable }

function TLockTable.CreateHandle: HDBICur;
begin
  Result := nil;
  DbiOpenLockList(TableHandle, True, True, Result);
end;

{ TDriversTable }

function TDriversTable.CreateHandle: HDBICur;
begin
  Result := nil;
  DbiOpenDriverList(Result);
end;

procedure TDriversTable.GetDriverList(List: TStrings);
var
  WasActive: Boolean;
begin
  WasActive := Active;
  Close;
  Open;
  List.Clear;
  while not Eof do begin
    List.Add(Fields[0].AsString);
    Next;
  end;
  Active := WasActive;
end;

{ TTableTypesTable }

function TTableTypesTable.CreateHandle: HDBICur;
begin
  Result := nil;
  DbiOpenTableTypesList(PChar(FDriverType), Result);
end;

{ TFieldTypesTable }

function TFieldTypesTable.CreateHandle: HDBICur;
begin
  Result := nil;
  DbiOpenFieldTypesList(PChar(FDriverType), nil, Result);
end;

end.

// ------------- End included unit -------------------------------------

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need Help from BDE API Gurus

2. BDE guru needed...

3. MATH GURU's - I need some help with an AVERAGE problem

4. help:Delphi C/S 2.01 + BDE 3.5 + SQL 6.5 can't modify datetime field

5. Help : BDE GURUS - Language and BLOB problems!

6. BDE Alias's and new installs of the BDE

7. BDE/TQuery guru question

8. BDE coulden't update a Varchar Field: Size 50, Phisycal Length 51

9. Any guru with BDE ?

10. Adding a field to the field-definitions using Diamond Access

11. Pascal Guru's please help....................................................................

12. !!!!!!! HELP QuickReport GURU's !!!!!!!

 

 
Powered by phpBB® Forum Software