Esempio n. 1
0
<?php

/*
* By Silvio Garbes
* Em: 10/11/2015
*/
require_once "../proxieNorthwind.php";
$proxy = new NorthwindEntities();
$response = $proxy->Execute("Customers");
foreach ($response->Result as $customer) {
    echo $customer->CompanyName . ": " . $customer->ContactName . "</br>";
}
$response = $proxy->Customers()->Filter("CustomerID eq 'ALFKI'")->Expand('Orders')->Execute();
$customer = $response->Result[0];
echo count($customer->Orders);
Esempio n. 2
0
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
require_once 'NorthwindEntities.php';
require_once 'urldef.php';
echo "<h3>Sample3: List all cutomer's ID in NorthWind DB with USA as Country and associated Order's ID using LoadProperty and Server Side paging</h3>";
try {
    $svc = new NorthwindEntities(NORTHWIND_SERVICE_URL);
    $query = $svc->Customers()->filter("Country eq 'USA'");
    $customerResponse = $query->Execute();
    $nextCustomerToken = null;
    do {
        if ($nextCustomerToken != null) {
            $customerResponse = $svc->Execute($nextCustomerToken);
        }
        foreach ($customerResponse->Result as $customer) {
            echo '<br/>CustomerID: ' . $customer->CustomerID . "<br/>";
            $nextOrderToken = null;
            echo "<br/>Associated Orders <br/>";
            echo "-----------------------<br/>";
            do {
                $ordersResponse = $svc->LoadProperty($customer, 'Orders', $nextOrderToken);
                foreach ($customer->Orders as $order) {
                    echo "     " . $order->OrderID . "<br/>";
Esempio n. 3
0
 *  provided that the following  conditions are met:
 *   - Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *   - Neither the name of Persistent Systems Limited nor the names of its contributors
 *     may be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
require_once 'NorthwindEntities.php';
require_once 'urldef.php';
echo "<h3>Sample4: Usage of Row Count</h3>";
try {
    $svc = new NorthwindEntities(NORTHWIND_SERVICE_URL);
    echo "<br/>Total number of Customers:" . $svc->Customers()->Count();
    echo "<br/>Total number of Customers with USA as Country:" . $svc->Customers()->filter("Country eq 'USA'")->Count();
} catch (DataServiceRequestException $ex) {
    echo 'Error: while running the query ' . $ex->Response->getQuery();
    echo "<br/>";
    echo $ex->Response->getError();
}
Esempio n. 4
0
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
require_once 'NorthwindEntities.php';
require_once 'urldef.php';
echo "<h3>Sample6: Update the CompanyName of customer entity added in Sample5 to 'Channel8'</h3>";
try {
    $svc = new NorthwindEntities(NORTHWIND_SERVICE_URL);
    $response = $svc->Customers()->filter("CustomerID eq 'CHAN9'")->Execute();
    if (count($response->Result)) {
        $customer = $response->Result[0];
        $customer->CompanyName = 'Channel8';
        $svc->UpdateObject($customer);
        $svc->SaveChanges();
        echo 'Company name of Customer with ID CHAN9 has been updated to Channel8';
    } else {
        echo 'Customer with CustomerID CHAN9 not found';
    }
} catch (ODataServiceException $e) {
    echo "Error:" . $e->getError() . "<br>" . "Detailed Error:" . $e->getDetailedError();
} catch (InvalidOperation $e) {
    echo $e->getError();
}
Esempio n. 5
0
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
require_once 'NorthwindEntities.php';
require_once 'urldef.php';
echo "<h3>Sample2: List all cutomer's ID in NorthWind DB with USA as Country and associated Order's ID using expand option and Server Side paging</h3>";
try {
    $svc = new NorthwindEntities(NORTHWIND_SERVICE_URL);
    $query = $svc->Customers()->filter("Country eq 'USA'")->Expand('Orders');
    $customerResponse = $query->Execute();
    $nextCustomerToken = null;
    do {
        if ($nextCustomerToken != null) {
            $customerResponse = $svc->Execute($nextCustomerToken);
        }
        foreach ($customerResponse->Result as $customer) {
            echo '<br/>CustomerID: ' . $customer->CustomerID . "<br/>";
            $nextOrderToken = null;
            $firstTime = true;
            $ordersResponse;
            echo "<br/>Associated Orders <br/>";
            echo "-----------------------<br/>";
            do {
                $orders = array();
Esempio n. 6
0
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
require_once 'NorthwindEntities.php';
require_once 'urldef.php';
echo "<h3>Sample1: List all cutomer's ID in NorthWind DB with USA as Country using Server Side Paging and print the number of coustmers using inline count</h3>";
try {
    $svc = new NorthwindEntities(NORTHWIND_SERVICE_URL);
    $query = $svc->Customers()->filter("Country eq 'USA'")->IncludeTotalCount();
    $customersResponse = $query->Execute();
    echo "<br/>";
    echo "Number of Customers with Country as USA:" . $customersResponse->TotalCount() . "<br/>";
    echo "CustomerID" . "<br/>";
    echo "----------" . "<br/>";
    $nextCustomerToken = null;
    do {
        if ($nextCustomerToken != null) {
            $customersResponse = $svc->Execute($nextCustomerToken);
        }
        foreach ($customersResponse->Result as $customer) {
            echo $customer->CustomerID . "<br/>";
        }
    } while (($nextCustomerToken = $customersResponse->GetContinuation()) != null);
} catch (DataServiceRequestException $ex) {
Esempio n. 7
0
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
require_once 'NorthwindEntities.php';
echo "<h3>Sample13: Shows how to use projection through select query option</h3>";
try {
    $svc = new NorthwindEntities();
    $query = $svc->Customers()->filter("Country eq 'USA'")->Select('CustomerID,CompanyName');
    $customersResponse = $query->Execute();
    foreach ($customersResponse->Result as $customer) {
        echo "CustomerID:" . $customer->CustomerID . "<br/>";
        echo "Company Name:" . $customer->CompanyName . "<br/>";
        echo "Country:" . $customer->Country . "(This will be null as we selected only CustomerID and CompanyName)" . "<br/>";
        echo "----------" . "<br/>";
    }
} catch (DataServiceRequestException $ex) {
    echo 'Error: while running the query ' . $ex->Response->getQuery();
    echo "<br/>";
    echo $ex->Response->getError();
} catch (ODataServiceException $e) {
    echo "Error:" . $e->getError() . "<br>" . "Detailed Error:" . $e->getDetailedError();
}