TFieldType problem

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

TFieldType problem

Post by kaffeburk » Sat 26 Jul 2008 13:43

I'm trying to clone a database into a TVirtualTable. Im using 3 methods from the TmyQuery:

(1) GetFieldNames (works fine)
(2) GetDataType (works randomly)
(3) GetFieldPrecision (works randomly)

The later 2 methods don't seem to work, are they implemented in Mydac? If not i guess i have to extract them myself from Mysql using paramtext....

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 31 Jul 2008 12:13

In order to learn the field datatype you can use the TFieldDef.DataType property.
To learn the field precision, you can use the TFieldDef.Precision property.

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Post by kaffeburk » Mon 04 Aug 2008 13:07

Dimon wrote:In order to learn the field datatype you can use the TFieldDef.DataType property.
To learn the field precision, you can use the TFieldDef.Precision property.
I cant find any such property. Where can i find the TFieldDef ? Its not a member of TMyQuery...

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 05 Aug 2008 11:26

To get access to the field definitions list for a dataset you can use the TDataSet.FieldDefs property or TDataSet.FieldDefList.

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Post by kaffeburk » Tue 05 Aug 2008 13:43

Dimon wrote:To get access to the field definitions list for a dataset you can use the TDataSet.FieldDefs property or TDataSet.FieldDefList.
Sorry, i cant find that either. Can you please provide an code example?

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Post by kaffeburk » Tue 05 Aug 2008 15:19

Ah, think i got it:

dbFtype:= qry_getinfo.FieldDefs[0].DataType;

Thanx!

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Post by kaffeburk » Tue 05 Aug 2008 16:03

Neither FieldDefs or FieldDefList provides the precision for VARCHAR, the result is always 0.

FieldDefs[].Name does work. I guess i'm back to query MySql directly...

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 06 Aug 2008 11:17

The Precision property defines the total number of digits stored in numeric fields. To get the length of string field you should use the TFieldDef.Size property.

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Post by kaffeburk » Wed 06 Aug 2008 13:27

Dimon wrote:The Precision property defines the total number of digits stored in numeric fields. To get the length of string field you should use the TFieldDef.Size property.
What i am looking for is the maximum precision as the database was defined in mysql. If i have a column created as VARCHAR(60) i want to retrieve the 60.

jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Post by jkuiper » Thu 07 Aug 2008 13:28

use this:

Code: Select all

virtualtable.Assign(MyQuery)
. Works for me.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 08 Aug 2008 06:18

In order to get 60 for the VARCHAR(60) field you should use the TFieldDef.Size property.
The Precision property defines the total number of digits stored in NUMERIC! fields.

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

Post by kaffeburk » Fri 08 Aug 2008 09:03

jkuiper wrote:use this:

Code: Select all

virtualtable.Assign(MyQuery)
. Works for me.
Thanx, i missed that procedure. ... Spending a week wrinting my own assign...

Is there any way to add another MyQuery? I need to add mutiple assigns to my virtualtable.

jkuiper
Posts: 138
Joined: Fri 04 Aug 2006 14:17

Post by jkuiper » Fri 08 Aug 2008 09:59

Do you mean adding another Myquery with the same structure after assigned the first dataset? I don't think so. Then its better to use TBatchmove.
If you want to use Myquery with another structure with the same virtualtable, it's possible.
The best thing to do that

Code: Select all

VirtualTable.DeleteFields;
Virtualtable.Assign(Myquery);
The stranges thing is that dimon could no the answere, because he could find it here http://devart.com/forums/viewtopic.php?t=107

I'm glad I could help you
:wink:

Post Reply