Database insert Bug if table is modified

I recocnized (and analyzed the error message in the error logs) that inserting Data into a database table is broken, once a column is added. instead of “insert into exampletable values(‘section’, ‘variable’, ‘value’)” ist should be “insert into exampletable(section,variable, value) values (‘section’, ‘variable’, ‘value’)” .

I hope this helps.
Keep up the good work <3

You are saying that you are adding an additional column to the tables that is not built into the schema as created by PhantomBot? I would agree that it could cause an issue as we expect three items to be inserted:

                try (PreparedStatement statement = connection.prepareStatement("INSERT INTO phantombot_" + fName + " values(?, ?, ?);")) {
                    statement.setQueryTimeout(10);
                    statement.setString(1, section);
                    statement.setString(2, key);
                    statement.setString(3, value);
                    statement.executeUpdate();

Which maps the parameters to a specific column in the table. If you change the schema, we cannot guarantee that PhantomBot works properly.

with all tables containing of three columns (section, variable and value) altering the code to the following would fit the current needs plus allows adding custom colums (as the last-edited-datetime filled by defaultvalue/trigger) without negative sideeffects (if derfault value is assigned or column is nullable).

I added a custom column for reporting of the last 10 edited commands in an own web-based mod-tool.

Thank you for your immediate Response :slight_smile:

 try (PreparedStatement statement = connection.prepareStatement("INSERT INTO phantombot_" + fName + "(section,variable,value) values(?, ?, ?);")) {
                    statement.setQueryTimeout(10);
                    statement.setString(1, section);
                    statement.setString(2, key);
                    statement.setString(3, value);
                    statement.executeUpdate();

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.