Projects · 14 / 19 Exercise Hard

Library with SQLite

Objective

Manage a library's loans by storing the books in an in-memory SQLite database. Use queries with parameters (?), do not concatenate text into the SQL.

Instructions

  • Create a table books with title (primary key), author and lent_to (null if available).
  • The first line has the number n of commands: add title author, lend title user, return title or list. Titles, authors and users are a single word.
  • Show OK or one of these errors: Error: duplicate book, Error: book not found, Error: already lent, Error: was not lent. The listing is sorted by title, with the format title (author): available or title (author): lent to user.
Input
5
add Dune Herbert
add Emma Austen
lend Dune ana
return Emma
list
Output
OK
OK
OK
Error: was not lent
Dune (Herbert): lent to ana
Emma (Austen): available

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise