{"record":{"id":"0d84ab733682553d","repo":"NationalSecurityAgency/ghidra","slug":"did-not-get-desctable-sequence-number-after-insert","errorCode":null,"errorMessage":"Did not get desctable sequence number after insertion","messagePattern":"Did not get desctable sequence number after insertion","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/tables/DescriptionTable.java","lineNumber":287,"sourceCode":"\t\tFunctionDescription func = (FunctionDescription) arguments[0];\n\t\tSignatureRecord srec = func.getSignatureRecord();\n\t\tlong vecid = 0;\n\t\tif (srec != null) {\n\t\t\tvecid = srec.getVectorId();\n\t\t}\n\n\t\tPreparedStatement s = insertStatement.prepareIfNeeded(\n\t\t\t() -> db.prepareStatement(INSERT_STMT, Statement.RETURN_GENERATED_KEYS));\n\t\ts.setString(1, func.getFunctionName());\n\t\ts.setInt(2, (int) func.getExecutableRecord().getRowId().getLong());\n\t\ts.setLong(3, vecid);\n\t\ts.setInt(4, func.getFlags());\n\t\ts.setLong(5, func.getAddress());\n\t\ts.executeUpdate();\n\n\t\ttry (ResultSet rs = s.getGeneratedKeys()) {\n\t\t\tif (!rs.next()) {\n\t\t\t\tthrow new SQLException(\"Did not get desctable sequence number after insertion\");\n\t\t\t}\n\t\t\treturn rs.getLong(1);\n\t\t}\n\t}\n\n\t/**\n\t * Return function DescriptionRow objects that have a matching vector id\n\t * \n\t * @param vectorId is the row id of the feature vector we want to match\n\t * @param maxRows is the maximum number of function rows to return\n\t * @return list of resulting DescriptionRows\n\t * @throws SQLException if there is a problem creating or executing the query\n\t */\n\tpublic List<DescriptionRow> queryVectorIdMatch(long vectorId, int maxRows)\n\t\tthrows SQLException {\n\n\t\tStringBuffer buf = new StringBuffer();\n\t\tbuf.append(SELECT_BY_SIGNATURE_ID_STMT).append(vectorId);","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/tables/DescriptionTable.java#L269-L305","documentation":"Thrown by DescriptionTable after inserting a new desctable row when Statement.getGeneratedKeys() returns an empty result set (rs.next() is false). The JDBC driver did not hand back an auto-generated sequence key for the insert, which the code needs to assign the new function's row id. This is typically a driver/database configuration problem with generated-key retrieval.","triggerScenarios":"Inserting a function description via the INSERT_STMT path (prepared with RETURN_GENERATED_KEYS) on a database/driver that does not support generated keys or where the table lacks an auto-increment/serial column. Also with certain PostgreSQL versions or H2 modes, or when the connection's autoGeneratedKeys flag is ignored. The insert succeeded but key retrieval failed.","commonSituations":"Using a JDBC driver or database mode that does not implement RETURN_GENERATED_KEYS properly (e.g., some H2 compatibility modes, older MySQL connectors, or a BSim custom database wrapper). The desctable was created without a SERIAL/autoincrement id column. Driver version mismatch.","solutions":["Ensure the underlying database and JDBC driver support generated keys for the desctable insert (the id column must be auto-increment/serial).","Update the JDBC driver to a version known to return generated keys for your database.","Verify the desctable schema has an auto-generated primary key column.","If generated keys are unavailable, switch the insert to use an explicit sequence/CURRENT_VALUE retrieval as a fallback."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before inserts, verify the driver/database supports generated keys.\nDatabaseMetaData md = db.getConnection().getMetaData();\nif (!md.supportsGetGeneratedKeys()) {\n    throw new IllegalStateException(\"Driver does not support generated keys; configure sequence fallback\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a JDBC driver and database mode that support RETURN_GENERATED_KEYS.","Ensure table id columns are auto-increment/serial.","Pin driver versions known to work with BSim."],"tags":["bsim","database","insert","generated-keys","jdbc","sql-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}