Untitled

mail@pastecode.io avatar
unknown
c_cpp
15 days ago
1.9 kB
2
Indexable
Never
// Complete this function
void displayOrderStatus(Connection *conn, int orderId, int customerId)
{
    Statement *stmt = nullptr;

    stmt = conn->createStatement("BEGIN customer_order(:1, :2); END;");
    stmt->setInt(1, customerId);
    stmt->registerOutParam(2, Type::OCCIINT, sizeof(orderId));

    stmt->executeUpdate();

    orderId = stmt->getInt(2);

    if (orderId == 0)
    {
        cout << "Order ID is not valid." << endl;
    }
    else
    {
        string status;
        stmt = conn->createStatement("BEGIN display_order_status(:1, :2); END;");
        stmt->setInt(1, orderId);
        stmt->registerOutParam(2, Type::OCCISTRING, sizeof(status));

        stmt->executeUpdate();

        status = stmt->getString(2);

        if (status.empty())
        {
            cout << "Order does not exist." << endl;
        }
        else
        {
            cout << "Order is " << status << endl;
        }
    }

    conn->terminateStatement(stmt);
}

// Complete this function
void cancelOrder(Connection *conn, int orderId, int customerId)
{
    Statement *stmt = nullptr;
    int cancelStatus;
    // cancel_order(orderId IN NUMBER, cancelStatus OUT NUMBER)

    stmt = conn->createStatement("BEGIN cancel_order(:1, :2); END;");
    stmt->setInt(1, orderId);
    stmt->registerOutParam(2, Type::OCCIINT, sizeof(cancelStatus));

    stmt->executeUpdate();

    cancelStatus = stmt->getInt(2);

    cout << cancelStatus << endl;

    switch (cancelStatus)
    {
    case 0:
        cout << "Order ID is not valid." << endl;
        break;
    case 1:
        cout << "The order has been already canceled." << endl;
        break;
    case 2:
        cout << "The order is shipped and cannot be canceled." << endl;
        break;
    case 3:
        cout << "The order is canceled successfully." << endl;
        break;
    default:
        break;
    }

    conn->terminateStatement(stmt);
}
Leave a Comment