Functions
create_table_ddl_t.cc File Reference
#include "cetlib/sqlite/Exception.h"
#include "cetlib/sqlite/column.h"
#include "cetlib/sqlite/create_table.h"
#include "cetlib/sqlite/detail/normalize_statement.h"
#include <iostream>
#include <string>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

int main ( void  )

Definition at line 30 of file create_table_ddl_t.cc.

30  {
31  // Test simple create_table() so we can use it later
32  {
33  auto const& test = detail::create_table("employees");
34  std::string const ref{"CREATE TABLE employees"};
35  compare_statements(test, ref);
36  }
37 
38  // One column
39  {
40  auto const& test =
41  detail::create_table_ddl("employees", column<string>{"name"});
42  std::string const ref{detail::create_table("employees") + "(name text)"};
43  compare_statements(test, ref);
44  }
45 
46  // Two columns
47  {
48  auto const& test = detail::create_table_ddl(
49  "employees", column<string>{"name"}, column<int>{"id"});
50  std::string const ref{detail::create_table("employees") +
51  "(name text, id integer)"};
52  compare_statements(test, ref);
53  }
54 
55  // Two columns, the first with the PRIMARY KEY constraint
56  {
57  auto const& test = detail::create_table_ddl(
58  "employees", column<int, primary_key>{"id"}, column<string>{"name"});
59  std::string const ref{detail::create_table("employees") +
60  "(id integer PRIMARY KEY, name text)"};
61  compare_statements(test, ref);
62  }
63 }
64 catch (std::exception const& e) {
65  std::cerr << e.what() << '\n';
66  return 1;
67 }
68 catch (...) {
69  std::cerr << "Caught unknown exception.\n";
70  return 2;
71 }
std::string string
Definition: nybbler.cc:12
const double e
void create_table(sqlite3 *const db, std::string const &tablename, Cols const &...cols)
Definition: create_table.h:118
std::string create_table_ddl(std::string const &tablename, Cols const &...cols)
Definition: create_table.h:96
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33