Access to MySQL from Webview/Webview 2

Discussions about CSEntry
Post Reply
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Access to MySQL from Webview/Webview 2

Post by htuser »

Dear All,
I would like to know how to access to MySQL from Webview/Webview 2?
As you know it, there's a NodeJS MySQL module, but, until now, i didn't find convenient way to use it in Webview/Webview 2. Browserify should give a solution, but i didn't test it yet. Please do you have a better solution?

Thanks in advance for your help and support.
G.VOLNY, a CSProuser from Haiti, since 2004
lestcape
Posts: 37
Joined: August 27th, 2016, 1:11 pm

Re: Access to MySQL from Webview/Webview 2

Post by lestcape »

Hi htuser.

I think that what happens is that you have not fully understood how webview works and you think it is one thing when it is really another.

What you want (and I want too) is to use javascript instead of CSPro's specific purpose language. However, to do that, CSPro developers need to embed javascript in CSEntry and CSPro. In addition, they must then define a javascript framework that is responsible for managing everything that is now capable of managing the CSPro language. If you also want that javascript to have the functionalities of nodejs, since it would no longer be just any javascript, you would have to specifically embed nodejs in the project.

I think I should give you the bad news that nodejs is not embedded in the CSPro/CSEntry logic. Adding support for webview is not embedding a new programing language within CSPro, it is simply embedding a visual component that manages a mini-instance of a browser in a completely isolated and unknown context. In other words, webview was developed without having in mind that it was going to run inside CSPro and therefore it is completely unaware of any existence of a survey or a database or whatever CSPro handles. You can then add to the context of the webview all you can add in a static webpage, because here there are not a "server" side, so, you can not have a server language like can be nodejs.

Have a good day.
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Access to MySQL from Webview/Webview 2

Post by htuser »

Dear Letscape,
Thanks for your support. Your comments are, at the same time, true and, for some, false.
a)
What you want (and I want too) is to use javascript instead of CSPro's specific purpose language

I don't think it's a good idea to use Javascript instead of CSPro logic. If Javascript is far more powerful compare to CSPro logic, the latest was designed and implemented specifically for data collection and processing. Manies things that are very easy to be implemented in CSPro logic require sophisticated time consuming programming in Javascript.
Based on an old version of the language (2011) and from CSProX, http://siteresources.worldbank.org/INTS ... Report.pdf , P.62, advanced CAPI experts comparing languages stated:

A rare achievement in software, CSProX boasts a concise programming language that marries simple syntax with strong programming power. Interactive error correction is a prime example. This function relies on a compact command that checks a user-defined logical condition (if-then), issues a user-scripted error message if the condition is violated, and provides user-specified options of how to resolve the issue by providing associated buttons that point back to potentially errant answers. In CSProX, this functionality is accomplished with a few lines of code, easily half of what is required by other programs.

However, even if it is far more powerful than any existing CAPI SDK (maybe, except for BLAISE), CSPro logic have manies limitations compare to a normal programming language:
i) Procedural, not object oriented;
ii) Lack of core functions such as complete math functions;
iii) One pass compilation;
iv) etc...
So,it's better for CSProusers to have both. Right now, Javascript fulfill almost, all CSPro logic weakness.

b)
If you also want that javascript to have the functionalities of nodejs, since it would no longer be just any javascript, you would have to specifically embed nodejs in the project.
No, it's not my request. I only need a convenient way to run some NodeJS modules in Webview. There's so much workaround to do this: Webpack, Browserify. Others asked for the same. Please see this post: https://stackoverflow.com/questions/613 ... evelopment

c)
Adding support for webview is not embedding a new programing language within CSPro, it is simply embedding a visual component that manages a mini-instance of a browser in a completely isolated and unknown context
No, it's more than that. It's because CSPro Developer Team is implementing the Javascript-CSPro API. Also, if you search on the forum, you'll see (Thanks to Alex) there's way to run any Javascript codes from the Webview part of any CSPro apps and link to CSPro logic during runtime.

