Skip to content

Commit 474bdbe

Browse files
committed
debug
1 parent 997d73b commit 474bdbe

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

db/db_tutorial.go

+29-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type LeafPageCell struct {
135135
}
136136

137137
type InternalPageCell struct {
138-
value uint32_t
138+
value uint32_t //pageNum
139139
key uint32_t
140140
}
141141

@@ -389,7 +389,27 @@ func doMetaCommand(inputBuffer *InputBuffer, table *Table) MetaCommandResult {
389389
fmt.Println(header.pageType, header.isRoot)
390390
}
391391
return MetaCommandSuccess
392-
}
392+
} else if strings.TrimSpace(string(inputBuffer.buffer)) == ".keys" {
393+
fmt.Println("keys:")
394+
for i := uint32_t(0); i < table.pager.numPages; i++ {
395+
header, body := table.pager.getPage(i)
396+
if header.pageType == PageLeaf {
397+
cells := (*LeafPageBody)(body).cells
398+
fmt.Println("leaf page ", i)
399+
for _, c := range cells {
400+
fmt.Println(c.key)
401+
}
402+
} else if header.pageType == PageInternal {
403+
fmt.Println("internal page ", i)
404+
cells := (*InternalPageBody)(body).cells
405+
for _, c := range cells {
406+
fmt.Println(c.key)
407+
}
408+
}
409+
}
410+
return MetaCommandSuccess
411+
}
412+
393413
return MetaCommandUnrecognizedCommand
394414
}
395415

@@ -449,14 +469,18 @@ func executeStatement(statement *Statement, table *Table) ExecuteResult {
449469
}
450470

451471
func (s *Statement) executeInsert(table *Table) ExecuteResult {
452-
header, body := table.pager.getPage(table.rootPageNum)
453-
leafPage := LeafPage{header: header, body: (*LeafPageBody)(body)}
454-
numCells := *(leafPage.leafNodeNumCells())
472+
//header, body := table.pager.getPage(table.rootPageNum)
473+
//leafPage := LeafPage{header: header, body: (*LeafPageBody)(body)}
474+
//numCells := *(leafPage.leafNodeNumCells())
455475

456476
rowToInsert := s.rowToInsert
457477
keyToInsert := rowToInsert.id
458478
cursor := table.find(keyToInsert)
459479

480+
header, body := table.pager.getPage(cursor.pageNum)
481+
leafPage := LeafPage{header: header, body: (*LeafPageBody)(body)}
482+
numCells := *leafPage.leafNodeNumCells()
483+
460484
if cursor.cellNum < numCells {
461485
keyAtIndex := *leafPage.leafNodeKey(cursor.cellNum)
462486
if keyAtIndex == keyToInsert {

0 commit comments

Comments
 (0)