NationalSecurityAgency/ghidra · error · SQLException

Insert failed for vector table

Error message

Insert failed for vector table

What it means

Thrown as an SQLException by H2VectorTable.insert() when PreparedStatement.executeUpdate() returns a row count other than 1 after an INSERT into h2_vectable. A correct single-row insert must return exactly 1; any other value indicates a database-level anomaly with the insert operation.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2VectorTable.java:101

			throw new IllegalArgumentException(
				"Insert method for H2VectorTable accepts two arguments: count(int) and LSHVector");
		}

		int count = (int) arguments[0];
		LSHVector vec = (LSHVector) arguments[1];

		PreparedStatement s = insert_stmt.prepareIfNeeded(() -> db.prepareStatement(
			"INSERT INTO " + TABLE_NAME + " (count,vec_hash,vec) VALUES(?,?,?)",
			Statement.RETURN_GENERATED_KEYS));

		StringBuilder vecBuf = new StringBuilder();
		vec.saveBase64(vecBuf, Base64Lite.encode);

		s.setInt(1, count);
		s.setLong(2, vec.calcUniqueHash());
		s.setString(3, vecBuf.toString());
		if (s.executeUpdate() != 1) {
			throw new SQLException("Insert failed for vector table");
		}
		long id;
		try (ResultSet rs = s.getGeneratedKeys()) {
			if (!rs.next()) {
				throw new SQLException("Unable to obtain vector id for insert");
			}
			id = rs.getLong(1);
		}
		vectorStore.update(
			new VectorStoreEntry(id, vec, count, vectorFactory.getSelfSignificance(vec)));
		return id;
	}

	/**
	 * Read all vectors from table and generate an ID-based vector map
	 * @return vector map (ID->VectorStoreEntry)
	 * @throws SQLException if error occurs
	 */

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Check the H2 database file integrity — run an H2 recovery or consistency check.
  2. Verify the H2 JDBC driver version is compatible with the Ghidra BSim module.
  3. Inspect the h2_vectable DDL for any unexpected triggers or constraints.
  4. If corruption is suspected, rebuild the BSim database from source programs.

Example fix

// before
if (s.executeUpdate() != 1) {
    throw new SQLException("Insert failed for vector table");
}

// after (diagnostic: capture actual row count)
int rc = s.executeUpdate();
if (rc != 1) {
    throw new SQLException(
        "Insert failed for vector table: executeUpdate returned " + rc);
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    long id = vectorTable.insert(count, vec);
} catch (SQLException e) {
    if (e.getMessage().equals("Insert failed for vector table")) {
        // This indicates an H2-level anomaly; check database integrity
        Msg.error(this, "Vector insert anomaly; database may be corrupt");
        checkH2Integrity(db);
    }
    throw e;
}

Prevention

When it happens

Trigger: Occurs when s.executeUpdate() for the INSERT statement returns 0 or a value greater than 1. This is extremely rare with a standard INSERT and typically indicates an H2 driver bug, a trigger on the table that alters affected row counts, or a corrupted database state that causes the insert to behave unexpectedly.

Common situations: H2 database file corruption. H2 JDBC driver version mismatch or bug. A database trigger (if any were manually added) interfering with the row count. Concurrent schema modification while inserting.

Related errors


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