Jump to content
Roger Cigol

Primary Key on FDMemTable

Recommended Posts

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

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

  • Thanks 1

Share this post


Link to post
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.

  • Thanks 1

Share this post


Link to post

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

Hi Uwe - Just spotted that you are different person to Anders. sorry to be so rude (and confusing?) with my last post !

 

  • Haha 2

Share this post


Link to post
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.

  • Thanks 1

Share this post


Link to post

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
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 by Anders Melander
venting
  • Like 1

Share this post


Link to post
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
5 hours ago, Roger Cigol said:

But what is the indice

indices = plural of index; also called indexes

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×