#1 2022-07-23 07:30:05

bigheart
Member
Registered: 2014-08-01
Posts: 45

How to access specific table in the db file

Hello,

The sqlite3 DB file is created as below:

  TTest1 = class(TOrm)
       ...
  end;

  TTest2 = class(TOrm)
       ...
  end;

   ...

function CreateTestModel: TOrmModel;
begin
  result := TOrmModel.Create([TTest1, TTest2]);
end;
 

If i just know one table "TTest1", and have no information about "TTest2",
how can i access to the "TTest1" from the DB file?

Is there any function to access using table name in the DB file?

Please give me some advise.

Thanks in advance

Offline

#2 2022-07-23 09:32:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,227
Website

Re: How to access specific table in the db file

What do you mean?
Do you mean that TTest2 has no property defined?

I don't understand what you want to do.
It is not possible to access something the ORM don't know about.
What you can always do is running a manual SQL statement over the database.

Or if you want to change the table name at startup for TTest2, then you can define TTest2 as external, and specify the table name in OrmMapExternal() just before CreateMissingTables().

Offline

#3 2022-07-23 23:22:12

bigheart
Member
Registered: 2014-08-01
Posts: 45

Re: How to access specific table in the db file

Hi, ab.

The TTest1 is defined in all of my sqlite files commonly.
Also, TTest2, TTest3 etc. is defined in each sqlite files with TTest1.

In this case, i just want to make a simple function to access only TTest1 over the db files without caring about other ORM like as TTest2, TTest3....

function SimpleAccessTest1(ADBFileName: string);
begin
   ...
   UpdateTest1(ADBFileName);
end;

Offline

#4 2022-07-24 06:51:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,227
Website

Re: How to access specific table in the db file

So use OrmMapExternal() for each TTest2, TTest3, etc... to access the 'test1' table.

But I don't see any use case for it....
You can do it at object pascal level by defining

type TTest2 = TTest1; 
    TTest3 = TTest1; ...

Offline

Board footer

Powered by FluxBB