[odb-users] Specific index creation for a container table column

Marcos Gonzalez Menendez marcos.glez at gmail.com
Fri Aug 22 13:00:24 EDT 2014


Hi,

I'm struggling with the way of creating an index for a particular column.
The table is not a "db object" itself, because it's rather the table that
is created by ODB when an container is used:

Here is my example:

    #pragma db object
    class B
    {
    public:
        #pragma db id
        int id_;

        int prop_;
    };

    #pragma db object
    class A
    {
    public:
        #pragma db auto id
        odbid id_;
        QList<QSharedPointer<B>> ref_list_;
        #pragma db index member(ref_list_.id)
    };

As I'm using sqlite, the ddl produced is like this:

CREATE TABLE "A" (
  "id" INTEGER NULL PRIMARY KEY AUTOINCREMENT);

CREATE TABLE "B" (
  "id" INTEGER NULL PRIMARY KEY,
  "prop" INTEGER NULL);

CREATE TABLE "A_ref_list" (
  "object_id" INTEGER NULL,
  "index" INTEGER NULL,
  "value" INTEGER NULL,
  CONSTRAINT "object_id_fk"
    FOREIGN KEY ("object_id")
    REFERENCES "A" ("id")
    ON DELETE CASCADE,
  CONSTRAINT "value_fk"
    FOREIGN KEY ("value")
    REFERENCES "B" ("id")
    DEFERRABLE INITIALLY DEFERRED);

CREATE INDEX "A_ref_list_object_id_i"
  ON "A_ref_list" ("object_id");

CREATE INDEX "A_ref_list_index_i"
  ON "A_ref_list" ("index");

Now I would like to have an index for A_ref_list.value but the sentece:

#pragma db index member(ref_list_.id)

does not seem to be the right one. In fact is an index for the FOREIGN KEY

Is it possible to do this with ODB?

Thanks for any help you can provide
-- 
Marcos González Menéndez


More information about the odb-users mailing list