[go: up one dir, main page]

File: once-temp-type.cpp

package info (click to toggle)
soci 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,944 kB
  • sloc: ansic: 169,887; cpp: 54,198; javascript: 12,258; ada: 1,973; sh: 36; makefile: 12; xml: 2
file content (189 lines) | stat: -rw-r--r-- 4,174 bytes parent folder | download
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// Copyright (C) 2004-2016 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//

#define SOCI_SOURCE
#include "soci/once-temp-type.h"
#include "soci/ref-counted-statement.h"
#include "soci/session.h"

using namespace soci;
using namespace soci::details;

once_temp_type::once_temp_type(session & s)
    : rcst_(new ref_counted_statement(s))
{
    // this is the beginning of new query
    s.get_query_stream().str("");
}

once_temp_type::once_temp_type(once_temp_type const & o)
    :rcst_(o.rcst_)
{
    rcst_->inc_ref();
}

once_temp_type & once_temp_type::operator=(once_temp_type const & o)
{
    o.rcst_->inc_ref();
    rcst_->dec_ref();
    rcst_ = o.rcst_;

    return *this;
}

once_temp_type::~once_temp_type() noexcept(false)
{
    rcst_->dec_ref();
}

once_temp_type & once_temp_type::operator,(into_type_ptr const & i)
{
    rcst_->exchange(i);
    return *this;
}

once_temp_type & once_temp_type::operator,(use_type_ptr const & u)
{
    rcst_->exchange(u);
    return *this;
}

ddl_type::ddl_type(session & s)
    : s_(&s), rcst_(new ref_counted_statement(s))
{
    // this is the beginning of new query
    s.get_query_stream().str("");
}

ddl_type::ddl_type(const ddl_type & d)
    : s_( d.s_ ), rcst_(d.rcst_)
{
    rcst_->inc_ref();
}

ddl_type & ddl_type::operator=(const ddl_type & d)
{
    s_ = d.s_;
    d.rcst_->inc_ref();
    rcst_->dec_ref();
    rcst_ = d.rcst_;

    return *this;
}

ddl_type::~ddl_type() noexcept(false)
{
    rcst_->dec_ref();
}

void ddl_type::create_table(const std::string & tableName)
{
    rcst_->accumulate(s_->get_backend()->create_table(tableName));
}

void ddl_type::add_column(const std::string & tableName,
    const std::string & columnName, db_type dt,
    int precision, int scale)
{
    rcst_->accumulate(s_->get_backend()->add_column(
            tableName, columnName, dt, precision, scale));
}

void ddl_type::alter_column(const std::string & tableName,
    const std::string & columnName, db_type dt,
    int precision, int scale)
{
    rcst_->accumulate(s_->get_backend()->alter_column(
            tableName, columnName, dt, precision, scale));
}

void ddl_type::drop_column(const std::string & tableName,
    const std::string & columnName)
{
    rcst_->accumulate(s_->get_backend()->drop_column(
            tableName, columnName));
}

ddl_type & ddl_type::column(const std::string & columnName, db_type dt,
                            int precision, int scale)
{
    if (rcst_->get_need_comma())
    {
        rcst_->accumulate(", ");
    }

    rcst_->accumulate(columnName);
    rcst_->accumulate(" ");
    rcst_->accumulate(
            s_->get_backend()->create_column_type(dt, precision, scale));

    rcst_->set_need_comma(true);

    return *this;
}

ddl_type & ddl_type::unique(const std::string & name,
    const std::string & columnNames)
{
    if (rcst_->get_need_comma())
    {
        rcst_->accumulate(", ");
    }

    rcst_->accumulate(s_->get_backend()->constraint_unique(
            name, columnNames));

    rcst_->set_need_comma(true);

    return *this;
}

ddl_type & ddl_type::primary_key(const std::string & name,
    const std::string & columnNames)
{
    if (rcst_->get_need_comma())
    {
        rcst_->accumulate(", ");
    }

    rcst_->accumulate(s_->get_backend()->constraint_primary_key(
            name, columnNames));

    rcst_->set_need_comma(true);

    return *this;
}

ddl_type & ddl_type::foreign_key(const std::string & name,
    const std::string & columnNames,
    const std::string & refTableName,
    const std::string & refColumnNames)
{
    if (rcst_->get_need_comma())
    {
        rcst_->accumulate(", ");
    }

    rcst_->accumulate(s_->get_backend()->constraint_foreign_key(
            name, columnNames, refTableName, refColumnNames));

    rcst_->set_need_comma(true);

    return *this;
}

ddl_type & ddl_type::operator()(const std::string & arbitrarySql)
{
    rcst_->accumulate(" " + arbitrarySql);

    return *this;
}

void ddl_type::set_tail(const std::string & tail)
{
    rcst_->set_tail(tail);
}