claeis / ili2db

interlis import/export to relational databases
30 stars 30 forks source link

Enum values are inserted twice when generating a script #426

Closed andykiss closed 3 years ago

andykiss commented 3 years ago

INSERT statements are doubled when a create script is created, e.g.:

INSERT INTO forderungglaeubiger_rolle (seq,iliCode,itfCode,dispName,inactive,description,thisClass,baseClass) VALUES (NULL,'Grundpfand',0,'Grundpfand','0',NULL,'eGRISDM11.Hauptbuch.ForderungGlaeubiger.Rolle',NULL);
INSERT INTO forderungglaeubiger_rolle (seq,iliCode,itfCode,dispName,inactive,description,thisClass,baseClass) VALUES (NULL,'Faustpfand',1,'Faustpfand','0','=Fahrnispfand','eGRISDM11.Hauptbuch.ForderungGlaeubiger.Rolle',NULL);
INSERT INTO forderungglaeubiger_rolle (seq,iliCode,itfCode,dispName,inactive,description,thisClass,baseClass) VALUES (NULL,'Nutzniesser',2,'Nutzniesser','0',NULL,'eGRISDM11.Hauptbuch.ForderungGlaeubiger.Rolle',NULL);
INSERT INTO forderungglaeubiger_rolle (seq,iliCode,itfCode,dispName,inactive,description,thisClass,baseClass) VALUES (NULL,'Grundpfand',0,'Grundpfand','0',NULL,'eGRISDM11.Hauptbuch.ForderungGlaeubiger.Rolle',NULL);
INSERT INTO forderungglaeubiger_rolle (seq,iliCode,itfCode,dispName,inactive,description,thisClass,baseClass) VALUES (NULL,'Faustpfand',1,'Faustpfand','0','=Fahrnispfand','eGRISDM11.Hauptbuch.ForderungGlaeubiger.Rolle',NULL);
INSERT INTO forderungglaeubiger_rolle (seq,iliCode,itfCode,dispName,inactive,description,thisClass,baseClass) VALUES (NULL,'Nutzniesser',2,'Nutzniesser','0',NULL,'eGRISDM11.Hauptbuch.ForderungGlaeubiger.Rolle',NULL);

This seems to come from #124 and the problem is in TransferFromIli.java as method "updateEnumEntries" creates the statement into the script but this method is called twice from each code path, e.g. in method "updateMultiEnumTableWithId"

                if(conn!=null) {
...
                        try{
                            updateEnumEntries(gen,exstEntries,thisSqlName.getQName(),ps, type, thisClass, baseClass);**
                        }catch(java.sql.SQLException ex){

and later

                if(gen!=null){
                    try{
                        HashSet<String> exstEntries=new HashSet<String>();
                        updateEnumEntries(gen,exstEntries,thisSqlName.getQName(),null, type, thisClass, baseClass);**
                    }catch(java.sql.SQLException ex){       
                        throw new Ili2dbException("failed to create inserts into enum-table "+thisSqlName,ex);
                    }
edigonzales commented 3 years ago

Not for me:


java -jar ili2pg-4.6.0.jar --nameByTopic --dbschema fubar --createEnumTabs --models eGRISDM11 --createscript fubar.sql

What is your command?

andykiss commented 3 years ago

I've used this command today and found out that it happend with 4.4.2, 4.4.5 and 4.4.7 too:

java -jar ili2mssql-4.6.0.jar --schemaimport --dbhost myhost --dbdatabase egrisdm202110-sm1 --dbusr dbusr --dbpwd dbpasswd --createEnumTabsWithId --beautifyEnumDispName --createStdCols --t_id_Name Id --createFk --createFkIdx --createUnique --createTidCol --createBasketCol --createMetaInfo --createscript createSchema.sql --dropscript dropSchema.sql --smart1Inheritance  egrisdm11hist20111103.ili

Regards, Andreas

edigonzales commented 3 years ago

Yes, same here. --createscript combined with --schemaimport seems to be the problem.