forked from qt-creator/qt-creator
Sqlite: Add Sqlite::Value
It adds a layer if you don't know if the type is integer, float or string. It does not handle bytearrays here because so far there is no need. There are two classes, Sqlite::Value and Sqlite::ValueView. Value owns the string, ValueView holds only a view the string. So there is no allocation. It is designed to hold Utf-8 string like Sqlite but it can be easily converted in and from QString or QVariant but mind about that this is not free. ValueView has no constructors on perpose because it would be ambiguous if there would be constructors for the other primitives of the Sqlite layer like "int64", "double" and "string view". Change-Id: Ia39364eb2fc1998e5c59fdb4316add22c748507d Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "sqliteglobal.h"
|
||||
|
||||
#include "sqliteexception.h"
|
||||
#include "sqlitevalue.h"
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
|
||||
@@ -67,6 +68,7 @@ public:
|
||||
long long fetchLongLongValue(int column) const;
|
||||
double fetchDoubleValue(int column) const;
|
||||
Utils::SmallStringView fetchSmallStringViewValue(int column) const;
|
||||
ValueView fetchValueView(int column) const;
|
||||
template<typename Type>
|
||||
Type fetchValue(int column) const;
|
||||
int columnCount() const;
|
||||
@@ -76,11 +78,9 @@ public:
|
||||
void bind(int index, long long fetchValue);
|
||||
void bind(int index, double fetchValue);
|
||||
void bind(int index, Utils::SmallStringView fetchValue);
|
||||
void bind(int index, const Value &fetchValue);
|
||||
|
||||
void bind(int index, uint value)
|
||||
{
|
||||
bind(index, static_cast<long long>(value));
|
||||
}
|
||||
void bind(int index, uint value) { bind(index, static_cast<long long>(value)); }
|
||||
|
||||
void bind(int index, long value)
|
||||
{
|
||||
@@ -345,34 +345,16 @@ private:
|
||||
struct ValueGetter
|
||||
{
|
||||
ValueGetter(StatementImplementation &statement, int column)
|
||||
: statement(statement),
|
||||
column(column)
|
||||
: statement(statement)
|
||||
, column(column)
|
||||
{}
|
||||
|
||||
operator int()
|
||||
{
|
||||
return statement.fetchIntValue(column);
|
||||
}
|
||||
|
||||
operator long()
|
||||
{
|
||||
return statement.fetchLongValue(column);
|
||||
}
|
||||
|
||||
operator long long()
|
||||
{
|
||||
return statement.fetchLongLongValue(column);
|
||||
}
|
||||
|
||||
operator double()
|
||||
{
|
||||
return statement.fetchDoubleValue(column);
|
||||
}
|
||||
|
||||
operator Utils::SmallStringView()
|
||||
{
|
||||
return statement.fetchSmallStringViewValue(column);
|
||||
}
|
||||
operator int() { return statement.fetchIntValue(column); }
|
||||
operator long() { return statement.fetchLongValue(column); }
|
||||
operator long long() { return statement.fetchLongLongValue(column); }
|
||||
operator double() { return statement.fetchDoubleValue(column); }
|
||||
operator Utils::SmallStringView() { return statement.fetchSmallStringViewValue(column); }
|
||||
operator ValueView() { return statement.fetchValueView(column); }
|
||||
|
||||
StatementImplementation &statement;
|
||||
int column;
|
||||
|
||||
Reference in New Issue
Block a user