Main Page
Namespaces
Classes
Files
File List
File Members
libism
ISM
soci
src
backends
mysql
mysql/standard-into-type.cpp
Go to the documentation of this file.
1
//
2
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton
3
// MySQL backend copyright (C) 2006 Pawel Aleksander Fedorynski
4
// Distributed under the Boost Software License, Version 1.0.
5
// (See accompanying file LICENSE_1_0.txt or copy at
6
// http://www.boost.org/LICENSE_1_0.txt)
7
//
8
9
#define SOCI_MYSQL_SOURCE
10
#include "
soci-mysql.h
"
11
#include <
soci-platform.h
>
12
#include "
common.h
"
13
// std
14
#include <cassert>
15
#include <ciso646>
16
#include <cstdlib>
17
#include <cstring>
18
#include <ctime>
19
#include <string>
20
21
#ifdef _MSC_VER
22
#pragma warning(disable:4355)
23
#endif
24
25
using namespace
soci
;
26
using namespace
soci::details
;
27
using namespace
soci::details::mysql
;
28
29
30
void
mysql_standard_into_type_backend::define_by_pos
(
31
int
&position,
void
*data,
exchange_type
type)
32
{
33
data_ = data;
34
type_ = type;
35
position_ = position++;
36
}
37
38
void
mysql_standard_into_type_backend::pre_fetch
()
39
{
40
// nothing to do here
41
}
42
43
void
mysql_standard_into_type_backend::post_fetch
(
44
bool
gotData,
bool
calledFromFetch,
indicator
*ind)
45
{
46
if
(calledFromFetch ==
true
&& gotData ==
false
)
47
{
48
// this is a normal end-of-rowset condition,
49
// no need to do anything (fetch() will return false)
50
return
;
51
}
52
53
if
(gotData)
54
{
55
int
pos = position_ - 1;
56
//mysql_data_seek(statement_.result_, statement_.currentRow_);
57
mysql_row_seek(statement_.result_,
58
statement_.resultRowOffsets_[statement_.currentRow_]);
59
MYSQL_ROW
row
= mysql_fetch_row(statement_.result_);
60
if
(row[pos] == NULL)
61
{
62
if
(ind == NULL)
63
{
64
throw
soci_error
(
65
"Null value fetched and no indicator defined."
);
66
}
67
*ind =
i_null
;
68
return
;
69
}
70
else
71
{
72
if
(ind != NULL)
73
{
74
*ind =
i_ok
;
75
}
76
}
77
const
char
*buf = row[pos] != NULL ? row[pos] :
""
;
78
switch
(type_)
79
{
80
case
x_char
:
81
{
82
char
*dest =
static_cast<
char
*
>
(data_);
83
*dest = *buf;
84
}
85
break
;
86
case
x_stdstring
:
87
{
88
std::string *dest =
static_cast<
std::string *
>
(data_);
89
unsigned
long
* lengths =
90
mysql_fetch_lengths(statement_.result_);
91
dest->assign(buf, lengths[pos]);
92
}
93
break
;
94
case
x_short
:
95
{
96
short
*dest =
static_cast<
short
*
>
(data_);
97
parse_num
(buf, *dest);
98
}
99
break
;
100
case
x_integer
:
101
{
102
int
*dest =
static_cast<
int
*
>
(data_);
103
parse_num
(buf, *dest);
104
}
105
break
;
106
case
x_long_long
:
107
{
108
long
long
*dest =
static_cast<
long
long
*
>
(data_);
109
parse_num
(buf, *dest);
110
}
111
break
;
112
case
x_unsigned_long_long
:
113
{
114
unsigned
long
long
*dest =
115
static_cast<
unsigned
long
long
*
>
(data_);
116
parse_num
(buf, *dest);
117
}
118
break
;
119
case
x_double
:
120
{
121
double
*dest =
static_cast<
double
*
>
(data_);
122
parse_num
(buf, *dest);
123
}
124
break
;
125
case
x_stdtm
:
126
{
127
// attempt to parse the string and convert to std::tm
128
std::tm *dest =
static_cast<
std::tm *
>
(data_);
129
parse_std_tm
(buf, *dest);
130
}
131
break
;
132
default
:
133
throw
soci_error
(
"Into element used with non-supported type."
);
134
}
135
}
136
}
137
138
void
mysql_standard_into_type_backend::clean_up
()
139
{
140
// nothing to do here
141
}
soci::details::x_stdstring
Definition:
soci-backend.h:39
soci::details::x_char
Definition:
soci-backend.h:38
soci::details::x_double
Definition:
soci-backend.h:44
soci::details::mysql::parse_std_tm
void parse_std_tm(char const *buf, std::tm &t)
Definition:
mysql/common.cpp:36
soci::details
Definition:
db2/common.h:15
soci::row
Definition:
row.h:41
soci::i_null
Definition:
soci-backend.h:28
soci::mysql_standard_into_type_backend::define_by_pos
virtual void define_by_pos(int &position, void *data, details::exchange_type type)
Definition:
mysql/standard-into-type.cpp:30
soci-mysql.h
soci::soci_error
Definition:
core/error.h:19
soci::details::mysql::parse_num
void parse_num(char const *buf, T &x)
Definition:
mysql/common.h:46
soci::i_ok
Definition:
soci-backend.h:28
soci::details::x_short
Definition:
soci-backend.h:40
soci::indicator
indicator
Definition:
soci-backend.h:28
soci::details::x_stdtm
Definition:
soci-backend.h:45
soci::mysql_standard_into_type_backend::clean_up
virtual void clean_up()
Definition:
mysql/standard-into-type.cpp:138
soci::details::mysql
Definition:
mysql/common.h:24
soci::details::x_unsigned_long_long
Definition:
soci-backend.h:43
soci::details::exchange_type
exchange_type
Definition:
soci-backend.h:36
soci::details::x_integer
Definition:
soci-backend.h:41
soci::details::x_long_long
Definition:
soci-backend.h:42
soci-platform.h
soci::mysql_standard_into_type_backend::post_fetch
virtual void post_fetch(bool gotData, bool calledFromFetch, indicator *ind)
Definition:
mysql/standard-into-type.cpp:43
soci
Definition:
db2/common.h:15
common.h
soci::mysql_standard_into_type_backend::pre_fetch
virtual void pre_fetch()
Definition:
mysql/standard-into-type.cpp:38
asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41