Skip to content

Commit

Permalink
Fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
eatonphil committed Mar 1, 2020
1 parent 2fd5ef3 commit 6a788b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ ok
====================
| 1 | Phil |
ok
# INSERT INTO users VALUES (3, 'Kate');
# INSERT INTO users VALUES (2, 'Kate');
ok
# SELECT name, id FROM users;
| name | id | name | id |
| name | id |
====================
| Phil | 1 |
| Kate | 3 |
| Kate | 2 |
ok
```
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"bytes"
"bufio"
"bytes"
"fmt"
"os"
"strings"
"fmt"

"github.com/eatonphil/gosql"
)
Expand Down
37 changes: 21 additions & 16 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (mb *MemoryBackend) Select(slct *SelectStatement) (*Results, error) {
}
}

for _, row := range table.rows {
for i, row := range table.rows {
result := []Cell{}
isFirstRow := i == 0

for _, col := range *slct.item {
if col.asterisk {
Expand All @@ -111,13 +112,15 @@ func (mb *MemoryBackend) Select(slct *SelectStatement) (*Results, error) {
found := false
for i, tableCol := range table.columns {
if tableCol == lit.value {
columns = append(columns, struct {
Type ColumnType
Name string
}{
Type: table.columnTypes[i],
Name: lit.value,
})
if isFirstRow {
columns = append(columns, struct {
Type ColumnType
Name string
}{
Type: table.columnTypes[i],
Name: lit.value,
})
}

result = append(result, row[i])
found = true
Expand All @@ -138,13 +141,15 @@ func (mb *MemoryBackend) Select(slct *SelectStatement) (*Results, error) {
columnType = TextType
}

columns = append(columns, struct {
Type ColumnType
Name string
}{
Type: columnType,
Name: col.exp.literal.value,
})
if isFirstRow {
columns = append(columns, struct {
Type ColumnType
Name string
}{
Type: columnType,
Name: col.exp.literal.value,
})
}
result = append(result, mb.tokenToCell(lit))
continue
}
Expand Down Expand Up @@ -194,7 +199,7 @@ func (mb *MemoryBackend) CreateTable(crt *CreateTableStatement) error {
t := table{}
mb.tables[crt.name.value] = &t
if crt.cols == nil {

return nil
}

Expand Down

0 comments on commit 6a788b6

Please sign in to comment.