You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _parts/part1.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,12 +83,11 @@ int main(int argc, char* argv[]) {
83
83
84
84
We'll define `InputBuffer` as a small wrapper around the state we need to store to interact with [getline()](http://man7.org/linux/man-pages/man3/getline.3.html). (More on that in a minute)
"Unrecognized statement"? That seems a bit like an exception. But [exceptions are bad](https://www.youtube.com/watch?v=EVhCUSgNbzo) (and C doesn't even support them), so I'm using enum result codes wherever practical. The C compiler will complain if my switch statement doesn't handle a member of the enum, so we can feel a little more confident we handle every result of a function. Expect more result codes to be added in the future.
Copy file name to clipboardExpand all lines: _parts/part3.md
+21-32Lines changed: 21 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,18 +46,16 @@ We store those parsed arguments into a new `Row` data structure inside the state
46
46
```diff
47
47
+#define COLUMN_USERNAME_SIZE 32
48
48
+#define COLUMN_EMAIL_SIZE 255
49
-
+struct Row_t {
49
+
+typedef struct {
50
50
+ uint32_t id;
51
51
+ char username[COLUMN_USERNAME_SIZE];
52
52
+ char email[COLUMN_EMAIL_SIZE];
53
-
+};
54
-
+typedef struct Row_t Row;
53
+
+} Row;
55
54
+
56
-
struct Statement_t {
55
+
typedef struct {
57
56
StatementType type;
58
57
+ Row row_to_insert; // only used by insert statement
59
-
};
60
-
typedef struct Statement_t Statement;
58
+
} Statement;
61
59
```
62
60
63
61
Now we need to copy that data into some data structure representing the table. SQLite uses a B-tree for fast lookups, inserts and deletes. We'll start with something simpler. Like a B-tree, it will group rows into pages, but instead of arranging those pages as a tree it will arrange them as an array.
@@ -114,11 +112,10 @@ Next, a `Table` structure that points to pages of rows and keeps track of how ma
I'm making our page size 4 kilobytes because it's the same size as a page used in the virtual memory systems of most computer architectures. This means one page in our database corresponds to one page used by the operating system. The operating system will move pages in and out of memory as whole units instead of breaking them up.
@@ -263,45 +260,38 @@ We'll address those issues in the next part. For now, here's the complete diff f
Copy file name to clipboardExpand all lines: _parts/part4.md
+6-8Lines changed: 6 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,14 +121,13 @@ db >
121
121
What's going on? If you take a look at our definition of a Row, we allocate exactly 32 bytes for username and exactly 255 bytes for email. But [C strings](http://www.cprogramming.com/tutorial/c/lesson9.html) are supposed to end with a null character, which we didn't allocate space for. The solution is to allocate one additional byte:
0 commit comments