-1

I am working on Windows desktop application in Delphi using FireDAC driver and MSSQL database system. Currently, I am having a problem in understanding how multiple sessions (users) should work. Right now, I have three test users, and when I log in with any of them, every session has the same data and functionalities. I don't want that. I want that each user (each session) has different data and functionalities.

Note that this is different from distributed systems, where tasks are distributed by hosts in a network. I am not interested in distributed system. I have a desktop application.

Could someone explain how to achieve this (different users (sessions) = different data and functionalities)?

  • Your question is unclear. Do you want multiple users to share the same database but each have their own private data? What do you mean exactly by different functionalities? Perhaps some concrete examples will better explain. – Dan Guzman May 20 '18 at 12:15
  • This has nothing to do with Delphi nor FireDAC. FireDAC only establishes connection to a DBMS where it's upon your administration to distribute each user certain access rights (to access different resources). – Victoria May 20 '18 at 12:17
  • @Victoria, Exactly, I meant that (access rights). Could you elaborate on this with more details. I didn't mean that it has anything to do with FireDAC, I have just mensioned it. – user9818764 May 20 '18 at 12:31
  • @Dan Guzman, I want multiple users to share the same database but each have their own data. Functionalities are priviledges that some users can do, and others can't. – user9818764 May 20 '18 at 12:33
  • See [this question for multi-tenant database design alternatives](https://stackoverflow.com/questions/2213006/how-to-create-a-multi-tenant-database-with-shared-table-structures). As to functionality that varies by user, that is controlled by your application code or framework. You could store that meta-data in the database. That's what ASP.NET membership does with the SQL Server provider. – Dan Guzman May 20 '18 at 13:05
  • Well, I would suggest creating business layer if you mean your application serious. – Victoria May 20 '18 at 13:06
  • @Dan Guzman, Could you give a concrete short code snippet in Delphi that manages this (different users (sessions) = different data and functionalities)? – user9818764 May 20 '18 at 13:15
  • @Victoria , What is a business layer? – user9818764 May 20 '18 at 13:16
  • It's a layer between client application and database server (see [business logic layer](https://en.wikipedia.org/wiki/Business_logic#Business_logic_and_tiers/layers)). It handles sessions and access rights by itself. – Victoria May 20 '18 at 13:24
  • @user9818764, I haven't used Delphi for over 20 years but what you are asking is well beyond code snippets. – Dan Guzman May 20 '18 at 13:40
  • I'm afraid your comments make what you want very unclear. You say "but each have their own data" What exactly is it that you want, that: a) different users see and work with different tables from one another; b) that different users see different data row in the same table as one another; or c) a combination of a) and b)? – MartynA May 20 '18 at 18:09
  • @MartynA, I want b) – user9818764 May 20 '18 at 18:29

1 Answers1

0

You've indicated in a comment that what you want is for a number of users o be able to see different data rows in the same table or tables

That's actually quite quite straightforward: you just need to define, for each user (or user type), the criteria which determine which data rows they are supposed to be able to see, then write a Where clause which selects only those rows. It's generally a bad idea to hard-code users's identities in a database and what data they are permitted to see and what operations they are permitted to carry out on the data.

It's hard to give a concrete example without getting into details of what you are wanting to do, but the following simple example might help.

Suppose you have a table of Customers, and one user is suposed to deal with the USA, the second user deals with France and the third with the rest of the world.

In your app, you could have an enumerated type to represent this:

type
  TRegion = (rtUSA, rtFR, rtRoW);  // RoW = Rest of the World

Then you could write a function to generate the Where clause of a SQL Select statement like this:

function GetRegionWhereClause(const ARegion : TRegion) : String;
begin
  Result := ' Where ';
  case ARegion of
    rtUSA : Result := Result + ' Customer.Country = ''USA''';
    rtFR : Result := Result + ' Customer.Country = ''FR''';
    rtRoW : Result := Result + ' not Customer.Country in (''USA'', ''FR'')'
  end;  { case }
end;

You could then call GetRegionWhereClause when you generate the Sql to open the Customers table.

Similarly define for each user type what operations they are permitted to carry out on the data (Update, Insert, Delete). But implementing that would be more a question of selectively enabling and disable the gui functionality in your app to do the tasksin question.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • That's for what I would create a table of regions and assign users (or their roles) through a relational table. If you really wanted to make data logically separated, you could use horizontal partitioning (even though for this case it might be overkill). – Victoria May 21 '18 at 04:47