-1

I have a void object which I declared, but want to get its class name is it possible??

item: detachable DB_ENTITY

db_connection.base_selection.query("SELECT * FROM " + item.generating_type.out)

Creating it is not what I want...

Pipo
  • 4,653
  • 38
  • 47

2 Answers2

1

A type object (i.e. an object like the one returned by generating_type for an existing object) can be obtained using curly braces enclosing the type name:

    {MY_TYPE}

In your example it would be {attached like item} if item is a feature (of type detachable DB_ENTITY to allow for a value Void), or {DB_ENTITY} if item is a local variable, so that the whole expression would read in one of the following ways:

  db_connection.base_selection.query("SELECT * FROM " + ({attached like item}).out)
  db_connection.base_selection.query("SELECT * FROM " + ({DB_ENTITY}).out)

In the second case, the corresponding string would be equivalent to "SELECT * FROM DB_ENTITY".

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • Thx, your first answer was the one, could you explain why you added attached to 'like item'? – Pipo Sep 26 '18 at 14:12
  • @PhilippeGachoud If the feature `item` is of type `DB_ENTITY`, this type is attached, and `like item` is attached as well. However, if you want to allow `item` to be `Void`, you need to declare it as `detachable DB_ENTITY`. In that case `like item` is detachable. To be attached, it should be written as `attached like item`. – Alexander Kogtenkov Sep 26 '18 at 16:07
  • I'll read more about the topic... https://www.eiffel.org/doc/eiffel/Void-safety-_Background%2C_definition%2C_and_tools – Pipo Sep 26 '18 at 23:29
  • Actually, ({attached like item}).out gave me `!COMPANY` not `COMPANY` why that? because its a created object isn't it?? so got to find another workaround – Pipo Sep 28 '18 at 17:43
  • @Pipo I guess `like item` without any attachment mark will do. – Alexander Kogtenkov Sep 29 '18 at 15:16
0

I would use

item_type_anchor: detachable DB_ENTITY
          -- `item_type_anchor' for Current.

and then

db_connection.base_selection.query ("SELECT * FROM " + ({like item_type_anchor}).generating_type.out)

This means that the feature `item_type_anchor' clearly communicates that it does not expect to be attached, but is there as a type-anchor reference only. Used with the static reference Alex pointed out, the story is now clear and concise. :-)

Larry Rix
  • 11
  • 2
  • The expression `({like item_type_anchor}).generating_type` computes a type of a type object, i.e. `TYPE [TYPE [DB_ENTITY]]`. And the subsequent call to `out` will yield a string `"TYPE [DB_ENTITY]"` that is not what is needed. – Alexander Kogtenkov Sep 26 '18 at 02:41