Пример #1
0
//==================================================================================
//Return the value for a given column for the current record - Private const version
QVariant pqxxSqlCursor::pValue(uint pos)const
{	
	if (m_res->size() <= 0)
	{
		KexiDBDrvWarn << "pqxxSqlCursor::value - ERROR: result size not greater than 0" << endl;
		return QVariant();
	}

	if (pos>=(m_fieldCount+(m_containsROWIDInfo ? 1 : 0)))
	{
//		KexiDBDrvWarn << "pqxxSqlCursor::value - ERROR: requested position is greater than the number of fields" << endl;
		return QVariant();
	}

	KexiDB::Field *f = (m_fieldsExpanded && pos<QMIN(m_fieldsExpanded->count(), m_fieldCount)) 
		? m_fieldsExpanded->at(pos)->field : 0;

//	KexiDBDrvDbg << "pqxxSqlCursor::value(" << pos << ")" << endl;

	//from most to least frequently used types:
	if (f) //We probably have a schema type query so can use kexi to determin the row type
	{
		if ((f->isIntegerType()) || (/*ROWID*/!f && m_containsROWIDInfo && pos==m_fieldCount))
		{
			return (*m_res)[at()][pos].as(int());
		}
		else if (f->isTextType())
		{
			return QString::fromUtf8((*m_res)[at()][pos].c_str()); //utf8?
		}
		else if (f->isFPNumericType())
		{
			return (*m_res)[at()][pos].as(double());
		}
		else if (f->typeGroup() == Field::BLOBGroup)
		{
//			pqxx::result::field r = (*m_res)[at()][pos];
//			kdDebug() << r.name() << ", " << r.c_str() << ", " << r.type() << ", " << r.size() << endl;
			return ::pgsqlByteaToByteArray((*m_res)[at()][pos]);
		}
	}
	else // We probably have a raw type query so use pqxx to determin the column type
	{
		return pgsqlCStrToVariant((*m_res)[at()][pos]);
	}

	return QString::fromUtf8((*m_res)[at()][pos].c_str(), (*m_res)[at()][pos].size()); //utf8?
}
Пример #2
0
void KexiTableEdit::setupContents( QPainter *p, bool focused, const QVariant& val, 
	QString &txt, int &align, int &/*x*/, int &y_offset, int &w, int &h  )
{
	Q_UNUSED(p);
	Q_UNUSED(focused);
	Q_UNUSED(h);
	KexiDB::Field *realField = displayedField();

#ifdef Q_WS_WIN
//	x = 1;
	y_offset = -1;
#else
//	x = 1;
	y_offset = 0;
#endif

	if (realField->isFPNumericType()) {
//! @todo ADD OPTION to displaying NULL VALUES as e.g. "(null)"
		if (!val.isNull()) {
			txt = KexiDB::formatNumberForVisibleDecimalPlaces(
				val.toDouble(), realField->visibleDecimalPlaces());
		}
		w -= 6;
		align |= AlignRight;
	}
	else if (realField->isIntegerType()) {
		Q_LLONG num = val.toLongLong();
		w -= 6;
		align |= AlignRight;
		if (!val.isNull())
			txt = QString::number(num);
	}
	else {//default:
		if (!val.isNull()) {
			txt = val.toString();
		}
		align |= AlignLeft;
	}
}