 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chip Guest
|
Posted: Tue May 03, 2005 8:13 pm Post subject: How can I get the size and precision of a field |
|
|
Dear all,
I wrote a little quick test program trying to get the first field
information from a table. I can get the field name but the size and
precision are not. It just return an zero to me.
Here is the highlight of the code
type
edit1: TEdit;
edit2: TEdit;
edit3: TEdit;
MyQuery: TQuery;
procedure TFormMain.FormActive(Sender: Tobject);
begin
MyQuery.Active := False;
MyQuery.Close;
MyQuery.Sql.Clear;
MyQuery.Sql.Add('select * from table1');
MyQuery.Active := True;
// Get first field definition and display it
edit1.text := MyQuery.FieldDefList.FieldDefs[0].Name;
edit2.text := IntToStr(MyQuery.FieldDefList.FieldDefs[0].Size);
edit3.text := IntToStr(MyQuery.FieldDefList.FieldDefs[0].Precision;
end
Rgds,
Chip Ling
|
|
| Back to top |
|
 |
Dan Guest
|
Posted: Wed May 04, 2005 12:39 am Post subject: Re: How can I get the size and precision of a field |
|
|
Chip,
It will help us a lot if you would tell us what database you are
using.
Dan
On 3 May 2005 13:13:14 -0700, "Chip" <chip_ling (AT) yahoo (DOT) ca> wrote:
| Quote: | Dear all,
I wrote a little quick test program trying to get the first field
information from a table. I can get the field name but the size and
precision are not. It just return an zero to me.
Here is the highlight of the code
type
edit1: TEdit;
edit2: TEdit;
edit3: TEdit;
MyQuery: TQuery;
procedure TFormMain.FormActive(Sender: Tobject);
begin
MyQuery.Active := False;
MyQuery.Close;
MyQuery.Sql.Clear;
MyQuery.Sql.Add('select * from table1');
MyQuery.Active := True;
// Get first field definition and display it
edit1.text := MyQuery.FieldDefList.FieldDefs[0].Name;
edit2.text := IntToStr(MyQuery.FieldDefList.FieldDefs[0].Size);
edit3.text := IntToStr(MyQuery.FieldDefList.FieldDefs[0].Precision;
end
Rgds,
Chip Ling
|
|
|
| Back to top |
|
 |
Chip Guest
|
Posted: Wed May 04, 2005 4:26 pm Post subject: Re: How can I get the size and precision of a field |
|
|
Dan,
Good question. It is a propriertary database from IEX using the Simba
ODBC driver.
I re-test my code with Oracle database. Now I can get the field size
for the varchar field.
But all the numeric fields still return me zero on both Size and
Decision.
Rgds,
Chip
|
|
| Back to top |
|
 |
Dan Guest
|
Posted: Thu May 05, 2005 6:42 pm Post subject: Re: How can I get the size and precision of a field |
|
|
On 4 May 2005 09:26:02 -0700, "Chip" <chip_ling (AT) yahoo (DOT) ca> wrote:
| Quote: | Dan,
Good question. It is a propriertary database from IEX using the Simba
ODBC driver.
I re-test my code with Oracle database. Now I can get the field size
for the varchar field.
But all the numeric fields still return me zero on both Size and
Decision.
This is not necessarily wrong. A Paradox number field for example: |
[from the help]
"The range of values possible for a number field is from -10^307 to
10^308 with 15 significant digits".
This means it is stored as a signed integer and a signed exponent.
There is no size or precision to set for this type of db. Maybe IEX
has a similar numeric field. I don't have the Oracle definitions handy
but I suspect it is similar to the Paradox type rather than the dBase
type.
HTH,
Dan
|
|
| Back to top |
|
 |
Chip Guest
|
Posted: Sat May 07, 2005 1:01 am Post subject: Re: How can I get the size and precision of a field |
|
|
OK, I might be going the wrong way then.
Let's get back to the beginning. I want to get the field definition of
a table in Delphi. I can get the data type, field name. So far I don't
know how to get the size and precision of it.
I know how to do it in C++, just make the ODBC API calls and can get
all those field definition back. Pretty simple.
Does Delphi object has such a capability to get those information?
Rgds,
Chip
Dan wrote:
| Quote: | This is not necessarily wrong. A Paradox number field for example:
[from the help]
"The range of values possible for a number field is from -10^307 to
10^308 with 15 significant digits".
This means it is stored as a signed integer and a signed exponent.
There is no size or precision to set for this type of db. Maybe IEX
has a similar numeric field. I don't have the Oracle definitions
handy
but I suspect it is similar to the Paradox type rather than the dBase
type.
HTH,
Dan
|
|
|
| Back to top |
|
 |
Dan Guest
|
Posted: Sat May 07, 2005 2:32 am Post subject: Re: How can I get the size and precision of a field |
|
|
On 6 May 2005 18:01:45 -0700, "Chip" <chip_ling (AT) yahoo (DOT) ca> wrote:
<snip>
| Quote: |
I know how to do it in C++, just make the ODBC API calls and can get
all those field definition back. Pretty simple.
You should be able to do exactly the same thing in Delphi. You might |
have to change a datatype here or there. For example, here is a BDE
API call I use successfully:
function Tdm.datapath: string;
var
dbDes: DBDesc; // DBDesc is defined in BDE unit
begin
try
Check(DbiGetDatabaseDesc(pchar('DCLSdata'), @dbDes));
// get Data path from BDE alias
result := dbDes.szPhyName;
except
result := 'C:Program Files ...
end;
end;
This uses Pchar(stringvalue) to cast the variable into the datatype
that the API uses.
hth,
Dan
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|