-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlutil.cpp
57 lines (53 loc) · 1.35 KB
/
sqlutil.cpp
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
#include "sqlutil.h"
#include <QString>
SqlUtil4::SqlUtil::SqlUtil()
{
}
QString SqlUtil4::SqlUtil::getPlaceholders(int count)
{
QString placeholders;
placeholders.resize(count*2+1,QChar('\0'));
placeholders[0] = '(';
for(int i=1;i<placeholders.length()-1; i++) {
if (i%2==0) {
placeholders[i] = ',';
} else {
placeholders[i] = '?';
}
}
placeholders[placeholders.length()-1] = ')';
return placeholders;
}
QString SqlUtil4::SqlUtil::getTuplePlaceholders(int numberOfTuples, int tupleItemCount)
{
QString placeholders;
placeholders.reserve((2*numberOfTuples+1)*tupleItemCount+tupleItemCount-1);
placeholders += "(?";
for(int i = 1;i < tupleItemCount; i++) {
placeholders += ",?";
}
placeholders += (')');
for(int j = 1; j < numberOfTuples; j++) {
placeholders += ",(?";
for(int i = 1;i < tupleItemCount; i++) {
placeholders += ",?";
}
placeholders += ')';
}
return placeholders;
}
QString SqlUtil4::SqlUtil::getArrayPlaceholders(int count)
{
QString placeholders;
placeholders.resize(count*2+1,QChar('\0'));
placeholders[0] = '[';
for(int i=1;i<placeholders.length()-1; i++) {
if (i%2==0) {
placeholders[i] = ',';
} else {
placeholders[i] = '?';
}
}
placeholders[placeholders.length()-1] = ']';
return placeholders;
}