// OData-compatible functions odata_read("/southwind/shippers") odata_read("/southwind/shippers","readresults.txt") ? filetostr("readresults.txt") cCreateString = '{"shipperid":4,"companyname":"Acme Inc.","phone":"(503) 555-1234"}' odata_create("/southwind/shippers",cCreateString) odata_read("/southwind/shippers") cUpdateString = '{"phone":"(503) 555-5678", "__olddata":{"shipperid":4}}' odata_update("/southwind/shippers",cUpdateString) odata_read("/southwind/shippers") cDeleteString = '{"shipperid":4}' odata_delete("/southwind/shippers",cDeleteString) odata_read("/southwind/shippers")
https://www.lianja.com/doc/index.php/ODATA_CREATE()
// All records that match the name/value pairs will be deleted // Here all the order_details records with an orderid of 10951 // will be deleted cDeleteString = '{"orderid":10951}' odata_delete("/southwind/order_details",cDeleteString) // OData-compatible functions odata_read("/southwind/shippers") odata_read("/southwind/shippers","readresults.txt") ? filetostr("readresults.txt") cCreateString = '{"shipperid":4,"companyname":"Acme Inc.","phone":"(503) 555-1234"}' odata_create("/southwind/shippers",cCreateString) odata_read("/southwind/shippers") cUpdateString = '{"phone":"(503) 555-5678", "__olddata":{"shipperid":4}}' odata_update("/southwind/shippers",cUpdateString) odata_read("/southwind/shippers") cDeleteString = '{"shipperid":4}' odata_delete("/southwind/shippers",cDeleteString) odata_read("/southwind/shippers")
https://www.lianja.com/doc/index.php/ODATA_DELETE()
// Use URI arguments to select the required records // Here 5 customers records are returned starting from record 10 odata_read("/southwind/customers?$skip=10&$top=5") // Call a stored procedure 'sp_fetchcustomer' in the southwind database odata_read("odata?$eval=southwind!sp_fetchcustomer('ALFKI')") // or odata_read('odata?$eval=sp_fetchcustomer("ALFKI")&$database=southwind') // Call a function 'fetchCustomer' in the 'mylibrary.prg' function library // mylibrary.prg should be in the current App or in the library odata_read('odata?$eval=mylibrary::fetchcustomer("ALFKI")') // Call fetchcustomer.prg located in the myapp App odata_read('odata?$eval=fetchcustomer("ALFKI")&$app=myapp') // Call a function 'fetchCustomer' in the 'mylibrary.prg' function library // located in the myapp App odata_read('odata?$eval=myapplibrary::fetchcustomer("ALFKI")&$app=myapp') // OData-compatible functions odata_read("/southwind/shippers") odata_read("/southwind/shippers","readresults.txt") ? filetostr("readresults.txt") cCreateString = '{"shipperid":4,"companyname":"Acme Inc.","phone":"(503) 555-1234"}' odata_create("/southwind/shippers",cCreateString) odata_read("/southwind/shippers") cUpdateString = '{"phone":"(503) 555-5678", "__olddata":{"shipperid":4}}' odata_update("/southwind/shippers",cUpdateString) odata_read("/southwind/shippers") cDeleteString = '{"shipperid":4}' odata_delete("/southwind/shippers",cDeleteString) odata_read("/southwind/shippers")
https://www.lianja.com/doc/index.php/ODATA_READ()
// All records that match the name/value pairs in __olddata will be updated // Here all the order_details records with an orderid of 10951 // will have their discount field set to 6 cUpdateString = '{"discount":6, "__olddata":{"orderid":10951}}' odata_update("/southwind/order_details",cUpdateString) // OData-compatible functions odata_read("/southwind/shippers") odata_read("/southwind/shippers","readresults.txt") ? filetostr("readresults.txt") cCreateString = '{"shipperid":4,"companyname":"Acme Inc.","phone":"(503) 555-1234"}' odata_create("/southwind/shippers",cCreateString) odata_read("/southwind/shippers") // Specify a unique name/value pair identifier to update an individual record cUpdateString = '{"phone":"(503) 555-5678", "__olddata":{"shipperid":4}}' odata_update("/southwind/shippers",cUpdateString) odata_read("/southwind/shippers") cDeleteString = '{"shipperid":4}' odata_delete("/southwind/shippers",cDeleteString) odata_read("/southwind/shippers")
https://www.lianja.com/doc/index.php/ODATA_UPDATE()
// create a new record var result = Lianja.OData_Create( "/odata/southwind/customers", { "customerid": "ABCD", ... } ); if (!result) { // Error: data cannot be created }
// read records Lianja.OData_Read( "/odata/yourdatabase/yourtable?$top=1&$skip=20&$rowid", // fetches row 21. function(status, result, args) { if (status) { // success } else { // failed } }, args);
// update a record Lianja.OData_Update( "/odata/yourdatabase/yourtable?$rowid=10", // updates record 10 { "name": "value", "amount":25.67, "date": "20140404", "__olddata" : { "amount":20.00, "date": "20140404" } }, function(status, result, args) { if (status) { // success } else { // failed } }, args);
// delete a record Lianja.OData_Delete( "/odata/yourdatabase/yourtable?$rowid=10", // deletes record 10 { "name": "value", "amount":25.67, "date": "20140404" }, function(status, result, args) { if (status) { // success } else { // failed } }, args);
https://www.lianja.com/doc/index.php/Working_with_JSON_and_JQL
When used with the Lianja Cloud Server, the URI is formed as follows:
/odata//
?&&…
e.g.
http://localhost:8001/odata/southwind/customers?$skip=10&$top=5
Or, if the Lianja Server is listening on port 80 or the ISAPI Extension for IIS is installed:
http://localhost/odata/southwind/customers?$skip=10&$top=5
Notes
When using the $sql argument, the URI does not include a table reference:
/odata/?$sql=
e.g.
http://localhost:8001/odata/southwind?$sql=select * from shippers
When using the $eval argument, the URI does not include a database or table reference:
/odata?$eval=
e.g.
http://localhost:8001/odata?$eval=time()
Note: the OData Read and Update services can be enabled/disabled in the Lianja Server Manager Security Settings.
OData Functions
When using the OData Functions from the Lianja App Builder Console or from a Lianja/VFP program (.prg), Lianja/VFP Server Page (.rsp) or JavaScript Server Page (.jssp), the URI is formed as follows:
//
?&&…
e.g.
odata_read("/southwind/customers?$skip=10&$top=5")
Exceptions
When using the $sql argument, the URI does not include a table reference:
/?$sql=
e.g.
odata_read("/southwind?$sql=select * from shippers order by companyname")
When using the $eval argument, the URI does not include a database or table reference:
/?$eval=
e.g.
odata_read("?$eval=time()")
or
odata_read("/odata?$eval=time()")
Value Selector
URIs can include a ‘value selector’ on the table.
e.g.
http://localhost/odata/southwind/customers('A*')
odata_read("/southwind/customers('A*')
The OData server will use heuristics to determine the column that ‘A*’ is referring to in the ‘customers’ table. If the column customersid exists it will be used, if that does not exist and the table is a ‘collection’ i.e. ends with an ‘s’, the ‘s’ will be removed and the column customerid will be looked up.
The column can also be specified, for example to select all customers where the ‘contactname’ starts with ‘A’:
http://localhost/odata/southwind/customers('A*', contactname)
odata_read("/southwind/customers('A*', contactname)")
The $nostrcompare argument can also be used to disable exact matching:
http://localhost/odata/southwind/customers('A', contactname)?$nostrcompare
odata_read("/southwind/customers('A', contactname)?$nostrcompare")
https://www.lianja.com/doc/index.php/OData_URIs