{"record":{"id":"416f19027a2d2985","repo":"NationalSecurityAgency/ghidra","slug":"insert-failed-for-vector-table","errorCode":null,"errorMessage":"Insert failed for vector table","messagePattern":"Insert failed for vector table","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2VectorTable.java","lineNumber":101,"sourceCode":"\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Insert method for H2VectorTable accepts two arguments: count(int) and LSHVector\");\n\t\t}\n\n\t\tint count = (int) arguments[0];\n\t\tLSHVector vec = (LSHVector) arguments[1];\n\n\t\tPreparedStatement s = insert_stmt.prepareIfNeeded(() -> db.prepareStatement(\n\t\t\t\"INSERT INTO \" + TABLE_NAME + \" (count,vec_hash,vec) VALUES(?,?,?)\",\n\t\t\tStatement.RETURN_GENERATED_KEYS));\n\n\t\tStringBuilder vecBuf = new StringBuilder();\n\t\tvec.saveBase64(vecBuf, Base64Lite.encode);\n\n\t\ts.setInt(1, count);\n\t\ts.setLong(2, vec.calcUniqueHash());\n\t\ts.setString(3, vecBuf.toString());\n\t\tif (s.executeUpdate() != 1) {\n\t\t\tthrow new SQLException(\"Insert failed for vector table\");\n\t\t}\n\t\tlong id;\n\t\ttry (ResultSet rs = s.getGeneratedKeys()) {\n\t\t\tif (!rs.next()) {\n\t\t\t\tthrow new SQLException(\"Unable to obtain vector id for insert\");\n\t\t\t}\n\t\t\tid = rs.getLong(1);\n\t\t}\n\t\tvectorStore.update(\n\t\t\tnew VectorStoreEntry(id, vec, count, vectorFactory.getSelfSignificance(vec)));\n\t\treturn id;\n\t}\n\n\t/**\n\t * Read all vectors from table and generate an ID-based vector map\n\t * @return vector map (ID->VectorStoreEntry)\n\t * @throws SQLException if error occurs\n\t */","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2VectorTable.java#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the H2 database file integrity — run an H2 recovery or consistency check.","Verify the H2 JDBC driver version is compatible with the Ghidra BSim module.","Inspect the h2_vectable DDL for any unexpected triggers or constraints.","If corruption is suspected, rebuild the BSim database from source programs."],"exampleFix":"// before\nif (s.executeUpdate() != 1) {\n    throw new SQLException(\"Insert failed for vector table\");\n}\n\n// after (diagnostic: capture actual row count)\nint rc = s.executeUpdate();\nif (rc != 1) {\n    throw new SQLException(\n        \"Insert failed for vector table: executeUpdate returned \" + rc);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    long id = vectorTable.insert(count, vec);\n} catch (SQLException e) {\n    if (e.getMessage().equals(\"Insert failed for vector table\")) {\n        // This indicates an H2-level anomaly; check database integrity\n        Msg.error(this, \"Vector insert anomaly; database may be corrupt\");\n        checkH2Integrity(db);\n    }\n    throw e;\n}","preventionTips":["Use a compatible H2 JDBC driver version matched to Ghidra.","Do not manually add triggers to BSim tables.","Run H2 database consistency checks periodically for production databases.","Back up BSim databases before schema changes."],"tags":["bsim","h2","vector","insert","sql","data-integrity"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}