Javascript and C language accessing the same database

Asked

Viewed 159 times

0

I’m using a Facebook APP (and Javascript SDK) to use login on a website, in addition I must store some basic information about the user. As required by the teacher, this site was built "using the C language" (Mongoose).

The problem is: I can get user data with Javascript without any difficulty, but the database that will store it is in the C application (Sqlite3).

It would be feasible to make the Javascript part of the application have access to the same database to record user data or there is some way to take this data and use in existing C functions?

  • You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? Something needs to be improved?

2 answers

4

You can access Sqlite directly from JS, but honestly I wouldn’t do it, nobody does, so we don’t know how reliable it is. Too much risk and too little gain.

Depending on how this application will work it is reckless to make direct access to the database. I will consider that either it will run everything on the server or everything on the client and it will not have sensitive data on it. If there is interaction between client and server (where the database would be), then direct access would be reckless.

Since there will be parts in JS and parts in C use what each one can offer the best.

As there are no details of the application I can not talk much as each part will communicate, but surely this is possible somehow.

  • Thanks for the reply. After reading the answers I received, I decided to use JSON.

1

In general it is not a good idea to allow the client to access the database directly, since a malicious client can send any message to the server. For example, a client could send an SQL command to delete a table from their database or do some other trickery.

The right way to address this problem is to hold the server accountable for the database. If the client needs to make a change to the database it makes an HTTP request to the server (possibly via AJAX) and the server sends an appropriate SQL command to the database.

And don’t forget to check that the user’s request is valid! That is, if the user is logged in, they have permissions to do what they want, etc. You should never blindly trust a data or message coming from the user.

  • Thanks for the reply. After reading the answers I received, I decided to use JSON.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.