aboutsummaryrefslogtreecommitdiff
path: root/odb/database.cxx
blob: c9692ba66273eb387a5a4ed523dae101f0ca2bcc (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
42
43
44
45
46
47
48
49
50
51
52
53
// file      : odb/database.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#include <odb/database.hxx>

using namespace std;

namespace odb
{
  database::
  ~database ()
  {
  }

  unsigned long long database::
  execute (const char* st, std::size_t n)
  {
    connection_type& c (transaction::current ().connection ());
    return c.execute (st, n);
  }

  const database::schema_version_info& database::
  schema_version_migration_ (const string& name) const
  {
    schema_version_map::const_iterator i (schema_version_map_.find (name));
    const schema_version_info& svi (
      i != schema_version_map_.end () && i->second.version != 0
      ? i->second
      : load_schema_version (name));

    if (default_schema_version_ == 0 && name.empty ())
      default_schema_version_ = &svi;

    return svi;
  }

  void database::
  schema_version_migration (const schema_version_migration_type& svm,
                            const string& name)
  {
    schema_version_info& svi (schema_version_map_[name]);
    if (svi.version != svm.version || svi.migration != svm.migration)
    {
      svi.version = svm.version;
      svi.migration = svm.migration;
      schema_version_seq_++;
    }

    if (default_schema_version_ == 0 && name.empty ())
      default_schema_version_ = &svi;
  }
}