d)
You can then add to the context of the webview all you can add in a static webpage, because here there are not a "server" side, so, you can not have a server language like can be nodejs.
No, the CSPro Webview part can support dynamic scripting and whatever Javascript can do in a browser. Dynamic: since you can use CSPro function inside Javascript and also output Javascript code from CSPro logic during runtime. It's not exactly as it's with NodeJS, but, don't forget also, for displaying Webview, CSPro have an embedded webserver. So, it can serve dynamic pages in the webview part.

@ The CSPro development Team, does my comments are correct?

Best,
Last edited by htuser on March 23rd, 2022, 3:39 pm, edited 1 time in total.
G.VOLNY, a CSProuser from Haiti, since 2004
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Access to MySQL from Webview/Webview 2

Post by htuser »

@ Letscape,
Please read this post: https://electerious.medium.com/from-com ... 8cdd4fb662
Others have tried to transform nodeJs modules to Es modules and using them in browser/webview.
We can try this. But, in the near future, JS developers will output more and more JS modules instead of commonJs modules, so, we will be able to use them in Webview context.

I think also, in the future, CSPro designer will allow us to include more directly JS libs.
In the meantime, you should read theses posts:
viewtopic.php?f=1&t=4780
viewtopic.php?f=1&t=4763
They give the actual way of running any JS libs in the Webview part of CSPro and sharing with CSPro logic during runtime.

Best,
G.VOLNY, a CSProuser from Haiti, since 2004
lestcape
Posts: 37
Joined: August 27th, 2016, 1:11 pm

Re: Access to MySQL from Webview/Webview 2

Post by lestcape »

@htuser Suppose what you want can be done, do you honestly believe that CSPro developers added webview so their users could do something like that? Good luck trying to reinvent the wheel, because this is more less what you trying to do. The people in the link you provided also wanted to have things that was not conceived to work in that way.

Javascript is a universal and general purpose language. In most of cases not any new effort is needed to learn it (most of developers know it already), while the specific programing languages need an additional effort always. The specific languages also do not provide a set of useful libraries like the general languages have. Also an additional plus is that should be very easy port CSPro to the web if you have the logic in javascript. That are only few examples of why i wanted javascript instead of an specific language. If you don't shared the same idea with me, that is ok.

You have right in said that the CSPro language is the "server side" here, mi point was that is only the CSPro language and not anything related with javascript.

Best,
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Access to MySQL from Webview/Webview 2

Post by htuser »

do you honestly believe that CSPro developers added webview so their users could do something like that?
The people in the link you provided also wanted to have things that was not conceived to work in that way.
I don't completely know why. But, what i know, Webview and Javascript-CSPro Logic API open an universe of freedom for CSProusers. Sometimes, developers doesn't have in mind the global scope of theirs systems. For example, can you imagine that, Android was initially designed as a Camera OS ? (https://www.pcworld.com/article/451350/ ... ra-os.html) And, now...?
Also an additional plus is that should be very easy port CSPro to the web if you have the logic in javascript.
Thanks to Webassembly! If the developer team had sufficient resources, they could give us JS/WASM libs of the engine and others necessary components, so we can always have CSPro Apps to the Web even with CSPro logic. I think it's a dream, but with this, we can also have standalone desktop and mobile apps based on CSPro.
a) The CSPro Runtime engine as a Web apps that can open directly any *.pen files on the server and serve questionnaires on the Web;
b) Output directly a standalone webpackage of any CSPro apps from the CSPro Designer where CSPro Logic is wrapped to JS/WASM and Dictionary/Form files to HTML/CSS.
That are only few examples of why i wanted javascript instead of an specific language. If you don't shared the same idea with me, that is ok.
I want the support of both CSPro Logic and Javascript.
You have right in said that the CSPro language is the "server side" here, mi point was that is only the CSPro language and not anything related with javascript.
It's not a client server-system... I wrote that, because, for displaying HTML/CSS/Javascript in Webview, CSPro use a local web server, so we can, not only display static, but also dynamic webpages. It's because of the Javascript-CSPro API. With it, we can output dynamic frontend during runtime.
Best,
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply