summaryrefslogtreecommitdiff
path: root/tests/test_database.cpp
blob: 2aa12b3bae3632d8074ec27c1f57d876cffde29f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * test_database.cpp
 *
 *  Created on: 28.10.2012
 *      Author: savop
 */

#include <iostream>
#include <sstream>
#include "../include/db/connection.h"

int main(){

  try {
    db::Connection connection = db::Connect("/tmp/test_db.sqlite");

    connection.BeginTransaction();

    std::stringstream ss;

    ss << "CREATE TABLE details"
       << "("
       << "  `propertyID` INTEGER PRIMARY KEY,"
       << "  `@id` TEXT "
       << "  REFERENCES metadata (`@id`) ON DELETE CASCADE ON UPDATE CASCADE,"
       << "  `property`   TEXT,"
       << "  `value`      TEXT"
       << ")";

    db::Statement statement = connection.Prepare(ss.str());

    statement.Execute();

    connection.CommitTransaction();

  } catch (const db::SQLiteException& e){
    std::cerr << "Exception: "<< e.what() << std::endl;
  }

  return 0;
}