Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Logs and databases #
######################
*.log

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
6 changes: 3 additions & 3 deletions benchmark/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var startUsage = process.memoryUsage();
function dumpMem(n)
{
var memusage = process.memoryUsage();
console.log(n + ' rss: ' + (memusage.rss - startUsage.rss) + ' vsize:' + (memusage.vsize - startUsage.vsize) +
console.log(n + ' rss: ' + (memusage.rss - startUsage.rss) + ' vsize:' + (memusage.vsize - startUsage.vsize) +
' heapTotal:' + (memusage.heapTotal - startUsage.heapTotal) + ' heapUsed:' + (memusage.heapUsed - startUsage.heapUsed)
);
}
Expand Down Expand Up @@ -50,13 +50,13 @@ client.query(config.create_table)
{
var duration = (+new Date - startTick) / 1000,
queriesPerSecond = 100 / duration;
startTick = +new Date;
startTick = +new Date;

console.log('%d queries / second', queriesPerSecond.toFixed(2));
}
});
client.debug(queries + 'finished');

}
queryOne();
});
26 changes: 13 additions & 13 deletions examples/myhttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var mysql = require('../lib/mysql-native');

function test_datasource()
{
var db = mysql.createTCPClient('127.0.0.1');
var db = mysql.createTCPClient('127.0.0.1');
db.auto_prepare = true;
var auth = db.auth('', 'root');
db.set('row_as_hash', false);
Expand All @@ -21,7 +21,7 @@ function dump_row(row, res, formatter)
res.write('<tr>');
for (var i=0; i < row.length; ++i)
{
res.write('<td>' + formatter(row[i]) + '</td>');
res.write('<td>' + formatter(row[i]) + '</td>');
}
res.write('</tr>\n');
}
Expand All @@ -31,9 +31,9 @@ function dump_query(cmd, res, formatter)

res.write("<table>\n<tr>");
cmd
.on('field', function(f) { res.write('<td>' + f.name + '</td>'); })
.on('fields_eof', function() { res.write('</tr>\n'); })
.on('row', function(r) { dump_row(r, res, formatter) })
.on('field', function(f) { res.write('<td>' + f.name + '</td>'); })
.on('fields_eof', function() { res.write('</tr>\n'); })
.on('row', function(r) { dump_row(r, res, formatter) })
.on('end', function() { res.end('</table>'); })
}

