NationalSecurityAgency/ghidra · error · SQLException

Did not get desctable sequence number after insertion

Error message

Did not get desctable sequence number after insertion

What it means

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.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/tables/DescriptionTable.java:287

		FunctionDescription func = (FunctionDescription) arguments[0];
		SignatureRecord srec = func.getSignatureRecord();
		long vecid = 0;
		if (srec != null) {
			vecid = srec.getVectorId();
		}

		PreparedStatement s = insertStatement.prepareIfNeeded(
			() -> db.prepareStatement(INSERT_STMT, Statement.RETURN_GENERATED_KEYS));
		s.setString(1, func.getFunctionName());
		s.setInt(2, (int) func.getExecutableRecord().getRowId().getLong());
		s.setLong(3, vecid);
		s.setInt(4, func.getFlags());
		s.setLong(5, func.getAddress());
		s.executeUpdate();

		try (ResultSet rs = s.getGeneratedKeys()) {
			if (!rs.next()) {
				throw new SQLException("Did not get desctable sequence number after insertion");
			}
			return rs.getLong(1);
		}
	}

	/**
	 * Return function DescriptionRow objects that have a matching vector id
	 * 
	 * @param vectorId is the row id of the feature vector we want to match
	 * @param maxRows is the maximum number of function rows to return
	 * @return list of resulting DescriptionRows
	 * @throws SQLException if there is a problem creating or executing the query
	 */
	public List<DescriptionRow> queryVectorIdMatch(long vectorId, int maxRows)
		throws SQLException {

		StringBuffer buf = new StringBuffer();
		buf.append(SELECT_BY_SIGNATURE_ID_STMT).append(vectorId);

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Ensure the underlying database and JDBC driver support generated keys for the desctable insert (the id column must be auto-increment/serial).
  2. Update the JDBC driver to a version known to return generated keys for your database.
  3. Verify the desctable schema has an auto-generated primary key column.
  4. If generated keys are unavailable, switch the insert to use an explicit sequence/CURRENT_VALUE retrieval as a fallback.
Defensive patterns

Strategy: validation

Validate before calling

// Before inserts, verify the driver/database supports generated keys.
DatabaseMetaData md = db.getConnection().getMetaData();
if (!md.supportsGetGeneratedKeys()) {
    throw new IllegalStateException("Driver does not support generated keys; configure sequence fallback");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/0d84ab733682553d. Report an issue: GitHub.