Home » Community » Newbie corner » Adding a records through a SqlArray with duplicated columns
|Adding a records through a SqlArray with duplicated columns [message #50220]
||Tue, 28 August 2018 10:16
Registered: August 2015
I'm developing an application that uses a PostGresql DB. In the DB there are (among others) one table that contains details of manufacturing machines and another that contains producible items. I have just introduced a third table, that contains what items a machine can produce. Below a snippet from my .sch file regarding those tables.
STRING (IDMACHINE, 5) PRIMARY_KEY
STRING_ (NAME, 20)
STRING (IDITEM, 2) PRIMARY_KEY
STRING_ (DESCRIPTION, 20)
SERIAL (ID) PRIMARY_KEY
STRING (IDMACHINE, 5) REFERENCES(MACHINES.IDMACHINE)
STRING (IDITEM, 2) REFERENCES(ITEMS.IDITEM)
I show the third table (the one with the items each machine can produce) in a SqlArray. To help user to better understand the data, I show also the name of the machine and the description of the item. To show them in a SqlArray, I defined two converters. Below, the code for the first one, the second one works in the same way.
struct ConvMachine : Convert
Value Format(const Value &q) const
sql * Select(NAME).From(MACHINES).Where(IDMACHINE == q);
name = sql[NAME];
descrizione = "";
return q.IsNull() ? Null : name;
The SqlArray that manages the tables is defined as below.
EditString item, machine;
tbl.AddColumn(IDMACHINE, t_("Machine"), 40).SetConvert(Single<ConvMachine>());
tbl.AddColumn(IDITEM, t_("Item"), 100).SetConvert(Single<ConvItem>());
The data are showed correctly, the problem is when I try to add a new record.
The sql code produced is:
insert into ITEMS_ALLOWED(IDMACHINE, IDMACHINE, IDITEM, IDITEM) values (NULL, NULL, NULL, NULL)
That triggers the following error:
ERROR ERROR: column "idmachine" specified more than once
I think that is a really common situation, how can I fix this?
Current Time: Tue Jan 19 09:30:56 CET 2021
Total time taken to generate the page: 0.01331 seconds