Expand All @@ -51,7 +51,7 @@ http.createServer(function (req, res) {
{
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<html><body>');
dump_query(conn.query('show databases'), res,
dump_query(conn.query('show databases'), res,
function(s) { return '<a href="/?db=' + s + '">' + s + '</a>'; }
);
} else if (query.db)
Expand All @@ -64,19 +64,19 @@ http.createServer(function (req, res) {
{
res.write("<html><body><table>\n<tr>");
conn.query('show tables')
.on('field', function(f) { res.write("<td>" + f.name + "</td>"); })
.on('fields_eof', function() { res.write("</tr>\n"); })
.on('row', function(r) { res.write('<tr><td><a href="/?db=' + db + '&q=select * from ' + r[0] + '">' + r[0] + '</a></td><tr>\n'); })
.on('field', function(f) { res.write("<td>" + f.name + "</td>"); })
.on('fields_eof', function() { res.write("</tr>\n"); })
.on('row', function(r) { res.write('<tr><td><a href="/?db=' + db + '&q=select * from ' + r[0] + '">' + r[0] + '</a></td><tr>\n'); })
.on('end', function() { res.end("</table></body></html>"); })
.on('error', function(e) { res.end(e.message); });
} else {
console.log('executing ' + q);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("<html><body><table>\n<tr>");
conn.query(q)
.on('field', function(f) { res.write("<td>" + f.name + "</td>"); })
.on('fields_eof', function() { res.write("</tr>\n"); })
.on('row', function(r) { dump_row(r, res); })
.on('field', function(f) { res.write("<td>" + f.name + "</td>"); })
.on('fields_eof', function() { res.write("</tr>\n"); })
.on('row', function(r) { dump_row(r, res); })
.on('end', function() { res.end("</table></body></html>"); })
.on('error', function(e) { res.end(e.message); });
}
Expand All @@ -85,5 +85,5 @@ http.createServer(function (req, res) {
res.end('<h3>please select DB</h3>');
}
console.log(req);

}).listen(8080, "127.0.0.1");
10 changes: 5 additions & 5 deletions examples/websql.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// websql example adapted from http://html5demos.com/database-rollback
// original code (c)
// original code (c)

var webdb = require('../lib/mysql-native/wrappers/websql');

var db = webdb.openDatabase('test');
db.transaction(function (tx) {
tx.executeSql("CREATE TABLE `foo` (`id` int(20) DEFAULT NULL, `text` blob ) ENGINE=InnoDB");
tx.executeSql("CREATE TABLE `foo` (`id` int(20) DEFAULT NULL, `text` blob ) ENGINE=InnoDB");
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")');
});

db.transaction(function (tx) {
tx.executeSql('SELECT * FROM foo', [], function (tx, results) {
console.log('found rows (should be 1): ' + sys.inspect(results));
console.log('found rows (should be 1): ' + sys.inspect(results));
}, function (tx, err) {
console.log('select* failed: ' + err.message);
});
Expand All @@ -20,7 +20,7 @@ db.transaction(function (tx) {
db.transaction(function (tx) {
tx.executeSql('DROP TABLE foo');
// known to fail - so should rollback the DROP statement
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")', [],
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")', [],
function(tx, rs)
{
console.log("insrted " + sys.inspect(rs));
Expand All @@ -31,7 +31,7 @@ db.transaction(function (tx) {

db.transaction(function (tx) {
tx.executeSql('SELECT * FROM foo', [], function (tx, results) {
console.log('found rows (should be 1): ' + sys.inspect(results));
console.log('found rows (should be 1): ' + sys.inspect(results));
}, function (tx, err) {
console.log('select* failed: ' + err.message);
});
Expand Down
6 changes: 3 additions & 3 deletions lib/mysql-native/charset.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.Charset.prototype.convertFromBytes = function(bytes) {
var convertUTF8ToBytes = function(str) {
if(typeof(str)=='undefined') return undefined;
if(typeof(str)=='undefined') return undefined;

var surrogate_1st = 0;
var unicode_codes = [];
for (var i = 0; i < str.length; ++i) {
Expand All @@ -58,7 +58,7 @@ var convertUTF8ToBytes = function(str) {
unicode_codes.push(utf16_code);
}
}

var utf8_bytes = "";
var i, unicode_code;
for(i=0; i<unicode_codes.length; ++i) {
Expand Down Expand Up @@ -134,7 +134,7 @@ var convertUTF8FromBytes = function(str) {
} else {
// Malformed UTF-8 sequence ignored.
}

return unicode_str.substring(1);

}
Expand Down
4 changes: 2 additions & 2 deletions lib/mysql-native/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ exports.createUNIXClient = function(path)
{
var path = path ? path : "/var/run/mysqld/mysqld.sock";
var connection = net.createConnection(path);

return new SocketClient(connection);
}

function dump(d)
{
return;
Expand Down
16 changes: 8 additions & 8 deletions lib/mysql-native/command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var sys = require('sys');
// , error = require('./error')

//
// base for all commands
// initialises EventEmitter and implemets state mashine
Expand All @@ -11,8 +11,8 @@ function cmd(handlers)
this.state = "start";
this.stmt = ""
this.params = []
// mixin all handlers

// mixin all handlers
for (h in handlers)
{
this[h] = handlers[h];
Expand All @@ -24,7 +24,7 @@ function cmd(handlers)

sys.inherits(cmd, process.EventEmitter)

cmd.prototype.process_packet = function(r)
cmd.prototype.process_packet = function(r)
{
if (this.client.verbose)
console.log(this.command_name + ":" + this.state + ' : ' + sys.inspect(this.args));
Expand All @@ -36,7 +36,7 @@ cmd.prototype.process_packet = function(r)
e.num = reserror.errno;
e.message = reserror.message;
e.command = this.command_name;
if (this.params)
if (this.params)
e.params = this.params
this.emit('error', e);
return true;
Expand All @@ -45,20 +45,20 @@ cmd.prototype.process_packet = function(r)
var next_state = (this[this.state]) ? this[this.state].apply(this, arguments) : 'done'

if (next_state) this.state = next_state;

if (this.state == "done")
{
this.emit('end', this);
return true;
}

if (this.state == "error") return true;
return false;
}

cmd.prototype.write = function(packet, pnum) {
packet.addHeader(pnum);
this.connection.write(packet.data, 'binary');
this.connection.write(packet.data, 'binary');
}

cmd.prototype.store_column = function(r,f,v, row_as_hash) {
Expand Down
12 changes: 6 additions & 6 deletions lib/mysql-native/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function(db, user, password) {
if (!password)
password = '';

var c = new cmd(
var c = new cmd(
{
start: function() { return 'read_status'; },
read_status: function( r )
Expand All @@ -65,9 +65,9 @@ module.exports = function(db, user, password) {
var scrambleLength = r.num(1); // length of the scramble
r.bytes(10); // (filler) always 0
salt += r.bytes(12);

this.client.charset = this.client.get('charset') ?
Charset.by_name( this.client.get('charset') ) :
Charset.by_name( this.client.get('charset') ) :
Charset.by_number( c.serverStatus.serverLanguage );

var token = password!=="" ? scramble(password, salt) : "";
Expand All @@ -84,12 +84,12 @@ module.exports = function(db, user, password) {
this.write(reply, 1);
return 'check_auth_ok';
},
check_auth_ok: function( r )
check_auth_ok: function( r )
{
var ok = r.readOKpacket();
this.emit('authorized', c.serverStatus);
return 'done';
}
return 'done';
}
});
c.state = 'start';
c.serverStatus = {};
Expand Down
Loading