-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlitevariant.cpp
More file actions
70 lines (65 loc) · 1.72 KB
/
Copy pathsqlitevariant.cpp
File metadata and controls
70 lines (65 loc) · 1.72 KB
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
#include "sqlitevariant.h"
#include "sqlite/sqlite3.h"
int BindVariantToStatement(sqlite3_stmt* stmt, const SQLiteVariant* value, int pos)
{
//pos is the position of the argument in the select statement
if(!value)
{
printf("Given a 0 variant pointer!\n");
return SQLITE_ERROR;
}
switch(value->GetType())
{
case SQLiteVariant::StoredType::VARINT:
switch(value->GetDataLength())
{
case sizeof(unsigned char):
case sizeof(unsigned short):
case sizeof(unsigned int):
{
//sqlite only stores data as signed anyway so we just have to cast it back
//if we know that's what we want
unsigned int val = 0;
value->GetValue(val);
return sqlite3_bind_int(stmt, pos, val);
}
break;
case sizeof(unsigned long long):
{
unsigned long long val = 0;
value->GetValue(val);
return sqlite3_bind_int64(stmt, pos, val);
break;
}
default:
return SQLITE_ERROR;
break;
}
break;
case SQLiteVariant::StoredType::VARREAL:
if(sizeof(float) == value->GetDataLength())
{
float val = 0.f;
value->GetValue(val);
return sqlite3_bind_double(stmt, pos, static_cast<double>(val));
}
else
{
double val = 0.0;
value->GetValue(val);
return sqlite3_bind_double(stmt, pos, val);
}
break;
case SQLiteVariant::StoredType::VARTEXT:
return sqlite3_bind_text(stmt, pos, value->GetValueBlobPtr(), value->GetDataLength() - 1, 0);
case SQLiteVariant::StoredType::VARBLOB:
return sqlite3_bind_blob(stmt, pos, value->GetValueBlobPtr(), value->GetDataLength(), 0);
default:
return SQLITE_ERROR;
}
}
std::string VariantTypeToString(SQLiteVariant::StoredType type)
{
static const char* typestrs[] = {"NULL", "INT", "REAL", "BLOB", "TEXT"};
return std::string(typestrs[static_cast<int>(type)]);
}