User 08026ff1f0
02-12-2005 20:49:55
Hi,
I wanted to know whether we can implement a naming scheme for cdid instead of just having it autoincremented. for eg. the cdid for the first compound should be table001 ,second should be table002 etc (where table is the table name). In this way each compound will be uniquely identified among the compounds in other tables. Where would I have to modify in order for it to implement this scheme? Thanks.
Bhargav
User 08026ff1f0
02-12-2005 20:54:09
Is it atleast possible to implement the above naming scheme when exporting it into a file?
I mean that the tables will have the cd_id in autoincremented format but when we export it to a file we will add the name of the table to it , so the field for cd_id in the exported file reads
tablename001, tablename002 etc.
Thanks
bhargav
ChemAxon 9c0afc9aaf
05-12-2005 10:55:23
Hi,
The cd_id column is numeric, so it can only store numbers.
(The range is between 1 and Integer.MAXVALUE).
It is certainly possible to create identifiers during the export, however it needs a relatively low-level usage of our API.
I can give further advice on that if needed, but until then here is a simpler solution (the examples assume that you use Oracle):
1. Add a text column to store the ID to your table:
Code: |
ALTER TABLE SCOTT.MYTABLE ADD ("ID" VARCHAR2(100)); |
2. Use a trigger to automatically to fill the ID column with the appropriate value on insert.
A BEFORE trigger is needed for this that is executed for each row.
Currently there is a BEFORE trigger for JChem tables (<table_name>_TR). This trigger affects the cd_id value, so it's best to modify this trigger. Simply insert the following line at the end of the "IF INSERTING" block:
Code: |
...
END IF;
:NEW.id := 'SCOTT.MYTABLE_' || :NEW.CD.ID; /*the new line*/
END IF;
IF UPDATING THEN
.... |
Please note that I have also included the schema into the identifier, since in an other schema you may have the same table name.
3. If there were rows in the table before the trigger modification, you should also update the values for pre-existing rows:
Code: |
UPDATE SCOTT.MYTABLE SET ID='SCOTT.MYTABLE_' || CD_ID WHERE ID IS NULL; |
Now you can use and export this field as any other data field.
Best regards,
Szilard
User 08026ff1f0
05-12-2005 22:10:22
Hi,
I assume that the TRIGGER, MYTABLE_TR is created when the table MYTABLE is being created. In order to add an extra column to the table, we are modifiying the trigger manually for each table after it is created. Is there any way that the statements
...
END IF;
:NEW.id := 'SCOTT.MYTABLE_' || :NEW.CD.ID; /*the new line*/
END IF;
IF UPDATING THEN
....
can be incorporated/added directly into the trigger MYTABLE_TR when it is created instead of manually changing it afterwards? Because every day we have around 10 -15 tables being created and it is not possible to add the lines to the trigger for each table manually.
Bhargav