Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Modelling Pizza Orders with XDb1

Re: Modelling Pizza Orders with XDb1

From: Neo <neo55592_at_hotmail.com>
Date: 15 Apr 2004 21:16:43 -0700
Message-ID: <4b45d3ad.0404152016.119dec75@posting.google.com>

> ... Pizza orders. The first order consists of a small, thin pizza 
> with mozzarella and veggies. The second order consists of a large, 
> thick pizza with mozzarella, parmesan, sausage, pepperoni, 
> black olives and four cokes.

The following code models the above data programmatically via XDb1's API. The code also shows how to find things via relational expressions.

void Example108()
{
  // Create classes
    // Create order

      int* pOrder = T_create();
      T_relate(&pOrder, rCls, &pThing_g);
      T_Name_set(&pOrder, _T("order"));

    // Create pizza
      int* pPizza = T_create();
      T_relate(&pPizza, rCls, &pThing_g);
      T_Name_set(&pPizza, _T("pizza"));

    // Create size
      int* pSize = T_create();
      T_relate(&pSize, rCls, &pThing_g);
      T_Name_set(&pSize, _T("size"));

    // Create crust
      int* pCrust = T_create();
      T_relate(&pCrust, rCls, &pThing_g);
      T_Name_set(&pCrust, _T("crust"));

    // Create cheese
      int* pCheese = T_create();
      T_relate(&pCheese, rCls, &pThing_g);
      T_Name_set(&pCheese, _T("cheese"));

    // Create topping
      int* pTopping = T_create();
      T_relate(&pTopping, rCls, &pThing_g);
      T_Name_set(&pTopping, _T("topping"));

    // Create drink
      int* pDrink = T_create();
      T_relate(&pDrink, rCls, &pThing_g);
      T_Name_set(&pDrink, _T("drink"));

    // Create drinkType
      int* pDrinkType = T_create();
      T_relate(&pDrinkType, rCls, &pThing_g);
      T_Name_set(&pDrinkType, _T("drinkType"));

    // Create qty
      int* pQty = T_create();
      T_relate(&pQty, rCls, &pThing_g);
      T_Name_set(&pQty, _T("qty"));

  // Create order 1
    int* pOrder1 = T_create();
    T_relate(&pOrder1, rCls, &pOrder);
    T_Name_set(&pOrder1, _T("order 1"));

    // Create a pizza

      int* pAPizza = T_create();
      T_relate(&pAPizza, rCls, &pPizza);


// Relate pizza is part of order 1
T_relate(&pAPizza, rAsm, &pOrder1);
// Set the pizza's size is thin
T_Val_set(&pAPizza, &pSize, _T("small"));
// Set the pizza's crust is thin
T_Val_set(&pAPizza, &pCrust, _T("thin"));
// Set the pizza's cheese is mozzarella
T_Val_set(&pAPizza, &pCheese, _T("mozzarella"));
// Set the pizza's topping is veggies
T_Val_set(&pAPizza, &pTopping, _T("veggies"));

  // Create order 2
    int* pOrder2 = T_create();
    T_relate(&pOrder2, rCls, &pOrder);
    T_Name_set(&pOrder2, _T("order 2"));

    // Create a pizza

      pAPizza = T_create();
      T_relate(&pAPizza, rCls, &pPizza);


// Relate the pizza is part of order 2
T_relate(&pAPizza, rAsm, &pOrder2);
// Set the pizza's size is large
T_Val_set(&pAPizza, &pSize, _T("large"));
// Set the pizza's crust is thick
T_Val_set(&pAPizza, &pCrust, _T("thick"));
// Set the pizza's cheese is mozzarella
T_Val_set(&pAPizza, &pCheese, _T("mozzarella"));
// Set the pizza's cheese is mozzarella
T_Val_set(&pAPizza, &pCheese, _T("parmesan"));
// Set the pizza's topping is sausage
T_Val_set(&pAPizza, &pTopping, _T("sausage"));
// Set the pizza's topping is pepperoni
T_Val_set(&pAPizza, &pTopping, _T("pepperoni"));
// Set the pizza's topping is black olives
T_Val_set(&pAPizza, &pTopping, _T("black olives")); // Create a drink int* pADrink = T_create(); T_relate(&pADrink, rCls, &pDrink);
// Relate the drink is part of order 2
T_relate(&pADrink, rAsm, &pOrder2);
// Set the drink's drinkType is coke
T_Val_set(&pADrink, &pDrinkType, _T("coke"));
// Set the drink's qty is 4
T_Val_set(&pADrink, &pQty, _T("4"));

  // Create a relational expression string to find order 1     TCHAR str[kNmSz_g+1] = _T("order (pizza thin veggies)");

  // Prepare relational expression str
    #define aSz 255
    int* pExpr[aSz+1] = {NULL};
    if (Q_Str_parse_r(str, pExpr, aSz)) {return;}     if (Q_SymStr_parse_r(pExpr)) {return;}

  // Loop thru things satisfying expression     while (int* pT=X(pExpr)){

      TCHAR sOrder[kNmSz_g+1] = _T("");
      T_Name_get(pT, sOrder, kNmSz_g);
      TRACE(_T("%s\n"), sOrder);

    }
} Received on Thu Apr 15 2004 - 23:16:43 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US