Delphi EMS FireDAC: How to pass parameter from client to server using EMS? - sql-server

I am working on the simple client server application using EMS (i.e: for future iOS application) in Delphi.
On the client unit, I have EMSProvider and EMSFireDACClient which fetches data from a Database (MSSQL) through a Datasource.
On the server unit, I have FDConnection and TFDQuery which deals with my Database. So far everything is working fine.
Question: Now I need to pass some parameters from client to the server and that fetches the result data. How should I do using EMS? Any functions or procedures available in EMS?
Regarding source code, everything was handled by corresponding components. So coding part is very less.
Thanks in advance.

An EMS call is like a REST call. You can pass further URL parameters both in the path (handled directly) -- see the default implementation of getting items by ID) and as extra query params. Those are in the request object. To pass them, use a custom Endpoint in the client.
Here is some more info:
Server declaration:
[ResourceSuffix('{item}')]
procedure GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
Server implementation:
procedure TNotesResource1.GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
LItem: string;
begin
LItem := ARequest.Params.Values['item'];
...
Client configuration for endpoint:
object BackendEndpointGetNote: TBackendEndpoint
Provider = EMSProvider1
Auth = BackendAuth1
Params = <
item
Kind = pkURLSEGMENT
name = 'item'
Options = [poAutoCreated]
end>
Resource = 'Notes'
ResourceSuffix = '{item}'
end
Client call:
BackendEndpointGetNote.Params.Items[0].Value := AID;
BackendEndpointGetNote.Execute;
Hope this helps.

Related

Report to find objects of a segw project and put them on a request

I'm new in SAP and during my practicing I came up with a 'problem': when I was transporting my project to another system I had to manually include some objects that were in other requests.
So now I'm trying to make a report to join all the objects related to a segw project in a single request. My idea is passing the Project ID or name to my report find the objects, create a request and put all of them into it.
I've already found something. When creating a segw project and generate it, the request has:
- Class (ABAP objects) with the DPC and MPC
- SAP Gateway Business Suite Enablement - Model
- SAP Gateway BSE - Service Builder Project
- SAP Gateway Business Suite Enablement - Service
I've found two tables that help me to get DPC and MPC objects:
TMDIR, VSEOCLASS.
Am I in the right path? Is there a way to find all related objects to the project or I'll need to find them separately like the DPC and MPC I've already found?
Thanks!
Assuming all your SEGW objects reside in a single package which is usually the case when you create SEGW project from scratch:
DATA: l_trkorr TYPE trkorr,
l_package TYPE devclass VALUE 'ZSEGW_P'.
cl_pak_package_queries=>get_all_subpackages( EXPORTING im_package = l_package
IMPORTING et_subpackages = DATA(lt_descendant) ).
INSERT VALUE cl_pak_package_queries=>ty_subpackage_info( package = l_package ) INTO TABLE lt_descendant.
SELECT pgmid, object, obj_name FROM tadir
INTO TABLE #DATA(lt_segw_objects)
FOR ALL ENTRIES IN #lt_descendant
WHERE devclass = #lt_descendant-package.
DATA(instance) = cl_adt_cts_management=>create_instance( ).
LOOP AT lt_segw_objects ASSIGNING FIELD-SYMBOL(<fs_obj>).
TRY.
instance->insert_objects_in_wb_request( EXPORTING pgmid = <fs_obj>-pgmid
object = <fs_obj>-object
obj_name = CONV trobj_name( <fs_obj>-obj_name )
IMPORTING result = DATA(result)
request = DATA(request)
CHANGING trkorr = l_trkorr ).
CATCH cx_adt_cts_insert_error.
ENDTRY.
ENDLOOP.
This snippet creates transport request with number l_trkorr and as soon as this var is not changed put all remainign objects in the same request.
WARNING: this will not work if the objects are locked (in another request) and will give you cx_adt_cts_insert_error exception. There is no way to unlock objects programmatically, only via SE03 tool.

