#!/bin/sh

###############################################################################
# Copyright 2002 W3C (MIT, INRIA, Keio), All Rights Reserved.
# W3C liability, trademark, document use and software licensing rules apply.
# Written by Eric Prud'hommeaux for the World Wide Web Consortium
# 
# OrderTracking1 - Billing department view
# Tests:
#   - join of Orders, Products, Customers, Addresses
# 
# Part of W3C/Rdf/test perl library test suite.
# See http://www.w3.org/1999/02/26-modules/
# $Id: OrderTracking1-alg.sh,v 1.2 2003/10/17 00:28:41 eric Exp $
###############################################################################

algae $* \
-a"
ns testDB=<http://localhost/OrderTracking#>
attach <http://www.w3.org/1999/02/26-modules/algae#dynamic> testDB:test1 (
                    class=\"W3C::Rdf::SqlDB\"
                    properties=\"OrderTracking.prop\")
ask testDB:test1 (
       ?o	testDB:Orders_id		?orderId .
       ?o	testDB:Orders_customer		?c .
       ?o	testDB:Orders_orderDate		20020907 .
       ?o	testDB:Orders_product		?p .
       ?p	testDB:Products_name		?productName .
       ?c	testDB:Customers_givenName	?first .
       ?c	testDB:Customers_familyName	?last .
       ?c	testDB:Customers_billingAddress	?billAddr .
       ?billAddr testDB:Addresses_street	?billStreet .
       ?billAddr testDB:Addresses_city		?billCity .
       ?billAddr testDB:Addresses_state		?billState
      )
collect (?orderId ?productName ?first ?last ?billStreet ?billCity ?billState) 
" \

# Table Results:
# +-------+------------+------+----------+----------------+----------+---------+
# |orderId| productName| first|      last|      billStreet|  billCity|billState|
# |-------|------------|------|----------|----------------|----------|---------|
# | "2185"|      "pool"|"Biff"|"Thompson"|"123 Elm Street"|"EdgeCity"|     "AV"|
# | "2187"| "nose ring"|"Chip"|"Thompson"|"123 Elm Street"|"EdgeCity"|     "AV"|
# | "3183"|"other ring"|"Chip"|"Thompson"|"123 Elm Street"|"EdgeCity"|     "AV"|
# +-------+------------+------+----------+----------------+----------+---------+

# SQL Query:
# SELECT Orders_0.id AS o_id,
#        Customers_0.id AS c_id,
#        Products_0.id AS p_id,
#        Products_0.name AS productName_name,
# Customers_0.givenName AS first_givenName,
# Customers_0.familyName AS last_familyName,
# Addresses_0.id AS billAddr_id,
#        Addresses_0.street AS billStreet_street,
# Addresses_0.city AS billCity_city,
# Addresses_0.state AS billState_state
# FROM Orders AS Orders_0
#      INNER JOIN Customers AS Customers_0 ON Orders_0.customer=Customers_0.id
#      INNER JOIN Products AS Products_0 ON Orders_0.product=Products_0.id
#      INNER JOIN Addresses AS Addresses_0 ON Customers_0.billingAddress=Addresses_0.id
# WHERE Orders_0.orderDate="20020907"

