Example #1
0
void CAeonView::CreateSecondaryData (const CTableDimensions &PrimaryDims, const CRowKey &PrimaryKey, CDatum dFullData, SEQUENCENUMBER RowID, CDatum *retdData)

//	CreateSecondaryData
//
//	Creates the data for a secondary view row.

	{
	int i, j;
	CComplexStruct *pData = new CComplexStruct;

	//	If the list of columns is empty then we just add the primary key

	if (m_Columns.GetCount() == 0)
		pData->SetElement(FIELD_PRIMARY_KEY, PrimaryKey.AsDatum(PrimaryDims));

	//	Otherwise we add all the fields listed in the columns array

	else
		{
		for (i = 0; i < m_Columns.GetCount(); i++)
			{
			//	The special string "primaryKey" means that we insert the 
			//	primary key as a special field.

			if (strEquals(m_Columns[i], FIELD_PRIMARY_KEY))
				pData->SetElement(FIELD_PRIMARY_KEY, PrimaryKey.AsDatum(PrimaryDims));

			//	The special string "*" means that we insert all existing
			//	fields.

			else if (strEquals(m_Columns[i], STR_ALL_COLUMNS))
				{
				for (j = 0; j < dFullData.GetCount(); j++)
					{
					CDatum dKey = dFullData.GetKey(j);
					CDatum dValue = dFullData.GetElement(j);

					if (!dValue.IsNil())
						pData->SetElement(dKey, dValue);
					}
				}

			//	Add the field by name.

			else
				{
				CDatum dColData = dFullData.GetElement(m_Columns[i]);
				if (!dColData.IsNil())
					pData->SetElement(m_Columns[i], dColData);
				}
			}
		}

	//	Done

	*retdData = CDatum(pData);
	}
Example #2
0
bool IComplexDatum::DeserializeAEONScript (CDatum::ESerializationFormats iFormat, const CString &sTypename, CCharStream *pStream)

//	DeserializeAEONScript
//
//	Deserialize AEONScript

	{
	int i;
	DWORD dwFlags = OnGetSerializeFlags();

	//	If we have an open brace then we've stored everything as a structure.

	if (pStream->GetChar() == '{')
		{
		//	Object must support this

		if (!(dwFlags & FLAG_SERIALIZE_AS_STRUCT))
			return false;

		//	Parse the structure

		CAEONScriptParser Parser(pStream);
		CDatum dData;
		CAEONScriptParser::ETokens iToken = Parser.ParseToken(&dData);
		if (iToken != CAEONScriptParser::tkDatum)
			return false;

		//	Take all the fields in the structure and apply them to our object
		//	(our descendants will do the right thing).

		for (i = 0; i < dData.GetCount(); i++)
			SetElement(dData.GetKey(i), dData.GetElement(i));
		}

	//	Otherwise we expect base64 encoded data

	else
		{
		//	Backup one character because we want the OnDeserialize call to read it.

		pStream->UnreadChar();

		//	Deserialize

		CBase64Decoder Decoder(pStream->GetByteStream());
		if (!OnDeserialize(iFormat, sTypename, Decoder))
			return false;

		//	Read the next character into the stream 

		pStream->RefreshStream();
		pStream->ReadChar();
		}

	return true;
	}
Example #3
0
CComplexStruct::CComplexStruct (CDatum dSrc)

//	CComplexStruct constructor

	{
	//	Clone from another complex structure

	for (int i = 0; i < dSrc.GetCount(); i++)
		{
		CString sKey = dSrc.GetKey(i);
		if (!sKey.IsEmpty())
			SetElement(sKey, dSrc.GetElement(i));
		}
	}
Example #4
0
CDatum CUserInfoSession::CreateSanitizedUserRecord (CDatum dRecord)

//	CreateSanitizedUserRecord
//
//	Creates a user record suitable for returning to clients. In partincular,
//	we remove the authentication information.

	{
	int i;

	//	Create a destination

	CComplexStruct *pDest = new CComplexStruct;

	//	Copy all appropriate fields

	for (i = 0; i < dRecord.GetCount(); i++)
		{
		//	If this is an auth field, then skip it

		if (strEquals(dRecord.GetKey(i), FIELD_AUTH_DESC))
			;

		else if (strEndsWith(dRecord.GetKey(i), FIELD_AUTH_DESC_SUFFIX))
			;
		
		//	Otherwise, copy it

		else
			pDest->SetElement(dRecord.GetKey(i), dRecord.GetElement(i));
		}

	//	Done

	return CDatum(pDest);
	}
Example #5
0
void CComplexStruct::AppendStruct (CDatum dDatum)

//	AppendStruct
//
//	Appends the element of the given structure

	{
	int i;

	if (dDatum.GetBasicType() == CDatum::typeStruct)
		{
		for (i = 0; i < dDatum.GetCount(); i++)
			SetElement(dDatum.GetKey(i), dDatum.GetElement(i));
		}
	}
