more on database (tests)
This commit is contained in:
parent
53666163b4
commit
eeae4fe609
4 changed files with 27 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "database.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
Database::Database(const std::string& dbname) : db_(nullptr)
|
||||
{
|
||||
|
@ -24,16 +24,14 @@ void Database::exec(const std::string& sql)
|
|||
|
||||
void Database::init()
|
||||
{
|
||||
std::string sqlCreateSellers{
|
||||
"CREATE TABLE IF NOT EXISTS sellers ("
|
||||
"id TEXT PRIMARY KEY NOT NULL, "
|
||||
"seller_no INTEGER, "
|
||||
"first_name TEXT, "
|
||||
"last_name TEXT, "
|
||||
"offered_articles INTEGER, "
|
||||
"UNIQUE (seller_no)"
|
||||
");"
|
||||
};
|
||||
std::string sqlCreateSellers{"CREATE TABLE IF NOT EXISTS sellers ("
|
||||
"id TEXT PRIMARY KEY NOT NULL, "
|
||||
"seller_no INTEGER, "
|
||||
"first_name TEXT, "
|
||||
"last_name TEXT, "
|
||||
"offered_articles INTEGER, "
|
||||
"UNIQUE (seller_no)"
|
||||
");"};
|
||||
|
||||
std::string sqlCreateArticles{
|
||||
"CREATE TABLE IF NOT EXISTS articles ("
|
||||
|
@ -46,10 +44,7 @@ void Database::init()
|
|||
"UNIQUE (source_no, article_no), "
|
||||
"FOREIGN KEY (seller_id) REFERENCES sellers(id) ON DELETE CASCADE, "
|
||||
"CHECK (article_no BETWEEN 0 AND 99999)"
|
||||
");"
|
||||
};
|
||||
|
||||
std::cout << sqlCreateArticles << "\n";
|
||||
");"};
|
||||
|
||||
beginTransaction();
|
||||
exec(sqlCreateSellers);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue