Пример #1
0
void ResultBuilder::build(const bool columnNames)
{
	if (mError==true) return;

	// Set up the columns
	try {
		const int	count = getColumnCount();
		if (count < 1) {
			// I think a count of 0 isn't technically an error, because the result set might just be empty.
			if (count < 0) mError = true;
			return;
		}
		for (int k=0; k<count; ++k) {
			const int	ct = getColumnType(k);
			if (ct == QUERY_NO_TYPE) mError = true;
			else mResult.mCol.push_back(ct);
			if (columnNames) {
				mResult.mColNames.push_back(getColumnName(k));
			}
		}
	} catch (std::exception&) {
		mError = true;
		return;
	}

	// Empty results are considered valid.
	if (!hasNext()) return;

	if (mError == true || mResult.mCol.size() < 1) {
		mError = true;
		return;
	}

	// Read the rows
	while (hasNext()) {
		startRow();
		for (int k=0; k<mResult.mCol.size(); k++) {
			const int		col = mResult.mCol.data()[k];
			if (col == QUERY_NUMERIC) {
				double		v = 0.0f;
				if (!getDouble(k, v)) mError = true;
				addNumeric(v);
			} else if (col == QUERY_STRING) {
				string		v;
				if (!getString(k, v)) mError = true;
				addString(v);
			} else if (col == QUERY_NULL) {
				// I can't determine at any point the actual type of the column,
				// because it looks like sqlite always bases that info on the first
				// row in the result set. So in this case, I've got to just get
				// every type.
				double		v = 0.0f;
				if (!getDouble(k, v)) v = 0.0f;
				addNumeric(v);

				--mColIdx;
				string		str;
				getString(k, str);
				addString(str);
			}
		}
		next();
	}
}
Пример #2
0
 /** Append 16bit long signed integer. */
 Struct& addInt16(int16_t val) {
    return addNumeric(IntegerType, 2, val);
 }
Пример #3
0
 /** Append 32bit long signed integer. */
 Struct& addInt32(int32_t val) {
    return addNumeric(IntegerType, 4, val);
 }
Пример #4
0
 /** Append 8bit long signed integer. */
 Struct& addInt8(int8_t val) {
    return addNumeric(IntegerType, 1, val);
 }
Пример #5
0
 /** Append 32bit long unsigned integer. */
 Struct& addUInt32(uint32_t val) {
    return addNumeric(UnsignedType, 4, val);
 }
Пример #6
0
 /** Append 16bit long unsigned integer. */
 Struct& addUInt16(uint16_t val) {
    return addNumeric(UnsignedType, 2, val);
 }
Пример #7
0
 /** Append 8bit long unsigned integer. */
 Struct& addUInt8(uint8_t val) {
    return addNumeric(UnsignedType, 1, val);
 }
Пример #8
0
 /** Add boolean. */
 Struct& addBool(bool val) {
    return addNumeric(BoolType, 1, (uint8_t) val);
 }