Roger Cigol 107 Posted November 24, 2020 I am using DUnit based unit tests to devlop FireDAC VCL C++ code (Sydney 10.4.1). I am using FDMemTables to create test instances of database tables to unit test FDQuery operations etc. So I want the FDMemTable to accurately reflect the structure of the eventual end database table(s). Some (most) of these tables need a primary key, often consisting of several fields. I can find how to add indexes to FDMemTables { using TFDIndex *NewIndex = MyFDMemTable->Indexes->Add() } but I can't find a way to add a primary key to the FDMemTable. Question ; can anyone show me C++ code (or Delphi code is fine too) how to add a primary key to a newly created FDMemTable. Share this post Link to post
Anders Melander 1815 Posted November 24, 2020 There isn't really a "primary key" index on a TFDMemTable. You can have multiple indices on a table and one of them can be the "current index". http://docwiki.embarcadero.com/Libraries/Sydney/en/FireDAC.Comp.DataSet.TFDDataSet.Indexes I guess you can specify the soPrimary option on an index but I'm not sure if there's any practical difference from the soUnique option. http://docwiki.embarcadero.com/Libraries/Sydney/en/FireDAC.Comp.DataSet.TFDIndex.Options 1 Share this post Link to post
Uwe Raabe 2064 Posted November 24, 2020 1 hour ago, Anders Melander said: I guess you can specify the soPrimary option on an index but I'm not sure if there's any practical difference from the soUnique option. If the goal is to have a close match to the real case, it might be worth to create the query mock indices the same as the database ones. 1 Share this post Link to post
Roger Cigol 107 Posted November 24, 2020 Hi Anders, Your first post pointed me in the right direction. I am now getting the expected exception when I deliberately try to post a "duplicate" entry to the table. - great ! really appreciate this. My plan was to do a little more testing (and test writing) and then click on the "thanks" button. But your second post has got me intrigued. I don't know what a query mock indice is. The goal is to have a close match "as is reasonably practical". But since I don't understand/recognise your term I am not qualified to make the judgement as to it being "reasonably practical". If you do have a spare moment to explain it would be really appreciated and valuable to me.... Share this post Link to post
Roger Cigol 107 Posted November 24, 2020 Hi Uwe - Just spotted that you are different person to Anders. sorry to be so rude (and confusing?) with my last post ! 2 Share this post Link to post
Uwe Raabe 2064 Posted November 24, 2020 3 hours ago, Roger Cigol said: I don't know what a query mock indice is. The query mock is your TFDMemTable, that is mocking the original query for the unit tests. 1 Share this post Link to post
Roger Cigol 107 Posted November 25, 2020 Thank you. I did realise that my FDMemTable is acting as a mock. But what is the indice ? Share this post Link to post
Guest Posted November 25, 2020 Just a guess... no a question actually, isn't the little property value (soPrimary) not for making transfers of datasets in a tree-tier solution? The primary key is "not null" but needs to be sent/retrieved as "null" to get the correct (centralized) sequencer or trigger value, the property would indicate that special handling is needed to all tiers. That was previously my understanding. But if you have the sources you could simply grep it. And i think this is TDataset, not FireDAC. Pls correct me! Share this post Link to post
Anders Melander 1815 Posted November 25, 2020 4 hours ago, Roger Cigol said: But what is the indice ? What do you mean? Can you rephrase the question, please. Share this post Link to post
Anders Melander 1815 Posted November 25, 2020 (edited) 4 hours ago, Dany Marmur said: isn't the little property value (soPrimary) not for making transfers of datasets in a tree-tier solution? I believe you're thinking of the pfInKey value of TField.ProviderFlags. <rant>I know the help has improved but why the hell isn't there a link in the help from the ProviderFlags property to the type of the property. Don't they have computers that can do this stuff for them?</rant> Edited November 25, 2020 by Anders Melander venting Share this post Link to post
Bill Meyer 337 Posted November 25, 2020 9 minutes ago, Anders Melander said: <rant>I know the help has improved but why the hell isn't there a link in the help from the ProviderFlags property to the type of the property. Don't they have computers that can do this stuff for them?</rant> And other things, too.... Share this post Link to post
Uwe Raabe 2064 Posted November 25, 2020 5 hours ago, Roger Cigol said: But what is the indice indices = plural of index; also called indexes 1 Share this post Link to post