@@ -135,7 +135,7 @@ type LeafPageCell struct {
135
135
}
136
136
137
137
type InternalPageCell struct {
138
- value uint32_t
138
+ value uint32_t //pageNum
139
139
key uint32_t
140
140
}
141
141
@@ -389,7 +389,27 @@ func doMetaCommand(inputBuffer *InputBuffer, table *Table) MetaCommandResult {
389
389
fmt .Println (header .pageType , header .isRoot )
390
390
}
391
391
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
+
393
413
return MetaCommandUnrecognizedCommand
394
414
}
395
415
@@ -449,14 +469,18 @@ func executeStatement(statement *Statement, table *Table) ExecuteResult {
449
469
}
450
470
451
471
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())
455
475
456
476
rowToInsert := s .rowToInsert
457
477
keyToInsert := rowToInsert .id
458
478
cursor := table .find (keyToInsert )
459
479
480
+ header , body := table .pager .getPage (cursor .pageNum )
481
+ leafPage := LeafPage {header : header , body : (* LeafPageBody )(body )}
482
+ numCells := * leafPage .leafNodeNumCells ()
483
+
460
484
if cursor .cellNum < numCells {
461
485
keyAtIndex := * leafPage .leafNodeKey (cursor .cellNum )
462
486
if keyAtIndex == keyToInsert {
0 commit comments