5 WvString
ColumnInfo::ColTypeNames
[ColumnTypeMax
+ 1] = {
20 WvString
ColumnInfo::ColTypeDBusType
[ColumnTypeMax
+ 1] = {
34 // Note: These use the MSSQL names for data types.
35 // FIXME: It may make sense to specify the SQL datatypes in the enum, and
36 // convert them to more DBussy types later, IOW flip this around.
37 WvString
ColumnInfo::getSqlColtype()
54 return "uniqueidentifier";
59 return WvString("varchar(%s)", size
);
61 return WvString("text");
65 return WvString("numeric(%s,%s)", precision
, scale
);
68 WVFAILEQ(WvString("Unknown SQL type %d", coltype
), WvString::null
);
73 void ColumnInfo::writeHeader(WvDBusMsg
&msg
)
75 msg
.struct_start(getDBusSignature());
78 msg
.append(ColumnInfo::ColTypeNames
[coltype
]);
79 msg
.append(precision
);
85 void Column::addDataTo(WvDBusMsg
&reply
)
92 case ColumnInfo::Int64
:
93 reply
.append(*(long long *)data
[0]);
95 case ColumnInfo::Int32
:
96 reply
.append(*(int *)data
[0]);
98 case ColumnInfo::Int16
:
99 reply
.append(*(short *)data
[0]);
101 case ColumnInfo::UInt8
:
102 reply
.append(*(unsigned char *)data
[0]);
104 case ColumnInfo::Bool
:
105 reply
.append(*(bool *)data
[0]);
107 case ColumnInfo::Double
:
108 reply
.append(*(double *)data
[0]);
110 case ColumnInfo::Uuid
:
111 reply
.append((char *)data
[0]);
113 case ColumnInfo::Binary
:
115 unsigned char *blob
= (unsigned char *)data
[0];
116 reply
.array_start("y");
117 for (int i
= 0; i
< info
.size
; ++i
)
118 reply
.append(blob
[i
]);
122 case ColumnInfo::String
:
123 reply
.append((char *)data
[0]);
125 case ColumnInfo::DateTime
:
126 reply
.struct_start("ii");
127 // FIXME: Each element in the vector should be a complete entry
128 WVPASS(data
.size() >= 2);
129 reply
.append(*(long long *)data
[0]);
130 reply
.append(*(int *)data
[1]);
133 case ColumnInfo::Decimal
:
134 reply
.append((char *)data
[0]);
136 case ColumnInfo::ColumnTypeMax
:
138 WVFAILEQ(WvString("Unknown SQL type %d", info
.coltype
), WvString::null
);
144 Column
& Column::append(WvStringParm str
)
146 char *newstr
= (char *)malloc(str
.len() + 1);
147 strcpy(newstr
, str
.cstr());
148 data
.push_back(newstr
);
152 // FIXME: It might be nice to template this.
153 Column
& Column::append(long long element
)
155 long long *newelem
= (long long *)malloc(sizeof(element
));
157 data
.push_back(newelem
);
161 Column
& Column::append(int element
)
163 // It's error-prone to have to specify LL after every time value literal,
164 // even the ones that fit into 32 bits.
165 if (info
.coltype
== ColumnInfo::DateTime
&& data
.size() == 0)
166 return append((long long)element
);
168 int *newelem
= (int *)malloc(sizeof(element
));
170 data
.push_back(newelem
);
174 Column
& Column::append(short element
)
176 short *newelem
= (short *)malloc(sizeof(element
));
178 data
.push_back(newelem
);
182 Column
& Column::append(unsigned char element
)
184 unsigned char *newelem
= (unsigned char *)malloc(sizeof(element
));
186 data
.push_back(newelem
);
190 Column
& Column::append(signed char element
)
192 signed char *newelem
= (signed char *)malloc(sizeof(element
));
194 data
.push_back(newelem
);
198 Column
& Column::append(double element
)
200 double *newelem
= (double *)malloc(sizeof(element
));
202 data
.push_back(newelem
);