Page 1 of 1

mysql TZTable.Fieldcount always 0

Posted: 06.04.2012, 14:18
by pomalo
hi

i try to find the number of field in a Mysql table. the table has 10 fields.

using

Code: Select all

tblDetail.FieldCount;
return always 0

i have try to use a TZQuery in a function returning an integer

Code: Select all

Query.SQL.ADD('SELECT COUNT(*) as total FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "' + mytable +'" AND TABLE_SCHEMA = "' + myDatabase + '";';  
Query.ExecSQL;
Result := Query.FieldByName('total').asInteger;

an exception occur saying
Query: Field not found "total"
Sending the query with the same user end password to the mysql utility return the good field count (10)

i use Lazarus 0.9.30 with FPC 2.4.2 on windows 7 and mysql 5.5

an idee
Thanks
Claude

Posted: 25.04.2012, 23:39
by mdaems
Not sure if that fixes your problem, but you should use Open instead of Execsql to get a resultset. Execsql is made for executing updates, deletes, inserts or alters. Not for returning resultsets.

Mark