PDA

View Full Version : Working with OData



barrymavin
2017-01-27, 04:05
Lianja Cloud Server supports OData-compatible data access.

The Server handles ODBC connections as well as HTTP requests using OData URIs. In the following article I will show you how to use Lianja Cloud Server with OData URIs that will allow you to perform CRUD (Create, Read, Update and Delete) operations on your data.

Making OData requests from jQuery and/or the Lianja HTML5 Client in a Web App is extremely straightforward and simple.

Unlike other OData implementations, Lianja Cloud Server OData services does not require any server-side configuration of web services.

http://www.lianja.com/resources/blog/39-coding-tips/379-working-with-odata-in-lianja-cloud-server-

You can use Lianja cloud server odata calls to perform CRUD operations on virtual tables too so this functionality is not limited to native Lianja data; MSSQL, MySQL, PostgreSQL, Oracle and others are all supported.

Let me just emphasize again. Unlike other OData implementations, Lianja Cloud Server OData services does not require any server-side configuration of web services.

josipradnik
2017-01-27, 13:38
Hi Barry,

After successful playing with Southwind, I've tried with MS SQL and virtual table.
I made ODBC (32 / windows authentification) and got 19820 records in vt_customers of database cloudlibtest and I see them in grid.

Demo example_webvirtualtables works great too with this VT.

I cant get it in Chrome:
http://127.0.0.1/odata/cloudlibtest/vt_customers

Error:

The requested page was not found
The requested URL /odata/cloudlibtest/vt_customers was not found on this server.

http://127.0.0.1/odata/southwind/customers works as expected
(the only thing I dont know how to open/use the result of $format=img)

I have tried with wwwroot settings in Lianja SQL Server Manager:
C:\lianja\sqlserver\wwwroot\ (from the blog screenshot)
and with
C:\lianja\cloudserver\tenants\public\wwwroot\
no avail.

Josip

yvonne.milne
2017-01-30, 09:26
Hi Josip,

Check the troubleshooter here: http://www.lianja.com/doc/index.php/Troubleshooting_example_webvirtualtables#Test_Web_ App

That is for the example_webvirtualtables App, but will also apply to accessing the vt_customers vt via direct OData URIs.

Regards,

Yvonne

josipradnik
2017-01-30, 13:39
I can't get odata to work in Chrome with virtual table and MS SQL Server 2008 / ODBC DSN client 10.0

I passed all troubleshooting points but nothing improved (deploying stuff is not applicable because it is not an app, but Chrome).

The same happened if I use SQL Server authentication.

I was expecting that if I can get vt_customers to be shown in the grid (Data ws) then everything is OK with my DSN, MS SQL Server connection and permissions.
Also, if I can get http://127.0.0.1/odata/southwind/customers to work in Chrome, then all is OK with Cloud Server.
That's why I am puzzled.

Something bothers me: what wwwroot need to be set?
In my Lianja Server Manager I initially found:

C:\lianja\cloudserver\tenants\public\wwwroot\
and in the blog it is

C:\lianja\sqlserver\wwwroot\
(have tried both. It doesn't matter for "odataing" southwind)

I wonder when doubleclicking on vt_customers in Data ws, from where (wwwroot) I get the records?
and from where in Chrome if I "odata" southwind or cloulibtest?

barrymavin
2017-01-30, 20:13
Using OData to query MSSQL is working fine for me.

1402

The example shows how to use it with Lianja SQL Server.

wwwroot should be set to C:\lianja\cloudserver\tenants\public\wwwroot\

Remember also that you have the odata_create(), odata_read(), odata_update() and odata_delete() functions that can be used in both programs and rsp pages. These functions provide an OData abstraction above the target database SQL syntax. e.g. you can fetch MSSQL data using $limit (see below).

1403

These examples were executed using the final release of Lianja 3.2 so try with that when it is available of download.

With regards to your question about $format=img, if you select an image field from a table then it will be output as an IMG tag with embedded data encoding so that you can insert this into the DOM to fetch and display an image.

1404

By specifying memo fields you can also perform CRUD operations on JSON data.

Clearly there is a lot of power in this and it demonstrates how you can use Lianja Cloud Server to handle OData CRUD operations from other third party UI frameworks if that is a requirement. To use these OData functions on the client (no server side coding required) you should include the following files in your App:

/library/jquery-1.10.2/jquery-1.10.2.min.js
/library/LianjaWebFramework/LianjaCloudDataServices.js

This provides core javascript client side functionality for working with the LIanja Cloud Server. It is not required with Lianja Apps as they have the full framework included.

You can read and study the source code to see what functions are available in LianjaCloudDataServices.js

I keep mentioning over and over but I will do so again. Lianja OData as implemented in Lianja Cloud Server does not require any server side coding or web services and it can be used to perform CRUD operations on all native Lianja databases and all major SQL databases i.e. MSSQL, PostGreSQL, MySQL, Oracle and others.