Best Practice to pass *gorm.db instance in a custom handler in go http

I am creating a custom web handler to handle my routes in an web application.
The handler is
type CustomHandler struct{
Db *gorm.DB
}
Then a receiver function:
func (h CustomHandler) Index() http.Handler {
return http.handlerFunc(w http.ResponseWriter,r *http.Request){
//Some code
//use h.Db.Find() ,etc.
})
I am passing this to my router as
//In package
customHandler := &CustomHandler{*gormInstance} //I've already got the instance
router.Handle("/someroute", customHandler.index() )
But a problem with this is gorm.DB instance, being a pointer will mutate once it pass through a route during one request.
Do I have to generate different copies of the initial gorm instance? If so, How can I pass them through each routes on each requests?
According to Gorm documentation :
All Chain Methods will clone and create a new DB object (shares one
connection pool), GORM is safe for concurrent use by multiple
goroutines.
Gorm creates clones when it needs to automatically, there is no need to handle this manually. For more information check this page in the documentation: http://gorm.io/docs/method_chaining.html

Play-slick - Is default.db required?

I'm working on an application using Play and Slick. This app requires access to (at least) two databases and this is working fine when one is defined as default and other is named. Eg.,
db.default.driver = "com.mysql.jdbc.Driver"
db.default.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"
I can then happily access each db as follows
DB.withSession { implicit session => ??? }
DB("db2").withSession { implicit session => ??? }
However, this doesn't really make sense as there is no reason DB1 should be the default. The DBs contain different types of data, neither is the default, both are important. What I would like is:
db.db1.driver = "com.mysql.jdbc.Driver"
db.db1.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"
Play-scala barfs at this thought. It needs a default db driver and URL and it needs to be able to connect to it.
Anyone know anyway to change this behaviour or to trick play into thinking it has a default?
UPDATE
To be clear, I've greped my code to ensure that I'm not using DB.withSession anywhere. That is, every time I create a session I use DB("db1").withSession or DB("db2").withSession. However, when I run my test, I still get an exception:
Caused by: Configuration error: Configuration error[Slick error : jdbc driver not defined in application.conf for db.default.driver key]
Something somewhere is trying to load the default config.
Default is just a name, with some convenience functions (withSession and withTransaction without name), so, no you do not need to have a default connection if it does not fit your project.

node.js, restify - handle a parameter of type array

I have a node.js server with restify. I want to send it a get request that has an array of names in it. I think the request should look like this (but I am not sure about it):
/users?names=bob,joe,michael,joey
Is this query correct?
How do I get the names I send on the node.js server?
The W3C recommendation is that one key can be repeated multiple times with multiple values:
GET /users?names=bob&names=joe&names=michael&names=joey
Good systems will be designed to handle this format of data and be able to recognize multiple keys to group them within an array.
You do not need to specify query variables in your route:
// perform: GET /users?names=bob&names=joe&names=michael&names=joey
server.get('/users', function (req, res) {
// All your query vars from the GET request are in req.query
res.json(req.query.names);
});

web service to deserilize JSON http request? and pass to stored Procedure to retrieve data from SQL server

I'm a newbie to VB.net. Right now I have a task to create a web service to receive client-side app's http request(with rpc={json data} in the end), deserilize it and put he parameter in stored Procedure in order to retrieve data from sql server.
The procedure query and client-side's app are already there and the return data to client-side app is JSON too.
Any help would be greatly appreciated. Please give me some suggestion or idea.
You can use dll like newtonsoft.dll for handling json data
In asp.net also you can handle json data using following namespace.
System.Web.Script.Serialization
Dim jsn As JavaScriptSerializer = New JavaScriptSerializer() // Define JavaScriptSerializer
// data is object which contains json data
Dim objjsn As Object = jsn.DeserializeObject(data) //Deserialize json
Dim args As Array = objjsn("users") // access json data

Resources