Inserting a structure

User 478d103dc9

07-10-2015 18:01:06

Hello,


  I'm trying to insert a structure and update an additional(custom) column on the fly, but getting below error:


Parameter #26 has not been set.


 


Here is my code:



Dim con As ConnectionHandler = GetConnectionHandler()


Dim uh As New
UpdateHandler(con, operationType, strStructureTableName, "AccNo")


uh.setStructure(Encoding.[Default].GetBytes(Me.hfMol.Value))


If operationType
= UpdateHandler.UPDATE Then


uh.setID(intID)


Else


uh.setValueForAdditionalColumn(1, 6365)


End If


 uh.execute()



Please advise.


Thank you

ChemAxon 9991eff751

08-10-2015 13:33:23

hello,


 


which jchem version are you using, i tried to reproduce your problem on the java side; and it worked without any problems.


note: it is desired to not set the accno when you are doing an update? because you have specified "AccNo" as an additional field for the updatehandler; the current implementation will leave the accno field alone, but it might be possible that for an earlier version the value is mandatory; would you try moving the setValueForAdditionalColumn outside of the if statement?


 


regards.kirk

User 478d103dc9

08-10-2015 14:58:43










kirk wrote:

hello,


 


which jchem version are you using, i tried to reproduce your problem on the java side; and it worked without any problems.


note: it is desired to not set the accno when you are doing an update? because you have specified "AccNo" as an additional field for the updatehandler; the current implementation will leave the accno field alone, but it might be possible that for an earlier version the value is mandatory; would you try moving the setValueForAdditionalColumn outside of the if statement?


 


regards.kirk



Hi Kirk,


I'm using version 6.2.2.


I got the same error when moved the uh.setValueForAdditionalColumn(1, 6365) outside the "If" statement.


The AccNo is custom filed that been introduced into structure table, not sure though whether it can be updated "on the fly" utilizing setValueForAdditionalColumn  method. 


I can always read the inserted id(cd_id) value and do another DB call to update the AccNo filed, but I would like to  avoid an additional DB call.


Thanks,


Igor

ChemAxon 9991eff751

09-10-2015 09:04:19

hi,


i have tried to reproduce your problem on 6.2.2, but i was unsuccessfull...i paste the java test code here, do you think it models your problem? what should we change to model more precisely your environment/situation


what kind of database are you using behind jchem?


what is the type of the column AccNo?


regards.kirk


 


 


import static org.junit.Assert.assertEquals;


 


import java.io.File;


import java.io.FileInputStream;


import java.io.IOException;


import java.sql.PreparedStatement;


import java.sql.ResultSet;


import java.sql.SQLException;


import java.util.Properties;


 


import org.junit.AfterClass;


import org.junit.Assert;


import org.junit.BeforeClass;


import org.junit.Test;


 


import chemaxon.jchem.db.DatabaseProperties;


import chemaxon.jchem.db.StructureTableOptions;


import chemaxon.jchem.db.UpdateHandler;


import chemaxon.util.ConnectionHandler;


import chemaxon.util.DotfileUtil;


 


public class UHAdditionColumnsProblem {


 


    private static final String TABLE_NAME = "test_adf";


    private static ConnectionHandler ch;


 


    @BeforeClass


    public static void beforeClass() throws SQLException, Exception {


        try {


            ch = new ConnectionHandler();


            File f = DotfileUtil.getDotFile(".jchem");


            Properties p = new Properties();


            p.load(new FileInputStream(f));


            ch.loadValuesFromProperties(p);


            ch.connectToDatabase();


            if (!DatabaseProperties.propertyTableExists(ch)) {


                DatabaseProperties.createPropertyTable(ch);


            }


 


        } catch (IOException e) {


            throw new RuntimeException(e);


        }


    }


 


    @AfterClass


    public static void afterClass() {


        try {


            ch.close();


        } catch (SQLException e) {


            throw new RuntimeException(e);


        }


    }


 


    @Test


    public void testWithAdditionalColumn() throws Exception{


 


        if (UpdateHandler.isStructureTable(ch, TABLE_NAME)) {


            UpdateHandler.dropStructureTable(ch, TABLE_NAME);


        }


        String createTableTail = ", AccNo int";


 


        StructureTableOptions tableOptions = new StructureTableOptions(TABLE_NAME);


        tableOptions.setExtraColumnDefinitions(createTableTail);


 


        System.out.println(ch);


        UpdateHandler.createStructureTable(ch, tableOptions);


 


        UpdateHandler uh = new UpdateHandler(ch, UpdateHandler.INSERT, TABLE_NAME, "AccNo");


        uh.setStructure("C1CCC1");


        int shouldBe = 0;


        if (shouldBe > 0) {


            uh.setValueForAdditionalColumn(1, shouldBe);


        }


 


        uh.execute();


        PreparedStatement pstmt =


                ch.getConnection().prepareStatement(


                        "select cd_structure,AccNo from " + tableOptions.getName() + "");


        try {


            ResultSet rs = pstmt.executeQuery();


            try {


                Assert.assertTrue(rs.next());


                System.out.println(rs.getString(1));


                System.out.println(rs.getString(2));


                if (shouldBe > 0) {


                    assertEquals(shouldBe, rs.getInt(2));


                } else {


                    assertEquals(0, rs.getInt(2));


                }


                Assert.assertFalse(rs.next());


            } finally {


                rs.close();


            }


        } finally {


            pstmt.close();


        }


    }


}

