I'm currently trying to use MySQL from server side Javascript
framework and I face two issues:
1/ the MySQL binding works in an asynchronous way. But this can be
annoying if you want for example to make a MySQL request into a
command code : as MySQL query is asynchronous, you cannot directly
send a 'command response' to the command sent by the client.
Is there any way to force the use of MySQL binding in an synchronous
way and thus avoid the need to send a 'command response' immediatly,
plus a second raw just after which contains the result of my query.
2/ When i run a query returning at least one field with an empty
varchar, I get an error: " ERROR (17) : Mysql binary mode field
corrupt ".
Notes:
- my APE server is a v1.00
- my MySQL database (v5.1.41-3) is running on the same host as the APE
server
- DB is using "utf8_general_ci" as charset (?)
- the field leading to the error is of type varchar(150), not null but
containing an empty string
- when the same field contains a non-empty string, everything behaves
well.
Any idea ?
Many thanks in advance.
Nouk²
var sqlFinished = false;
var sqlResult = null;
sql.query(statement, function(result){
sqlResult = result;
sqlFinished = true;
})
while(sqlFinished === false)
{
//waiting loop
}
//now work on sqlResult
Ugly but could work. However I would advise against going synchronous,
in my experience js is made to work asynchronously, and every time I
tried to went against that it ended up badly :)
For your second question I did not have the issue myself yet, so
cannot really help, sorry.
Cadrach
On Jan 15, 11:46 am, nouknouk <noukn...@gmail.com> wrote:
> Nobody ?
--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to ape-p...@googlegroups.com
To unsubscribe from this group, send email to
ape-project...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/
Going synchoneously on aAPE server will just stop everithing else until sql request ends, you'll exeriment lags on all other responses and messages.
For your first question, what you could do is, inside your event or
command on the server:
var sqlFinished = false;
var sqlResult = null;
sql.query(statement, function(result){
sqlResult = result;
sqlFinished = true;
})
while(sqlFinished === false)
{
//waiting loop
}
//now work on sqlResult
Ugly but could work. However I would advise against going synchronous,
in my experience js is made to work asynchronously, and every time I
tried to went against that it ended up badly :)
For your second question I did not have the issue myself yet, so
cannot really help, sorry.
while(sqlFinished === false)
{
//waiting loop
}
is horrible, this could use up to 100% cpu only for one user, able to
slow down your whole server just for one single SQL request. there's a
reason why there is no sleep-function in javascript.
get used to asynchronous handling. send the cmd result to the client
when it is available and make the client work with this. in my
rails+ape+mysql-example you'll find a way how you could this, take a
look at
it:http://flip.netzbeben.de/2010/01/howto-create-a-web-chat-with-ape-rails-and-mysql/
flip
Cadrach
On Jan 15, 3:41 pm, flipkick <flipk...@gmail.com> wrote:
> you don't want to use synchronous requests because this will block your
> whole module with all users until the sql for one user has returned.
> and in the idea of cadrach for instance:
>
> while(sqlFinished === false)
> {
> //waiting loop
>
> }
>
> is horrible, this could use up to 100% cpu only for one user, able to
> slow down your whole server just for one single SQL request. there's a
> reason why there is no sleep-function in javascript.
>
> get used to asynchronous handling. send the cmd result to the client
> when it is available and make the client work with this. in my
> rails+ape+mysql-example you'll find a way how you could this, take a
> look at
> it:http://flip.netzbeben.de/2010/01/howto-create-a-web-chat-with-ape-rai...
You can delay any command using "return -2" :
Ape.registerCmd("foo", true, function(params, cmd) {
example_async(function() {
cmd.sendReponse("ASYNC_REPLY", {"foo":"bar"}); // (or
cmd.user.pipe.sendRaw)
});
return -2.
});
Le 15/01/10 16:33, Cadrach a �crit :
Le 15/01/10 16:53, Anthony Catel a �crit :
you don't want to use synchronous requests because this will block your whole module with all users until the sql for one user has returned.
and in the idea of cadrach for instance:
is horrible, this could use up to 100% cpu only for one user, able to slow down your whole server just for one single SQL request.
there's a reason why there is no sleep-function in javascript.
get used to asynchronous handling.
Maybe what we should have asked is: Why having the SQL request
processed and the result sent on another raw is an issue for you?
Just for information :
You can delay any command using "return -2" :
there's a reason why there is no sleep-function in javascript.
Because historically, Javascript was only designed for browser needs ; we are not in the same context here.
get used to asynchronous handling.
Being used to develop networked apps, that's not the problem here.
2010/1/15 Anthony Catel <a.c...@weelya.com>
You can delay any command using "return -2" :Many thanks, this is the tip I was waiting for :-)
that's not what i meant, using sleep in a browser app makes no sense just as in your javascript server side ape module.
lol, pretty contradictory, you don't want to use the asynchronous model but say thanks for the tip do to use it.
2010/1/15 flipkick <flip...@gmail.com>
that's not what i meant, using sleep in a browser app makes no sense just as in your javascript server side ape module.
sleep is a very common function available in most of programmting languages. sleep has never been a 'non sense', and there's not reason for Javascript to be an exception (but that's another debate). In the current context, it would have been usefull as the best workaround to do 'active wait' without burning CPU resources.
lol, pretty contradictory, you don't want to use the asynchronous model but say thanks for the tip do to use it.
Not at all. As said before, my goal has never been to avoid an asynchronous scheme, but to be able to send a command's response filled with my DB data.
You know flipkick, my little SQL request is typically performed in less than 150 microseconds on my linux server. That means an active wait would have frozen my whole APE server for something like the same time. Huuuge !