schliack Posted September 15, 2023 Share Posted September 15, 2023 Hi there, is there a way to work with the HTTPRequestInfo from Servermodule (UniGUIServerModuleHTTPCommand) in the mainmodule ? i want to use urls to check Data and give a result back. So i tried to use procedure TUniServerModule.UniGUIServerModuleHTTPCommand( ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); begin if ARequestInfo.URI='/api/yealink' then test( ARequestInfo); end; in the Servermodule and the funktion test in the mainmodule. But then the mainmodule will not be created and i cant use the database Componnents in the Mainmodule cause there ist no safe session. This will work when there is a little bit time between the calls to unigui. but if there are some at the same time, then there are conflicts to the databasecomponents and i get a systemerror. Any Ideas about that ? Cheers and thanks Andreas Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 15, 2023 Share Posted September 15, 2023 Hello, And to be more specific? Quote Link to comment Share on other sites More sharing options...
schliack Posted September 15, 2023 Author Share Posted September 15, 2023 i want to use urls to check Data and give a result back (API-Server) Every datapoint is called via URL (/api/yealink , /api/shelly , /api/placetel) and parmeters like authkey .... and sometimes jsondata in the Body. So i tried to use procedure TUniServerModule.UniGUIServerModuleHTTPCommand( ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); begin if ARequestInfo.URI='/api/yealink' then test( ARequestInfo); end; in the Servermodule and the funktion test in the mainmodule. But then the mainmodule will not be created and i cant use the database Componnents in the Mainmodule cause there ist no safe session. This will work when there is a little bit time between the calls to unigui. but if there are some at the same time, then there are conflicts to the databasecomponents and i get a systemerror. Any Ideas about that ? Cheers and thanks Andreas Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 15, 2023 Share Posted September 15, 2023 11 minutes ago, schliack said: Any Ideas about that ? If I understand you correctly, then you can dynamically create a connection and queries to the database. Quote Link to comment Share on other sites More sharing options...
schliack Posted September 15, 2023 Author Share Posted September 15, 2023 yes, it works while single calls , but if there simultan comming calls, the creation crashes ... So .. i read that on each call (session) the mainmodule is created and it is only für the session where i can create the database components. But the mainmodule is only created when i not use TUniServerModule.UniGUIServerModuleHTTPCommand. but i need the TIdHTTPRequestInfo for working with ... Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 15, 2023 Share Posted September 15, 2023 10 minutes ago, schliack said: yes, it works while single calls , but if there simultan comming calls, the creation crashes ... What database are you using? How do you create connections? Quote Link to comment Share on other sites More sharing options...
schliack Posted September 15, 2023 Author Share Posted September 15, 2023 I use devart unidac and MS SQL / Connection is in datamodule (will be created on function call ( test( ARequestInfo)) and query will bee created on Call) like this: datamod := Tdb1_frm.create(nil); getcon_sql := TUniQuery.create(nil); getcon_ds := TUniDataSource.create(nil); getcon_sql.Connection := datamod.sqlcon; getcon_ds.DataSet := getcon_sql; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 15, 2023 Share Posted September 15, 2023 1 minute ago, schliack said: Connection is in datamodule You can create connections and queries to the database on the server module. Quote Link to comment Share on other sites More sharing options...
schliack Posted September 15, 2023 Author Share Posted September 15, 2023 but they are for each session (call) save ? I think they will also crash when there are calls at the same time Quote Link to comment Share on other sites More sharing options...
schliack Posted September 15, 2023 Author Share Posted September 15, 2023 I had read a lot here ... all say only the mainmodule will work with sessions and this page http://www.unigui.com/doc/online_help/sessions.htm also Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted September 15, 2023 Administrators Share Posted September 15, 2023 Hello, You need a dedicated connection for each HTTP call. There are no sessions here, so you need to manage everything yourself. You must create a DataModule (containing your connection and queries) instance each time a request is received and destroy it upon completion of the request. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 15, 2023 Share Posted September 15, 2023 2 hours ago, Sherzod said: You can create connections and queries to the database on the server module. 2 hours ago, Sherzod said: If I understand you correctly, then you can dynamically create a connection and queries to the database. Quote Link to comment Share on other sites More sharing options...
Skyp Posted October 12, 2023 Share Posted October 12, 2023 On 9/15/2023 at 6:55 PM, schliack said: I use devart unidac and MS SQL / Connection is in datamodule (will be created on function call ( test( ARequestInfo)) and query will bee created on Call) like this: datamod := Tdb1_frm.create(nil); getcon_sql := TUniQuery.create(nil); getcon_ds := TUniDataSource.create(nil); getcon_sql.Connection := datamod.sqlcon; getcon_ds.DataSet := getcon_sql; Hi. Not long ago I gave a detailed answer on connecting to a DBMS and working with connection: (it example) remember one connection can only return one set of data at a time, use a connection pool Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.