Retrieving Table's Field Info
Posted: Thu 19 Jul 2012 14:02
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.
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.