Subject AW: [firebird-support] question table numbers in select
Author Olaf Kluge
Hello Set,

>> I would like to assign a element-group to an table. For example group
>> perhaps I can assign the table not by its name, rather with its table
>> ID? Maybe I can select the ID and. "select * from TABLEID where xxx"?
>
>Is there a possible way to select/insert records in a table where only
>the tablename is known - and without a statement? In my case the structure
>of some tables is the same, only the names are different. I can assign a
>tablename to an category and would like to update the corresponding table.
>
>For example:
>
>Members:
>ID Name Category
>1 Compressor1 1
>2 Compressor2 1
>3 Valve1 2
>
>Categories:
>ID Table
>1 TCompressor
>2 TValve
>
>TCompressors:
>ID STATE .
>1 .
>
>Now If the PLC send me a change of ID 1, I would like to look for the right

>table and update this. Select table from . . update TABLENAME set STATE = .
>
>How can I realize this without an statement?

>Sorry, Olaf, I still don't quite get your question, but I guess something
similar to the following might be what you want:

>EXECUTE BLOCK(ID INTEGER, STATE VARCHAR(55)
>AS
>DECLARE VARIABLE S VARCHAR(255);
>BEGIN
>SELECT C.TABLE
>FROM CATEGORIES C
>JOIN MEMBERS M ON C.CATEGORY = M.CATEGORY
>WHERE M.ID = :ID
>INTO :S;
>S = 'UPDATE ' +S+ ' SET STATE = '+STATE+' WHERE ID = '+ID;
>EXECUTE STATEMENT S;
>END;

>Now, I've assumed that TCompressor and TCompressors are the same in your
description, and I'm very uncertain whether you want to update all records
of TCompressors or only the one with the same ID as in Members or something
completely different that you simply haven't >described. I generally don't
use EXECUTE STATEMENT myself, and chose to not use parameters within S since
I simply do not know how to use them (albeit with STATE being a VARCHAR
parameter, this does make the statement vulnerable to SQL injection
attacks). >Moreover, it is likely that there are some errors in my suggested
EXECUTE BLOCK statement above and you may want to change EXECUTE BLOCK to a
stored procedure or something similar.

>HTH,
<Set

Each Member in TMembers has an unigue ID. The other Tables (TCategory,
TValve and so on) has a 1:1 relationship to TMembers, only the matching IDs
(Compressors in TCompressor and so on) be entered. Each ID should have a
category, this points to a table like Tcompressor for Compressors.

Now I get from the PLC a status change (only the id an the new state). Now I
get the tablename from tcategory and I would like to update the record in
the right table. Your suggestion is a viable way. It does not seem to be
possible without a statement?

Thank you.



PS: tcompressor ist the same as tcompressors. the names are fictitious





[Non-text portions of this message have been removed]