an example in
coffeescript, don't know if it is the most elegant solution. You nest the two (three...) functions (q1...q2...qx) with your mysql statements having the first call the second (and the second the third...) and at the end you call the first (q1). That way they will get executed in the order determined by you (sync). You have a local "myRender" inherit the render method and call that in your function. That should be all. Alternatively use a module like async. (I try keep use of modules low to avoid extra overhead) ... myRender = @render # make render method available for funcs below q1 = -> MysqlConnection = mysql.createConnection(mysql_options) MysqlConnection.connect() # is there a matching user (pktnr) with this password (dance)? sql = "select count(*) as pkt_count from pkt where pktnr = " + MysqlConnection.escape(suchpktnr) + " and dance = " + MysqlConnection.escape(suchpwd) MysqlConnection.query sql, (err, result) -> throw err if err MysqlConnection.end q2(result[0].pkt_count) #nested callback, write sessionid to mysql if pktnr+pwd exists in db q2 = (pkt_count) -> if pkt_count > 0 pr_pktnr = suchpktnr #if correct then write sessionid to the customers record in mysql MysqlConnection = mysql.createConnection(mysql_options) MysqlConnection.connect() sql = "update pkt set sessionid = '" + pr_sid + "' where pktnr = " + MysqlConnection.escape(suchpktnr) + " and dance = " + MysqlConnection.escape(suchpwd) MysqlConnection.query sql, (err, result) -> throw err if err MysqlConnection.end myRender showstock1: { pktnr: pr_pktnr currentBrowser: currentBrowser } else pr_pktnr = '00000' myRender showstock1: { pktnr: pr_pktnr currentBrowser: currentBrowser } q1() Hope this is useful, best wishes for the New Year Karl-L. Rumpf klru...@gmail.com Málaga, Spain On 25/12/12 18:14, Joman Sierra wrote: I have this scenario: -- |
- [nodejs] Waiting for two Mysql Functions? Joman Sierra
- Re: [nodejs] Waiting for two Mysql Functions? Martin Wawrusch
- Re: [nodejs] Waiting for two Mysql Functions? klrumpf
- Re: [nodejs] Waiting for two Mysql Functions? Jake Verbaten
- Re: [nodejs] Waiting for two Mysql Functions? Tim Smart
- [nodejs] Re: Waiting for two Mysql Functions? Andrey