Hi,
is it possible to determine what the native SQL data type of a field in a TMyTable is?
If yes, is there a generic method in TCustomDADataSet that could be used for this task in ODAC, PgDAC, etc.?
By SQL data type I mean "INTEGER", "CHAR", "TIMESTAMP", etc.
How to obtain the native SQL data type?
-
AndreyZ
Hello,
To obtain data type names, you can use the TMyMetaData component. Here is an example:You can use the same approach in ODAC and PgDAC.
To obtain data type names, you can use the TMyMetaData component. Here is an example:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
ts: string;
begin
MyMetaData1.MetaDataKind := 'Columns';
MyMetaData1.Restrictions.Values['TABLE_SCHEMA'] := 'database';
MyMetaData1.Restrictions.Values['TABLE_NAME'] := 'table';
MyMetaData1.Open;
ts := '';
while not MyMetaData1.Eof do begin
ts := ts + 'Field name: ' + MyMetaData1.FieldByName('COLUMN_NAME').AsString +
'; Field type: ' + MyMetaData1.FieldByName('DATA_TYPE').AsString + #13#10;
MyMetaData1.Next;
end;
if ts '' then
ShowMessage(ts);
end;-
jmuehlenhoff
- Posts: 36
- Joined: Fri 30 Apr 2010 11:25
As a matter of fact I have a few additional questions:
I've tried this with the TDAMetaData component on several differnt databases.
MySQL: I get exactly what I expect, the data_type is the SQL data type name and the data_length is ok.
Firebird: The data_length is fine, but the data_type returns numbers instead of names.
Microsoft SQL Server: The same as Firebird.
PostgreSQL: The same as Firebird, but in addition CHAR fields have a data_length of -1.
I haven't tried Oracle yet.
So the questions are:
1. Why does PgDAC return -1 for data_length on CHAR fields?
2. Why do some databases return numbers for the data_type and how can I map the numbers to SQL type names?
I've tried this with the TDAMetaData component on several differnt databases.
MySQL: I get exactly what I expect, the data_type is the SQL data type name and the data_length is ok.
Firebird: The data_length is fine, but the data_type returns numbers instead of names.
Microsoft SQL Server: The same as Firebird.
PostgreSQL: The same as Firebird, but in addition CHAR fields have a data_length of -1.
I haven't tried Oracle yet.
So the questions are:
1. Why does PgDAC return -1 for data_length on CHAR fields?
2. Why do some databases return numbers for the data_type and how can I map the numbers to SQL type names?
-
AndreyZ