Re: Relational vs. PICK/Object DBMS
Date: 26 Apr 2004 22:24:14 -0700
Message-ID: <4b45d3ad.0404262124.4113eb73_at_posting.google.com>
Below is a solution using XDb1/TDM.
void Example109()
// Create coat class
See www.xdb1.com/Example/Ex109.asp for additional info.
See www.xdb1.com/Example/Ex108.asp for similar problem/solution.
{
// Create wig class
int* pWig = T_create();
T_relate(&pWig, rCls, &pThing_g);
T_Name_relate(&pWig, _T("wig"));
int* pCoat = T_create();
T_relate(&pCoat, rCls, &pThing_g);
T_Name_relate(&pCoat, _T("coat"));
// Create color class
int* pColor = T_create();
T_relate(&pColor, rCls, &pThing_g);
T_Name_relate(&pColor, _T("color"));
// Create texture class
int* pTexture = T_create();
T_relate(&pTexture, rCls, &pThing_g);
T_Name_relate(&pTexture, _T("texture"));
// Create material class
int* pMaterial = T_create();
T_relate(&pMaterial, rCls, &pThing_g);
T_Name_relate(&pMaterial, _T("material"));
// Create wig1
// Its color is red.
int* pWig1 = T_create();
T_relate(&pWig1, rCls, &pWig); T_Name_relate(&pWig1, _T("wig1")); T_Val_relate(&pWig1, &pColor, _T("red"));
// Create wig2
// Its color is red, green
// AND texture is soft AND material is nylon.
int* pWig2 = T_create();
T_relate(&pWig2, rCls, &pWig); T_Name_relate(&pWig2, _T("wig2")); T_Val_relate(&pWig2, &pColor, _T("red")); T_Val_relate(&pWig2, &pColor, _T("green")); T_Val_relate(&pWig2, &pTexture, _T("soft")); T_Val_relate(&pWig2, &pMaterial, _T("nylon"));
// Create wig3
// Its texture is soft AND material is jute.
int* pWig3 = T_create();
T_relate(&pWig3, rCls, &pWig); T_Name_relate(&pWig3, _T("wig3")); T_Val_relate(&pWig3, &pTexture, _T("soft")); T_Val_relate(&pWig3, &pMaterial, _T("jute"));
// Create coat1
// Its color is red.
int* pCoat1 = T_create();
T_relate(&pCoat1, rCls, &pCoat); T_Name_relate(&pCoat1, _T("coat1")); T_Val_relate(&pCoat1, &pColor, _T("red"));
// Create coat2
// Its texture is soft AND material is cotton.
int* pCoat2 = T_create();
T_relate(&pCoat2, rCls, &pCoat); T_Name_relate(&pCoat2, _T("coat2")); T_Val_relate(&pCoat2, &pTexture, _T("soft")); T_Val_relate(&pCoat2, &pMaterial, _T("cotton"));
// Create coat3
// Its color is green AND texture is smooth, supple.
int* pCoat3 = T_create();
T_relate(&pCoat3, rCls, &pCoat); T_Name_relate(&pCoat3, _T("coat3")); T_Val_relate(&pCoat3, &pColor, _T("green")); T_Val_relate(&pCoat3, &pTexture, _T("smooth")); T_Val_relate(&pCoat3, &pTexture, _T("supple"));
// Create a relational expression
// to find things related to color AND texture
TCHAR sExpr[kNmSz_g+1] = _T("((color)) ((texture))");
// Prepare relational expression
#define aSz 255
int* pExpr[aSz+1] = {NULL};
if (X_parse_r(sExpr, pExpr, aSz)) {return;}
// Loop thru things satisfying expression
// and print the found thing's full name.
// The loop below prints the following three lines
// "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))(((material))(nylon))"
// "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))(((material))(nylon))"
// "((coat))(coat3)(((color))(green))(((texture))(smooth))(((texture))(supple))"
// Note: wig2 is printed twice because
// the query routes via the two colors of wig2: red and green
while (int* pT=X(pExpr)){
TCHAR sName[kNmSz_g+1] = _T("");
T_Name_get(pT, sName, kNmSz_g, TRUE);
TRACE(_T("%s\n"), sName);
}
// Given wig1, print its info
// Prints "((wig))(wig1)(((color))(red))"
TCHAR sName[kNmSz_g+1] = _T("");
T_Name_get(pWig1, sName, kNmSz_g, TRUE);
TRACE(_T("%s\n"), sName);
// Given wig2, print its info
// Prints "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))(((material))(nylon))"
_tcscpy(sName, _T(""));
T_Name_get(pWig2, sName, kNmSz_g, TRUE);
TRACE(_T("%s\n"), sName);
// Given wig3, print its properties/values using alternate method
// "wig3's name is wig3."
// "wig3's texture is soft."
// "wig3's material is jute."
// Loop thru wig3's relations
int* pR = pWig3;
while (*(++pR)){
// If relation is to a value if (rIs == R_Type_get(pR)){ // Get value int* pVal = R_Dest(pR); // Get value's Cls (same a property) int* pProp = T_R_Xth(pVal, rCls); // Print "thingX's propY is valX." TCHAR sTh[kNmSz_g+1] = _T(""); T_Name_get(pWig3, sTh, kNmSz_g); TCHAR sProp[kNmSz_g+1] = _T(""); T_Name_get(pProp, sProp, kNmSz_g); TCHAR sVal[kNmSz_g+1] = _T(""); T_Name_get(pVal, sVal, kNmSz_g); TCHAR sSent[3*kNmSz_g+1] = _T(""); _stprintf(sSent, _T("%s's %s is %s."), sTh, sProp, sVal); TRACE(_T("%s\n"), sSent); }
}
}
> What happens to the solution if the set of all attributes is large > but the set of attributes recorded for any entity vary from none to all?
The problems that arise from the above situation in RDM don't apply to XDb1/TDM. Received on Tue Apr 27 2004 - 07:24:14 CEST