16
16
#include < SQLiteCpp/Exception.h>
17
17
18
18
#include < string>
19
+ #include < stdint.h>
19
20
20
21
21
22
namespace SQLite
@@ -41,32 +42,32 @@ namespace SQLite
41
42
class Column
42
43
{
43
44
public:
44
- // Make clang happy by explicitly implementing the copy-constructor:
45
- Column (const Column & aOther) :
46
- mStmtPtr (aOther.mStmtPtr ),
47
- mIndex (aOther.mIndex )
48
- {
49
- }
50
-
51
45
/* *
52
46
* @brief Encapsulation of a Column in a Row of the result.
53
47
*
54
48
* @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object.
55
49
* @param[in] aIndex Index of the column in the row of result
56
50
*/
57
51
Column (Statement::Ptr& aStmtPtr, int aIndex) noexcept ; // nothrow
58
- // / @brief Simple destructor
52
+ // / Simple destructor
59
53
virtual ~Column () noexcept ; // nothrow
60
54
61
55
// default copy constructor and assignment operator are perfectly suited :
62
56
// they copy the Statement::Ptr which in turn increments the reference counter.
63
57
58
+ // / Make clang happy by explicitly implementing the copy-constructor:
59
+ Column (const Column & aOther) :
60
+ mStmtPtr (aOther.mStmtPtr ),
61
+ mIndex (aOther.mIndex )
62
+ {
63
+ }
64
+
64
65
/* *
65
66
* @brief Return a pointer to the named assigned to this result column (potentially aliased)
66
67
*
67
68
* @see getOriginName() to get original column name (not aliased)
68
69
*/
69
- const char * getName () const noexcept ; // nothrow
70
+ const char * getName () const noexcept ; // nothrow
70
71
71
72
#ifdef SQLITE_ENABLE_COLUMN_METADATA
72
73
/* *
@@ -76,36 +77,36 @@ class Column
76
77
* - when building the SQLite library itself (which is the case for the Debian libsqlite3 binary for instance),
77
78
* - and also when compiling this wrapper.
78
79
*/
79
- const char * getOriginName () const noexcept ; // nothrow
80
+ const char * getOriginName () const noexcept ; // nothrow
80
81
#endif
81
82
82
- // / @brief Return the integer value of the column.
83
- int getInt () const noexcept ; // nothrow
84
- // / @brief Return the 64bits integer value of the column.
85
- sqlite3_int64 getInt64 () const noexcept ; // nothrow
86
- // / @brief Return the double (64bits float) value of the column.
87
- double getDouble () const noexcept ; // nothrow
83
+ // / Return the integer value of the column.
84
+ int getInt () const noexcept ; // nothrow
85
+ // / Return the 64bits integer value of the column.
86
+ int64_t getInt64 () const noexcept ; // nothrow
87
+ // / Return the double (64bits float) value of the column.
88
+ double getDouble () const noexcept ; // nothrow
88
89
/* *
89
90
* @brief Return a pointer to the text value (NULL terminated string) of the column.
90
91
*
91
92
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
92
93
* thus you must copy it before using it beyond its scope (to a std::string for instance).
93
94
*/
94
- const char * getText (const char * apDefaultValue = " " ) const noexcept ; // nothrow
95
+ const char * getText (const char * apDefaultValue = " " ) const noexcept ; // nothrow
95
96
/* *
96
97
* @brief Return a pointer to the binary blob value of the column.
97
98
*
98
99
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
99
100
* thus you must copy it before using it beyond its scope (to a std::string for instance).
100
101
*/
101
- const void * getBlob () const noexcept ; // nothrow
102
+ const void * getBlob () const noexcept ; // nothrow
102
103
/* *
103
104
* @brief Return a std::string for a TEXT or BLOB column.
104
105
*
105
106
* Note this correctly handles strings that contain null bytes.
106
107
*
107
108
*/
108
- std::string getString () const noexcept ; // nothrow
109
+ std::string getString () const noexcept ; // nothrow
109
110
110
111
/* *
111
112
* @brief Return the type of the value of the column
@@ -117,27 +118,27 @@ class Column
117
118
*/
118
119
int getType () const noexcept ; // nothrow
119
120
120
- // / @brief Test if the column is an integer type value (meaningful only before any conversion)
121
+ // / Test if the column is an integer type value (meaningful only before any conversion)
121
122
inline bool isInteger () const noexcept // nothrow
122
123
{
123
124
return (SQLITE_INTEGER == getType ());
124
125
}
125
- // / @brief Test if the column is a floating point type value (meaningful only before any conversion)
126
+ // / Test if the column is a floating point type value (meaningful only before any conversion)
126
127
inline bool isFloat () const noexcept // nothrow
127
128
{
128
129
return (SQLITE_FLOAT == getType ());
129
130
}
130
- // / @brief Test if the column is a text type value (meaningful only before any conversion)
131
+ // / Test if the column is a text type value (meaningful only before any conversion)
131
132
inline bool isText () const noexcept // nothrow
132
133
{
133
134
return (SQLITE_TEXT == getType ());
134
135
}
135
- // / @brief Test if the column is a binary blob type value (meaningful only before any conversion)
136
+ // / Test if the column is a binary blob type value (meaningful only before any conversion)
136
137
inline bool isBlob () const noexcept // nothrow
137
138
{
138
139
return (SQLITE_BLOB == getType ());
139
140
}
140
- // / @brief Test if the column is NULL (meaningful only before any conversion)
141
+ // / Test if the column is NULL (meaningful only before any conversion)
141
142
inline bool isNull () const noexcept // nothrow
142
143
{
143
144
return (SQLITE_NULL == getType ());
@@ -154,28 +155,42 @@ class Column
154
155
*/
155
156
int getBytes () const noexcept ;
156
157
157
- // / @brief Alias returning the number of bytes used by the text (or blob) value of the column
158
+ // / Alias returning the number of bytes used by the text (or blob) value of the column
158
159
inline int size () const noexcept
159
160
{
160
161
return getBytes ();
161
162
}
162
163
163
- // / @brief Inline cast operator to int
164
+ // / Inline cast operator to int
164
165
inline operator int () const
165
166
{
166
167
return getInt ();
167
168
}
168
- // / @brief Inline cast operator to 32bits unsigned integer
169
- inline operator uint32_t () const
169
+ #ifndef __x86_64__
170
+ // / Inline cast operator to long as 32bits integer for 32bit systems
171
+ inline operator long () const
170
172
{
171
- return static_cast <uint32_t >(getInt64 ());
173
+ return getInt ();
174
+ }
175
+ #endif // __x86_64__
176
+ #if defined(__GNUC__) && !defined(__APPLE__)
177
+ // / Inline cast operator to long long for GCC and Clang
178
+ inline operator long long () const
179
+ {
180
+ return getInt64 ();
172
181
}
173
- // / @brief Inline cast operator to 64bits integer
174
- inline operator sqlite3_int64 () const
182
+ #endif // __GNUC__
183
+ // / Inline cast operator to 64bits integer
184
+ inline operator int64_t () const
175
185
{
176
186
return getInt64 ();
177
187
}
178
- // / @brief Inline cast operator to double
188
+ // / Inline cast operator to 32bits unsigned integer
189
+ inline operator uint32_t () const
190
+ {
191
+ return static_cast <uint32_t >(getInt64 ());
192
+ }
193
+ // / Inline cast operator to double
179
194
inline operator double () const
180
195
{
181
196
return getDouble ();
@@ -218,18 +233,7 @@ class Column
218
233
}
219
234
#endif
220
235
221
- // NOTE : the following is required by GCC and Clang to cast a Column result in a long/int64_t
222
- // / @brief Inline cast operator to long as 64bits integer
223
- inline operator long () const
224
- {
225
- #ifdef __x86_64__
226
- return getInt64 ();
227
- #else
228
- return getInt ();
229
- #endif
230
- }
231
-
232
- // / @brief Return UTF-8 encoded English language explanation of the most recent error.
236
+ // / Return UTF-8 encoded English language explanation of the most recent error.
233
237
inline const char * errmsg () const
234
238
{
235
239
return sqlite3_errmsg (mStmtPtr );
0 commit comments