Example #6
0
int CDatum::DefaultCompare (void *pCtx, const CDatum &dKey1, const CDatum &dKey2)

//	DefaultCompare
//
//	Default comparison routine used for sorting. Returns:
//
//	-1:		If dKey1 < dKey2
//	0:		If dKey1 == dKey2
//	1:		If dKey1 > dKey2
//
//	NOTES:
//
//	Nil == ""
//	Nil == {}
//	Nil == ()
//	"abc" != "ABC"

	{
	int i;

	//	If both are the same datatype, then compare

	CDatum::Types iType1 = dKey1.GetBasicType();
	CDatum::Types iType2 = dKey2.GetBasicType();

	//	If both types are equal, then compare

	if (iType1 == iType2)
		{
		switch (iType1)
			{
			case CDatum::typeNil:
			case CDatum::typeTrue:
				return 0;

			case CDatum::typeInteger32:
				if ((int)dKey1 > (int)dKey2)
					return 1;
				else if ((int)dKey1 < (int)dKey2)
					return -1;
				else
					return 0;

			case CDatum::typeInteger64:
				if ((DWORDLONG)dKey1 > (DWORDLONG)dKey2)
					return 1;
				else if ((DWORDLONG)dKey1 < (DWORDLONG)dKey2)
					return -1;
				else
					return 0;

			case CDatum::typeDouble:
				if ((double)dKey1 > (double)dKey2)
					return 1;
				else if ((double)dKey1 < (double)dKey2)
					return -1;
				else
					return 0;

			case CDatum::typeIntegerIP:
				return KeyCompare((const CIPInteger &)dKey1, (const CIPInteger &)dKey2);

			case CDatum::typeString:
				return KeyCompare((const CString &)dKey1, (const CString &)dKey2);

			case CDatum::typeDateTime:
				return ((const CDateTime &)dKey1).Compare((const CDateTime &)dKey2);

			case CDatum::typeArray:
				if (dKey1.GetCount() > dKey2.GetCount())
					return 1;
				else if (dKey1.GetCount() < dKey2.GetCount())
					return -1;
				else
					{
					for (i = 0; i < dKey1.GetCount(); i++)
						{
						CDatum dItem1 = dKey1.GetElement(i);
						CDatum dItem2 = dKey2.GetElement(i);
						int iItemCompare = CDatum::DefaultCompare(pCtx, dItem1, dItem2);
						if (iItemCompare != 0)
							return iItemCompare;
						}

					return 0;
					}

			case CDatum::typeStruct:
				if (dKey1.GetCount() > dKey2.GetCount())
					return 1;
				else if (dKey1.GetCount() < dKey2.GetCount())
					return -1;
				else
					{
					for (i = 0; i < dKey1.GetCount(); i++)
						{
						CString sItemKey1 = dKey1.GetKey(i);
						CString sItemKey2 = dKey2.GetKey(i);
						int iKeyCompare = KeyCompare(sItemKey1, sItemKey2);
						if (iKeyCompare != 0)
							return iKeyCompare;

						CDatum dItem1 = dKey1.GetElement(i);
						CDatum dItem2 = dKey2.GetElement(i);
						int iItemCompare = CDatum::DefaultCompare(pCtx, dItem1, dItem2);
						if (iItemCompare != 0)
							return iItemCompare;
						}

					return 0;
					}

			//	LATER: Not yet supported

			default:
				return 0;
			}
		}

	//	If one of the types is nil, then compare

	else if (iType1 == CDatum::typeNil || iType2 == CDatum::typeNil)
		{
		CDatum dNonNil;
		int iResult;
		if (iType2 == CDatum::typeNil)
			{
			dNonNil = dKey1;
			Swap(iType1, iType2);
			iResult = 1;
			}
		else
			{
			dNonNil = dKey2;
			iResult = -1;
			}

		switch (iType2)
			{
			case CDatum::typeString:
				if (((const CString &)dNonNil).IsEmpty())
					return 0;
				else
					return iResult;

			case CDatum::typeArray:
			case CDatum::typeStruct:
				if (dNonNil.GetCount() == 0)
					return 0;
				else
					return iResult;

			default:
				//	nil is always less
				return iResult;
			}
		}

	//	If one of the types is a number, then compare as numbers

	else if (dKey1.IsNumber() || dKey2.IsNumber())
		{
		CNumberValue Number1(dKey1);
		CNumberValue Number2(dKey2);

		if (Number1.IsValidNumber() && Number2.IsValidNumber())
			return Number1.Compare(Number2);
		else if (Number1.IsValidNumber())
			return 1;
		else if (Number2.IsValidNumber())
			return -1;
		else
			return 0;
		}

	//	Otherwise, cannot compare

	else
		return 0;
	}