Main Page
Namespaces
Classes
Files
File List
File Members
libism
ISM
soci
src
backends
sqlite3
backends/sqlite3/blob.cpp
Go to the documentation of this file.
1
//
2
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
3
// Distributed under the Boost Software License, Version 1.0.
4
// (See accompanying file LICENSE_1_0.txt or copy at
5
// http://www.boost.org/LICENSE_1_0.txt)
6
//
7
8
#include "
soci-sqlite3.h
"
9
#include <algorithm>
10
#include <cstring>
11
12
using namespace
soci
;
13
14
sqlite3_blob_backend::sqlite3_blob_backend
(
sqlite3_session_backend
&
session
)
15
: session_(session), buf_(0), len_(0)
16
{
17
}
18
19
sqlite3_blob_backend::~sqlite3_blob_backend
()
20
{
21
if
(
buf_
)
22
{
23
delete
[]
buf_
;
24
buf_
= 0;
25
len_
= 0;
26
}
27
}
28
29
std::size_t
sqlite3_blob_backend::get_len
()
30
{
31
return
len_
;
32
}
33
34
std::size_t
sqlite3_blob_backend::read
(
35
std::size_t offset,
char
* buf, std::size_t toRead)
36
{
37
size_t
r = toRead;
38
39
// make sure that we don't try to read
40
// past the end of the data
41
if
(r >
len_
- offset)
42
{
43
r =
len_
- offset;
44
}
45
46
memcpy(buf,
buf_
+ offset, r);
47
48
return
r;
49
}
50
51
52
std::size_t
sqlite3_blob_backend::write
(
53
std::size_t offset,
char
const
* buf,
54
std::size_t toWrite)
55
{
56
const
char
* oldBuf =
buf_
;
57
std::size_t oldLen =
len_
;
58
len_
= (std::max)(
len_
, offset + toWrite);
59
60
buf_
=
new
char
[
len_
];
61
62
if
(oldBuf)
63
{
64
// we need to copy both old and new buffers
65
// it is possible that the new does not
66
// completely cover the old
67
memcpy(
buf_
, oldBuf, oldLen);
68
delete
[] oldBuf;
69
}
70
memcpy(
buf_
+ offset, buf, toWrite);
71
72
return
len_
;
73
}
74
75
76
std::size_t
sqlite3_blob_backend::append
(
77
char
const
* buf, std::size_t toWrite)
78
{
79
const
char
* oldBuf =
buf_
;
80
81
buf_
=
new
char
[
len_
+ toWrite];
82
83
memcpy(
buf_
, oldBuf,
len_
);
84
85
memcpy(
buf_
+
len_
, buf, toWrite);
86
87
delete
[] oldBuf;
88
89
len_
+= toWrite;
90
91
return
len_
;
92
}
93
94
95
void
sqlite3_blob_backend::trim
(std::size_t newLen)
96
{
97
const
char
* oldBuf =
buf_
;
98
len_
= newLen;
99
100
buf_
=
new
char
[
len_
];
101
102
memcpy(
buf_
, oldBuf,
len_
);
103
104
delete
[] oldBuf;
105
}
106
107
std::size_t
sqlite3_blob_backend::set_data
(
char
const
*buf, std::size_t toWrite)
108
{
109
if
(
buf_
)
110
{
111
delete
[]
buf_
;
112
buf_
= 0;
113
len_
= 0;
114
}
115
return
write
(0, buf, toWrite);
116
}
soci::sqlite3_blob_backend::len_
size_t len_
Definition:
soci-sqlite3.h:246
soci::sqlite3_blob_backend::sqlite3_blob_backend
sqlite3_blob_backend(sqlite3_session_backend &session)
Definition:
backends/sqlite3/blob.cpp:14
soci::sqlite3_blob_backend::get_len
virtual std::size_t get_len()
Definition:
backends/sqlite3/blob.cpp:29
soci::sqlite3_session_backend
Definition:
soci-sqlite3.h:249
soci::sqlite3_blob_backend::~sqlite3_blob_backend
~sqlite3_blob_backend()
Definition:
backends/sqlite3/blob.cpp:19
soci::sqlite3_blob_backend::buf_
char * buf_
Definition:
soci-sqlite3.h:245
soci-sqlite3.h
soci::sqlite3_blob_backend::append
virtual std::size_t append(char const *buf, std::size_t toWrite)
Definition:
backends/sqlite3/blob.cpp:76
soci::session
Definition:
session.h:40
soci::sqlite3_blob_backend::read
virtual std::size_t read(std::size_t offset, char *buf, std::size_t toRead)
Definition:
backends/sqlite3/blob.cpp:34
soci::sqlite3_blob_backend::set_data
std::size_t set_data(char const *buf, std::size_t toWrite)
Definition:
backends/sqlite3/blob.cpp:107
soci::sqlite3_blob_backend::trim
virtual void trim(std::size_t newLen)
Definition:
backends/sqlite3/blob.cpp:95
soci
Definition:
db2/common.h:15
soci::sqlite3_blob_backend::write
virtual std::size_t write(std::size_t offset, char const *buf, std::size_t toWrite)
Definition:
backends/sqlite3/blob.cpp:52
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:40