Hi
I want an efficient way to retrieve a table's field info.
I want to find a given field and read its DataType.
Example of what I've tried:
SQL:='SELECT * FROM '+pTable;
dqFieldType:=TMyQuery.Create(self);
dqFieldType.Connection:=DB;
dqFieldType.SQL.Add(SQL);
dqFieldType.FetchAll:=False;
dqFieldType.FetchRows:=1;
dqFieldType.Execute;
Then I use the following to retrieve the DataType of a field (F)
FT:=dqFieldType.Fields.FindField(F).DataType;
This works until to try to Close and Destroy it. When you do it raises this exception:
Project TMS.exe raised exception class EMySqlException with message 'Lost connection to MySQL server during query'.
Why? This problem arises only when I set FetchAll to False and FetchRows to 1. Otherwise it works well. The problem is that some tables are very large and it can take a few seconds to open them in their entirety. I want it to be efficient.
Is there another way to get this info? (Needs to be speed efficient)
Is there a bug in MyDAC?
Thanks for any help offered.
Retrieving Table's Field Info
-
AndreyZ
Re: Retrieving Table's Field Info
Hello,
The TField.DataType property identifies the data type of the field component. It can be determined only after a dataset has been opened (and its fields created). Therefore you can use your code to determine TField.DataType.Is there another way to get this info?
In this case the 'Lost connection to MySQL server during query' error is an internal MyDAC error that is used for internal purposes. Such MyDAC behaviour is correct, it is caused by the specificity of working with not fetched data. You will see the 'Lost connection to MySql server during query' error only if you run your application from IDE. You will not see this error when you run the executable file of your application.Is there a bug in MyDAC?