How to read primary key
How to read primary key
I am trying to read the primary key info using TMyTable.IndexDefs
However IndexDefs.Options does not contain ixPrimary even if the index is a primary key.
How to read primary key info?
Best regards,
Jaakko
However IndexDefs.Options does not contain ixPrimary even if the index is a primary key.
How to read primary key info?
Best regards,
Jaakko
Please specify some addition information:
- Pascal code you use to get the information about key fields;
- script to create your table;
- exact version of Delphi, C++Builder or Kylix;
- exact version of MyDAC. You can see it in the About sheet of TMyConnection Editor;
- exact version of MySQL server and MySQL client. You can see it in the Info sheet of TMyConnection Editor.
- Pascal code you use to get the information about key fields;
- script to create your table;
- exact version of Delphi, C++Builder or Kylix;
- exact version of MyDAC. You can see it in the About sheet of TMyConnection Editor;
- exact version of MySQL server and MySQL client. You can see it in the Info sheet of TMyConnection Editor.
MySQL version: 5.0.24a
MySQL client: 5.0.11
MyDAC verison: I don't know because I use them from code only. Have not installed them because installing messes up my Delphi. I do not have source code but DCU only. Date is
22.10.2005 00:23 103 685 MemData.dcu
I am using Delphi 7
Here is code:
procedure TLaMySqlDatabase.DoGetForeignKeys(dataSet: TDataSet; keys: TTntStrings);
begin
IndexDefsToForeignKeys((dataSet as TMyTable).IndexDefs, keys);
end;
procedure TLaDatabase.IndexDefsToForeignKeys(value: TIndexDefs; keys: TTntStrings);
var
i: Integer;
begin
for i := 0 to value.Count - 1 do
if not (ixPrimary in value.Options) then
keys.Add(value.Fields);
end;
In the above Options does not contains ixPrimary
I used MySQL Administrator to create the table not SQL.
I tried to attach a screnshot to this forum but could not. How to do that?
Best regards,
Jaakko
MySQL client: 5.0.11
MyDAC verison: I don't know because I use them from code only. Have not installed them because installing messes up my Delphi. I do not have source code but DCU only. Date is
22.10.2005 00:23 103 685 MemData.dcu
I am using Delphi 7
Here is code:
procedure TLaMySqlDatabase.DoGetForeignKeys(dataSet: TDataSet; keys: TTntStrings);
begin
IndexDefsToForeignKeys((dataSet as TMyTable).IndexDefs, keys);
end;
procedure TLaDatabase.IndexDefsToForeignKeys(value: TIndexDefs; keys: TTntStrings);
var
i: Integer;
begin
for i := 0 to value.Count - 1 do
if not (ixPrimary in value.Options) then
keys.Add(value.Fields);
end;
In the above Options does not contains ixPrimary
I used MySQL Administrator to create the table not SQL.
I tried to attach a screnshot to this forum but could not. How to do that?
Best regards,
Jaakko
Here is SQL code
DROP TABLE IF EXISTS `original`.`original`;
CREATE TABLE `original`.`original` (
`Id` int(10) unsigned NOT NULL auto_increment,
`Original` int(10) unsigned NOT NULL,
`Language` varchar(10) NOT NULL,
`Name` varchar(45) NOT NULL,
PRIMARY KEY (`Id`),
KEY `FK_Original_1` (`Original`),
CONSTRAINT `FK_Original_1` FOREIGN KEY (`Original`) REFERENCES `original` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
You see that Id has primary key bit TMyTable.IndexDefs[0].Options does not have it.
Jaakko
DROP TABLE IF EXISTS `original`.`original`;
CREATE TABLE `original`.`original` (
`Id` int(10) unsigned NOT NULL auto_increment,
`Original` int(10) unsigned NOT NULL,
`Language` varchar(10) NOT NULL,
`Name` varchar(45) NOT NULL,
PRIMARY KEY (`Id`),
KEY `FK_Original_1` (`Original`),
CONSTRAINT `FK_Original_1` FOREIGN KEY (`Original`) REFERENCES `original` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
You see that Id has primary key bit TMyTable.IndexDefs[0].Options does not have it.
Jaakko
Check the MydacVersion constant at run time (the MyAccess unit should be included into the uses clause).jaska45 wrote: MyDAC verison: I don't know because I use them from code only. Have not installed them because installing messes up my Delphi. I do not have source code but DCU only. Date is
22.10.2005 00:23 103 685 MemData.dcu
Thank you for information.
This property does not provide the information about primary keys. Try to use the following way:
Another way to request such meta information is to execute a MySQL command like 'SHOW COLUMNS FROM tb_name';
This property does not provide the information about primary keys. Try to use the following way:
Code: Select all
for i := 0 to MyTable.Fields.Count - 1 do
if pfInKey in MyTable.Fields[i].ProviderFlags then
// ...How is this doing with primary key. I don't understand. According to VCL's documentation is NOTHING to do with primary keys. Can tell little bit more about your idea.
On avery other data control (e.g. TTable, TIBTable, TAdoTable) IndexDefs works. Why is it so that your controls do not work in the same was as VCL's own controls. Even your different controls (e.g. MyDAC, ODAC and SDAC) they all work in the different way. It is very hard to use them because they do not work in the same way.
Jaakko
On avery other data control (e.g. TTable, TIBTable, TAdoTable) IndexDefs works. Why is it so that your controls do not work in the same was as VCL's own controls. Even your different controls (e.g. MyDAC, ODAC and SDAC) they all work in the different way. It is very hard to use them because they do not work in the same way.
Jaakko
Provider flags are filled by TMyTable for the reasons of compatibility with Midas (see Delphi help for more information). You can use these flags to obtain the information you need.
I tested this issue with BDE, ADO and MySQL server. They also do not allow determining primary keys in this way. Please send me an example at evgeniyd*crlab*com if I am wrong.
We well think about filling the ixPrimary option of IndexDef in one of the next MyDAC builds.
We are investigating the possibility to add to MyDAC a new component for retrieving metainformation like TMSMetadata in SDAC.
I tested this issue with BDE, ADO and MySQL server. They also do not allow determining primary keys in this way. Please send me an example at evgeniyd*crlab*com if I am wrong.
We well think about filling the ixPrimary option of IndexDef in one of the next MyDAC builds.
We are investigating the possibility to add to MyDAC a new component for retrieving metainformation like TMSMetadata in SDAC.