Locking a Table and Ending a Session with EMySQL API
Using the EMySQL API – Part 7
Foreword: In this part of the series, I talk about Locking a Table and Ending a Session with EMySQL API.
By: Chrysanthus Date Published: 28 Jul 2016
The following code will lock the table, pet for writing.
var locStr = `LOCK TABLES pet WRITE`;
con.query(locStr, function(err, OK)
Again just place the correct SQL statement without the ending semicolon as argument to the query() function.
After locking you should unlock. The following code unlock all tables locked:
var unlocStr = `UNLOCK TABLES`;
con.query(unlocStr, function(err, OK)
Ending a Session
The connect statement opens a socket. Any socket opened has to be closed. At the end of your session, you have to close the socket. However, you are not to do the low-level coding; you just use the Mysql package close() function, as follows:
If you have the privilege to shut down the MySQL server, you can do so. This command should be issued before closing the connection. The shutdown() function shuts down the server (remote) and not the socket. The function is defined in the Mysql package, but in your script, you type something like,
con.shutdown('', function(err, result)
That is it for this part of the series. We stop here and continue in the next part.
Related LinksFree Pure ECMAScript MySQL API for Node.js
More Related Links
Node.js Web Development Course
Major in Website Design
Writing ECMAScript Module
ECMAScript 2015 Course