User 478d103dc9

09-10-2015 14:59:22










kirk wrote:

hi,


i have tried to reproduce your problem on 6.2.2, but i was unsuccessfull...i paste the java test code here, do you think it models your problem? what should we change to model more precisely your environment/situation


what kind of database are you using behind jchem?


what is the type of the column AccNo?


regards.kirk


 


 


import static org.junit.Assert.assertEquals;


 


import java.io.File;


import java.io.FileInputStream;


import java.io.IOException;


import java.sql.PreparedStatement;


import java.sql.ResultSet;


import java.sql.SQLException;


import java.util.Properties;


 


import org.junit.AfterClass;


import org.junit.Assert;


import org.junit.BeforeClass;


import org.junit.Test;


 


import chemaxon.jchem.db.DatabaseProperties;


import chemaxon.jchem.db.StructureTableOptions;


import chemaxon.jchem.db.UpdateHandler;


import chemaxon.util.ConnectionHandler;


import chemaxon.util.DotfileUtil;


 


public class UHAdditionColumnsProblem {


 


    private static final String TABLE_NAME = "test_adf";


    private static ConnectionHandler ch;


 


    @BeforeClass


    public static void beforeClass() throws SQLException, Exception {


        try {


            ch = new ConnectionHandler();


            File f = DotfileUtil.getDotFile(".jchem");


            Properties p = new Properties();


            p.load(new FileInputStream(f));


            ch.loadValuesFromProperties(p);


            ch.connectToDatabase();


            if (!DatabaseProperties.propertyTableExists(ch)) {


                DatabaseProperties.createPropertyTable(ch);


            }


 


        } catch (IOException e) {


            throw new RuntimeException(e);


        }


    }


 


    @AfterClass


    public static void afterClass() {


        try {


            ch.close();


        } catch (SQLException e) {


            throw new RuntimeException(e);


        }


    }


 


    @Test


    public void testWithAdditionalColumn() throws Exception{


 


        if (UpdateHandler.isStructureTable(ch, TABLE_NAME)) {


            UpdateHandler.dropStructureTable(ch, TABLE_NAME);


        }


        String createTableTail = ", AccNo int";


 


        StructureTableOptions tableOptions = new StructureTableOptions(TABLE_NAME);


        tableOptions.setExtraColumnDefinitions(createTableTail);


 


        System.out.println(ch);


        UpdateHandler.createStructureTable(ch, tableOptions);


 


        UpdateHandler uh = new UpdateHandler(ch, UpdateHandler.INSERT, TABLE_NAME, "AccNo");


        uh.setStructure("C1CCC1");


        int shouldBe = 0;


        if (shouldBe > 0) {


            uh.setValueForAdditionalColumn(1, shouldBe);


        }


 


        uh.execute();


        PreparedStatement pstmt =


                ch.getConnection().prepareStatement(


                        "select cd_structure,AccNo from " + tableOptions.getName() + "");


        try {


            ResultSet rs = pstmt.executeQuery();


            try {


                Assert.assertTrue(rs.next());


                System.out.println(rs.getString(1));


                System.out.println(rs.getString(2));


                if (shouldBe > 0) {


                    assertEquals(shouldBe, rs.getInt(2));


                } else {


                    assertEquals(0, rs.getInt(2));


                }


                Assert.assertFalse(rs.next());


            } finally {


                rs.close();


            }


        } finally {


            pstmt.close();


        }


    }


}



Hi Kirk,


The database is SQL Server 2008 R2.


The datatype of AccNo column is integer. Like I mentioned it's a custom column, the column index is 28.(not 26 as error message says). Index # 26 assigned to one of the default column: cd_fp15.


Also, do you know whether it is matter or not, the structure table was created using JChemManager version 6.2.0, while .NET API i'm using has slightly newer version 6.2.2 ?


Thanks,


Igor


An update...


When I "wrapped" the integer value with double quotes it worked. Please share your thoughts.


uh.setValueForAdditionalColumn(1, "6365")



ChemAxon 9991eff751

13-10-2015 09:33:10

Hello,


Sorry for the late answer but we are trying to reproduce your problem more precisely.


The info about using quoting was very helpful, i can confirm that 6.2.2 on the java side doesnt emit the problem with my testcase.


regards.kirk