Page 1 of 1
Check if field exists
Posted: Tue 27 Nov 2012 08:58
by oz8hp
I have got the problem that I need to check if a field exists in a table but since the app runs on both MS Access and MySQL I need a way to do it in general.
(I use an old version 3 of UniDAC but company won't upgrade since this version works OK for our needs)
Re: Check if field exists
Posted: Tue 27 Nov 2012 10:18
by AndreyZ
You can use the TUniMetaData component for this. Here is code example:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
UniMetaData1.MetaDataKind := 'Columns';
if AnsiSameText(UniMetaData1.Connection.ProviderName, 'MySQL') then // MS Access does not support schemas
UniMetaData1.Restrictions.Values['TABLE_SCHEMA'] := 'databasename';
UniMetaData1.Restrictions.Values['TABLE_NAME'] := 'tablename';
UniMetaData1.Restrictions.Values['COLUMN_NAME'] := 'columnname';
UniMetaData1.Open;
if not UniMetaData1.Eof then
ShowMessage('Field exists')
else
ShowMessage('Field does not exist');
end;