Sqllite challenge - table columns with a serial type of integer are not being returned

When trying to complete stage #WS9, I’ve started to notice that the column serial type coming back for integer types has a value of 0.

For example, here are the logs when I tried to query the superheroes db file:

parseRecord {
  buffer: <Buffer 08 00 45 1f 21 00 2b 15 42 61 72 6f 6e 20 42 6c 69 74 7a 6b 72 69 65 67 20 28 4e 65 77 20 45 61 72 74 68 29 42 6c 75 65 20 45 79 65 73 42 6c 61 63 6b ... 24 more bytes>,
  serialType: Map(7) {
    'id' => 0,
    'name' => 69,
    'eye_color' => 31,
    'hair_color' => 33,
    'appearance_count' => 0,
    'first_appearance' => 43,
    'first_appearance_year' => 21
  },
  record: Map(7) {
    'id' => null,
    'name' => 'Baron Blitzkrieg (New Earth)',
    'eye_color' => 'Blue Eyes',
    'hair_color' => 'Black Hair',
    'appearance_count' => null,
    'first_appearance' => '1977, September',
    'first_appearance_year' => '1977'
  }
}

In this example, the id and appearance_count columns have a serial type value of 0. I double-checked that this was also true when querying the file using hexdump (from the terminal).

I’ve pushed all my recent changes. To run the program with the same debugging logs, please run the program with the debug command.

e.g.

npm run debug superheroes.db "select id,name from superheroes where eye_color='Amber Eyes'"

I’ve also noticed that this was the case even when querying the sample.db.
e.g.

parseRecord {
  buffer: <Buffer 04 00 2d 19 47 6f 6c 64 65 6e 20 44 65 6c 69 63 69 6f 75 73 59 65 6c 6c 6f 77>,
  serialType: Map(3) { 'id' => 0, 'name' => 45, 'color' => 25 },
  record: Map(3) {
    'id' => null,
    'name' => 'Golden Delicious',
    'color' => 'Yellow'
  }
}

Sorry, this could be a silly question, but I must be missing something basic here.

1 Like

TLDR:

  1. The real id is rowId.
  2. Your code is handling appearance_count correctly.

Explanation for 1:

See ROWIDs and the INTEGER PRIMARY KEY:

if a rowid table has a primary key and the declared type of that column is “INTEGER”, then the column becomes an alias for the rowid. Such a column is usually referred to as an “integer primary key”.

Sanity check for 1:

Run .schema superheroes in sqlite3 CLI:

CREATE TABLE "superheroes" (
    id integer primary key autoincrement, 
    name text not null, 
    ...
);

Take Batman (Bruce Wayne) at index 1 in superheroes.db for example:



Sanity check for 2:

While Batman (Bruce Wayne) has an appearance_count of 3093, Baron Blitzkrieg (New Earth) doesn’t actually have any:


3 Likes

Excellent, thanks again for the quick response. I can’t recommend you guys enough.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.