Skip to content

Commit c64a936

Browse files
committed
Fix bug EXECUTE_DUPLICATE_KEY
1 parent 3d54333 commit c64a936

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

db.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,13 @@ void leaf_node_insert(Cursor* cursor, uint32_t key, Row* value) {
808808
}
809809

810810
ExecuteResult execute_insert(Statement* statement, Table* table) {
811-
void* node = get_page(table->pager, table->root_page_num);
812-
uint32_t num_cells = (*leaf_node_num_cells(node));
813-
814811
Row* row_to_insert = &(statement->row_to_insert);
815812
uint32_t key_to_insert = row_to_insert->id;
816813
Cursor* cursor = table_find(table, key_to_insert);
817814

815+
void *node = get_page(table->pager, cursor->page_num);
816+
uint32_t num_cells = *leaf_node_num_cells(node);
817+
818818
if (cursor->cell_num < num_cells) {
819819
uint32_t key_at_index = *leaf_node_key(node, cursor->cell_num);
820820
if (key_at_index == key_to_insert) {

0 commit comments

Comments
 (0)