mariano / node-db-mysql Goto Github PK
View Code? Open in Web Editor NEWMySQL database bindings for Node.js
Home Page: http://nodejsdb.org
MySQL database bindings for Node.js
Home Page: http://nodejsdb.org
When a BLOB is selected, it is not converted to Buffer correctly.
Oh, actually this is a problem in node-db module, not in node-db-mysql.
For example, this is correct:
<Buffer 15 03 00 02 00 97 15 05 00 03 35 32 33>
This is what is now wrong:
<Buffer 15 03 00 02 00 ef bf bd 15 05 00 03 35 32 33>
My guess is that BLOB is getting converted to Buffer without second argument which by default is 'utf8', but it should be 'binary' for BLOB's.
I don't know C++, but this is how I would do it in JavaScript:
value = new Buffer( BLOB_value_here , 'binary' );
I think that this is the code which should get updated, I found it in 'query.cc' file, line 1308:
value = v8::Local<v8::Value>::New(node::Buffer::New(v8::String::New(currentValue, currentLength)));
As I don't know C++, I can only guess how the fix would look like:
value = v8::Local<v8::Value>::New(node::Buffer::New(v8::String::New(currentValue, currentLength), 'binary' ));
I hope you will fix this soon.
Thank you for the great job you are doing!
Example code:
db.query().
update("sessions").
set({
"push_id": "2472966781482252390"
}).
execute();
Value inserted is: 2472966781482252288
push_id is varchar(40)
Any ideas?
Last time I had similar issues with my macbook but there I figured out, but now I'm switching to an iMac, I just reinstalled the OS on it, and I have errors again when I try to install db-mysql.
I have Node.js 0.4.8, Mac OS X 10.6.7, and MySQL 5.5.13
The mysql_config is at: /usr/local/mysql/bin/mysql_config , I know this because I tested it by going to Finder->Command+Shift+G -> /usr/local/mysql/bin and mysql_config is there
I'm trying to install it with:
export MYSQL_CONFIG=/usr/local/mysql/bin/mysql_config npm install db-mysql
But I get:
> [email protected] install /Users/adamfisher/node_modules/db-mysql
> node-waf configure build
Checking for program g++ or c++ : not found
/Users/adamfisher/node_modules/db-mysql/wscript:22: error: could not configure a cxx compiler!
npm ERR! error installing [email protected] Error: [email protected] install: `node-waf configure build`
npm ERR! error installing [email protected] `sh "-c" "node-waf configure build"` failed with 1
npm ERR! error installing [email protected] at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:17)
npm ERR! error installing [email protected] at ChildProcess.onexit (child_process.js:192:12)
> [email protected] preuninstall /Users/adamfisher/node_modules/db-mysql
> rm -rf build/*
npm ERR! [email protected] install: `node-waf configure build`
npm ERR! `sh "-c" "node-waf configure build"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Darwin 10.7.0
npm ERR! command "node" "/usr/bin/npm" "install" "db-mysql"
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/adamfisher/npm-debug.log
npm not ok
I get the error "PROCEDURE mydb.test can't return a result set in the given context" in any procedure that returns a result such as the one below.
CREATE DEFINER=root
@%
PROCEDURE test
()
BEGIN
select 1 as result;
END
Im executing something like db.query('call test()').
Any help would be apreciated.
Would it be possible to implement a connection pool, with a configurable number of connections, inside of the driver? It would be great if we had an async connection pool to the db for queries.
What I have done:
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : ok /Users/piotr/local/node/bin
Checking for node prefix : ok /Users/piotr/local/node
Checking for program mysql_config : /usr/local/mysql/bin/mysql_config
Checking for library mysqlclient_r : yes
'configure' finished successfully (0.557s)
Waf: Entering directory `/Users/piotr/Documents/Workspace/MieciuNode/devel/node_modules/db-mysql/build'
[ 1/11] cxx: lib/node-db/binding.cc -> build/default/lib/node-db/binding_1.o
[ 2/11] cxx: lib/node-db/connection.cc -> build/default/lib/node-db/connection_1.o
[ 3/11] cxx: lib/node-db/exception.cc -> build/default/lib/node-db/exception_1.o
[ 4/11] cxx: lib/node-db/query.cc -> build/default/lib/node-db/query_1.o
[ 5/11] cxx: lib/node-db/result.cc -> build/default/lib/node-db/result_1.o
[ 6/11] cxx: src/connection.cc -> build/default/src/connection_1.o
[ 7/11] cxx: src/mysql.cc -> build/default/src/mysql_1.o
[ 8/11] cxx: src/query.cc -> build/default/src/query_1.o
[ 9/11] cxx: src/result.cc -> build/default/src/result_1.o
[10/11] cxx: src/mysql_bindings.cc -> build/default/src/mysql_bindings_1.o
[11/11] cxx_link: build/default/lib/node-db/binding_1.o build/default/lib/node-db/connection_1.o build/default/lib/node-db/exception_1.o build/default/lib/node-db/query_1.o build/default/lib/node-db/result_1.o build/default/src/connection_1.o build/default/src/mysql_1.o build/default/src/query_1.o build/default/src/result_1.o build/default/src/mysql_bindings_1.o -> build/default/mysql_bindings.node
Waf: Leaving directory `/Users/piotr/Documents/Workspace/MieciuNode/devel/node_modules/db-mysql/build'
'build' finished successfully (4.681s)
When running
var mysql = require('db-mysql'); I'm getting
Error: dlopen(/Users/piotr/Documents/Workspace/MieciuNode/devel/node_modules/db-mysql/build/default/mysql_bindings.node, 1): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/piotr/Documents/Workspace/MieciuNode/devel/node_modules/db-mysql/build/default/mysql_bindings.node
Reason: image not found
at Object..node (module.js:416:11)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at require (module.js:348:19)
at Object.<anonymous> (/Users/piotr/Documents/Workspace/MieciuNode/devel/node_modules/db-mysql/db-mysql.js:12:15)
at Module._compile (module.js:404:26)
at Object..js (module.js:410:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at require (module.js:348:19)
No idea why it is not working. It seems I have everything installed correctly. Node version 0.4.7
[email protected] install /var/nodejs/node_modules/db-mysql
node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "/usr/local/bin/node-waf", line 16, in
Scripting.prepare(t, os.getcwd(), VERSION, wafdir)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 145, in prepare
prepare_impl(t, cwd, ver, wafdir)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 135, in prepare_
impl
main()
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 188, in main
fun(ctx)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 241, in configur
e
conf.sub_config([''])
File "/usr/local/bin/../lib/node/wafadmin/Configure.py", line 221, in sub_conf
ig
self.recurse(k, name='configure')
File "/usr/local/bin/../lib/node/wafadmin/Utils.py", line 634, in recurse
f(self)
File "/var/nodejs/node_modules/db-mysql/wscript", line 35, in configure
conf.env.append_unique('CXXFLAGS', Utils.cmd_output(Options.options.mysql_co
nfig + ' --include').split())
File "/usr/local/bin/../lib/node/wafadmin/Utils.py", line 453, in cmd_output
raise ValueError(msg)
ValueError: command execution failed: mysql_config --include -> ''
npm ERR! error installing [email protected] Error: [email protected] install: node-wa f configure build
npm ERR! error installing [email protected] sh "-c" "node-waf configure build"
fa
iled with 1
npm ERR! error installing [email protected] at ChildProcess. (/usr/l
ocal/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:
17)
npm ERR! error installing [email protected] at ChildProcess.onexit (child_proce
ss.js:192:12)
npm ERR! [email protected] install: node-waf configure build
npm ERR! sh "-c" "node-waf configure build"
failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.38.2-grsec-xxxx-grs-ipv6-64
npm ERR! command "node" "/usr/local/bin/npm" "install" "db-mysql"
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /var/nodejs/npm-debug.log
npm not ok
db.query.select('foo').from('bar')
.on('each', function(row, index, last) {
console.log(index + ': ' + last);
}).execute();
If 'bar' contains 3 rows I'd expect the output to be:
0: false
1: false
2: true
but I'm instead getting:
0: false
1: false
2: false
I'm using 0.6.7 with MySQL.
In the examples, all actions are chained to the original Database class, through .connect(). Eg. I was unable to do this:
var mysql = require('db-mysql');
new mysql.Database({
hostname: 'hyfnrsx.com',
user: 'remote',
password: '2bq44acLtPTx2D46',
database: 'online-presence-scrubber'
}).connect(function(error) {})
// something else happening
mysql.query().select('..') ...
// or
mysql.Database.query()...
Is there a way to reuse the options and connection for later querying?
I wanted to take this code to query the data stored in the database but can not find documentation for this:
I'd like to know if this module supports stored procedure before using it in my project.
as I can't find corresponding example on the site, I have to ask here.
thanks in advance!
node.js:183
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: /srv/sir2/app/node/node_modules/db-mysql/build/default/mysql_bindings.node: undefined symbol: ev_rt_now
at Object..node (module.js:435:11)
at Module.load (module.js:339:31)
at Function._load (module.js:298:12)
at require (module.js:367:19)
at Object. (/srv/sir2/app/node/node_modules/db-mysql/db-mysql.js:12:15)
at Module._compile (module.js:423:26)
at Object..js (module.js:429:10)
at Module.load (module.js:339:31)
at Function._load (module.js:298:12)
at require (module.js:367:19)
I have libmysqlclient-dev installed and set the MYSQL_CONFIG variable correctly before installing, but still no luck. what am I doing wrong?
Hi,
I can't seem to find in the documentation (code.google.com/apis/maps/documentation/javascript/reference.html) how to perform a groupby (without running a raw statement) is this something planned for future release?
I'm running RED HAT Enterprise 5.7 with node 0.4.10 and npm 1.0.25 and I'm running into an error message when trying to install db-mysql. After running "sudo npm install db-mysql," this is my output.
node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
Checking for program mysql_config : /usr/bin/mysql_config
Checking for library mysqlclient_r : Missing libmysqlclient_r
'configure' finished successfully (0.135s)
Waf: Entering directory/apps/home/hotseat/node_modules/db-mysql/build' [ 1/11] cxx: lib/node-db/binding.cc -> build/default/lib/node-db/binding_1.o [ 2/11] cxx: lib/node-db/connection.cc -> build/default/lib/node-db/connection_1.o [ 3/11] cxx: lib/node-db/exception.cc -> build/default/lib/node-db/exception_1.o [ 4/11] cxx: lib/node-db/query.cc -> build/default/lib/node-db/query_1.o [ 5/11] cxx: lib/node-db/result.cc -> build/default/lib/node-db/result_1.o [ 6/11] cxx: src/connection.cc -> build/default/src/connection_1.o In file included from ../src/connection.cc:2: ../src/./connection.h:5:19: error: mysql.h: No such file or directory ../src/././result.h:16: error: expected â,â or â...â before â&â token ../src/././result.h:16: error: ISO C++ forbids declaration of âMYSQL_FIELDâ with no type ../src/././result.h:28: error: expected
)' before â*â token
(and it goes on for another 40 lines or so)
running a "which mysql_config", my file is: /usr/bin/mysql_config. The /usr/bin mysqlclient_r directory is also in my path and my path is no different than my regular account.
I ran a search, but was unable to locate the mysqlclient_r file. I am however able to log on to the mysql server (v. 5.0.77) and run queries manually.
Does anyone know a way around this problem?
Is there a way to detect loss of connection to the server? How about a use for this purpose event 'error'
on Database
object?
And also use option MYSQL_OPT_RECONNECT
when executing queries to automatic reconnection.
Hi. Would be queries caching available?
For example possibility to connect some memory storage (Redis for example) and retreive data from it, without quering database?
That is any SELECT query is added into table cache, while UPDATE, INSERT, DELETE drop cache of affected table.
Is it possible to connect directly to a socket instead of connecting to a host/port? For example, on OSX, mysql uses a socket file, /tmp/mysql.sock, by default.
I've got a query with an on error handler attached. I've noticed that I am unable to log the query (with bind parameters) I am about to execute to the console prior to .execute. Also, when there is a syntax error (or any error emitted during query execution), the error caught is an unspecified error: (unknown error).
This is against 0.7.4
Example:
self.query().
on('error', function(error) {
//handle error
}).
execute('some malformed sql', function(error, result) {
if (error) {
//handle error
}
else {
//alls good!
}
});
Sample code:
var mysql = require('db-mysql');
var db = new mysql.Database({
hostname: '192.168.100.10',
user: 'root',
password: '11',
database: 'db1'
});
db.connect(function(err){
if (err){
throw err;
}
db.query('SET names utf8').execute(function(err){
if (err){
throw err;
}
['proc1', 'proc2', 'proc3', 'proc4', 'proc5'].forEach(function(sp_name){
db.query('SHOW CREATE PROCEDURE ' + sp_name + '_backup').execute(function(err, rows){
console.log(sp_name);
if (err){
console.log(err);
} else {
console.log(rows);
}
});
});
});
});
There is no procedures in database.
Executing this script rarely produces same output.
Sometimes err parameter in callback is empty and rows is undefined!
Is it bug, or I should execute queries sequentally?
Hello,
I can not get the insert() method working and I could not find an example in the documentation.
Could you provide some example please?
Regards,
Jean-Marc
The following code triggers the bug:
var insert_values = new Array({ value: '@someid', escape: false },
someval,
anotherval
);
db.query().insert('table', ['`fkey_ids`', '`col1`', '`col2`'],
new Array(insert_values, ...)).execute();
I believe the bug is due to node_db::Query::placeholders
miscalulating the delta. It only occurs when INSERTing lots of rows.
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::replace
Program received signal SIGABRT, Aborted.
0x00007ffff62cc165 in raise () from /lib/libc.so.6
(gdb) bt
#0 0x00007ffff62cc165 in raise () from /lib/libc.so.6
#1 0x00007ffff62cef70 in abort () from /lib/libc.so.6
#2 0x00007ffff6d7bdc5 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#3 0x00007ffff6d7a166 in ?? () from /usr/lib/libstdc++.so.6
#4 0x00007ffff6d7a193 in std::terminate() () from /usr/lib/libstdc++.so.6
#5 0x00007ffff6d7a1a6 in ?? () from /usr/lib/libstdc++.so.6
#6 0x00007ffff6d797e3 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.6
#7 0x00007ffff588461b in node_db::Query::parseQuery (this=0xfb8ca0) at ../lib/node-db/query.cc:1378
#8 0x00007ffff587d2f8 in node_db::Query::Execute (args=...) at ../lib/node-db/query.cc:599
#9 0x00000000005a96b1 in v8::internal::Builtin_HandleApiCall(v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)1>, v8::internal::Isolate*) ()
#10 0x00002d40ce48814e in ?? ()
I have a "Error: Uncaught, unspecified 'error' event." I think it happens when I'm about to commit. Is there anything I can do to have more debug output or something to hunt this bug down?
Code
console.log("COMMIT");
conn.query().execute("COMMIT;", function(error, rows) {
if (error) {
console.log("error", error);
} else {
console.log("ok");
}
});
Log
COMMIT
events.js:50
throw new Error("Uncaught, unspecified 'error' event.");
^
Error: Uncaught, unspecified 'error' event.
at [object Object].emit (events.js:50:15)
npm install db-mysql
> [email protected] install /home/levijm/projects/node/node_modules/db-mysql
> node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
Checking for program mysql_config : /usr/bin/mysql_config
Checking for library mysqlclient_r : no such environment: default
Traceback (most recent call last):
File "/usr/local/bin/node-waf", line 16, in <module>
Scripting.prepare(t, os.getcwd(), VERSION, wafdir)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 145, in prepare
prepare_impl(t, cwd, ver, wafdir)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 135, in prepare_impl
main()
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 188, in main
fun(ctx)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 241, in configure
conf.sub_config([''])
File "/usr/local/bin/../lib/node/wafadmin/Configure.py", line 221, in sub_config
self.recurse(k, name='configure')
File "/usr/local/bin/../lib/node/wafadmin/Utils.py", line 634, in recurse
f(self)
File "/home/levijm/projects/node/node_modules/db-mysql/wscript", line 38, in configure
conf.check_cxx(lib="mysqlclient_r", errmsg="Missing libmysqlclient_r")
File "/usr/local/bin/../lib/node/wafadmin/Tools/config_c.py", line 567, in check_cxx
return self.check(*k, **kw)
File "/usr/local/bin/../lib/node/wafadmin/Tools/config_c.py", line 444, in check
ret = self.run_c_code(*k, **kw)
File "/usr/local/bin/../lib/node/wafadmin/Tools/config_c.py", line 521, in run_c_code
o = bld(features=kw['features'], source=test_f_name, target='testprog')
File "/usr/local/bin/../lib/node/wafadmin/Build.py", line 343, in __call__
return TaskGen.task_gen(*k, **kw)
File "/usr/local/bin/../lib/node/wafadmin/TaskGen.py", line 118, in __init__
self.env = self.bld.env.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
npm ERR! error installing [email protected] Error: [email protected] install: `node-waf configure build`
npm ERR! error installing [email protected] `sh "-c" "node-waf configure build"` failed with 1
npm ERR! error installing [email protected] at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:17)
npm ERR! error installing [email protected] at ChildProcess.onexit (child_process.js:192:12)
> [email protected] preuninstall /home/levijm/projects/node/node_modules/db-mysql
> rm -rf build/*
npm ERR! [email protected] install: `node-waf configure build`
npm ERR! `sh "-c" "node-waf configure build"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.38-11-generic
npm ERR! command "node" "/usr/local/bin/npm" "install" "db-mysql"
npm ERR! cwd /home/levijm/projects/node
npm ERR! node -v v0.4.12
npm ERR! npm -v 1.0.90
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/levijm/projects/node/npm-debug.log
npm not ok
Running mysql_config --libs_r:
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient_r
What does no such environment:
mean? and default
?
Right now if you pass "table._" as a string to Database.name() it will return "table
._
"
It shouldn't escape the astrick in the string passed.
Hi I have problem with the dyld, I using XAMPP package for mysql and the using MacBook Pro, Model Identifier: MacBookPro7,1, Processor Name: Intel Core 2 Duo
The error it's
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /opt/local/lib/node/.npm/db-mysql/0.6.5/package/build/default/mysql_bindings.node
Expected in: dynamic lookup
dyld: Symbol not found: _mysql_init
Referenced from: /opt/local/lib/node/.npm/db-mysql/0.6.5/package/build/default/mysql_bindings.node
Expected in: dynamic lookup
Do you have any idea what's going on. Cause i have tried this link but no luck http://bixsolutions.net/forum/printthread.php?tid=18
Regards
Setyagus Sucipto
Following code does not executed correctly.
It has three kinds of errors:
Example code:
var mysql = require('db-mysql'),
timers = require('timers');
var num = 1;
var db = new mysql.Database({
hostname: '',
user: '',
password: '',
database: ''
});
db.on('ready', function () {
console.log("Database ready");
for (var i = 0; i < 10000; ++i) {
timers.setTimeout(execute, 5);
}
});
db.on('error', function (err) {
console.log("Database error: " + err);
});
db.connect();
function execute() {
var q = db.query("SELECT COUNT(*) cnt FROM `job`");
q.on('error', function (err) {
console.log("Query error: " + err);
});
q.execute(function (rows, cols) {
console.log('[' + num + '] Jobs count: ' + rows[0].cnt);
++num;
});
}
Backtrace:
*** glibc detected *** node: double free or corruption (!prev): 0x08845878 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x6b961)[0xb73dc961]
/lib/i386-linux-gnu/libc.so.6(+0x6d28b)[0xb73de28b]
/lib/i386-linux-gnu/libc.so.6(cfree+0x6d)[0xb73e141d]
/usr/lib/libmysqlclient_r.so.16(my_no_flags_free+0x21)[0xb46dee41]
/usr/lib/libmysqlclient_r.so.16(vio_delete+0x30)[0xb470f850]
/usr/lib/libmysqlclient_r.so.16(end_server+0x34)[0xb4709c44]
/usr/lib/libmysqlclient_r.so.16(cli_safe_read+0xe8)[0xb4709df8]
/usr/lib/libmysqlclient_r.so.16(+0x6bdb5)[0xb470adb5]
/usr/lib/libmysqlclient_r.so.16(mysql_real_query+0x46)[0xb470b8a6]
/usr/lib/libmysqlclient_r.so.16(mysql_query+0x35)[0xb46d90d5]
/home/zerodivisi0n/node/lib/node/.npm/db-mysql/0.4.8/package/build/default/mysql_bindings.node(_ZNK13node_db_mysql10Connection5queryERKSs+0x7f)[0xb497dfc9]
/home/zerodivisi0n/node/lib/node/.npm/db-mysql/0.4.8/package/build/default/mysql_bindings.node(_ZN7node_db5Query7executeEPNS0_17execute_request_tE+0x4b)[0xb4976e4d]
/home/zerodivisi0n/node/lib/node/.npm/db-mysql/0.4.8/package/build/default/mysql_bindings.node(_ZN7node_db5Query10eioExecuteEP7eio_req+0x5f)[0xb4976d5b]
node[0x816f721]
/lib/i386-linux-gnu/libpthread.so.0(+0x5e99)[0xb74d7e99]
/lib/i386-linux-gnu/libc.so.6(clone+0x5e)[0xb744173e]
Tested on Ubuntu Server 11.04.
I can't get the execute() to work, but I might be doing something wrong?
My code:
new mysql.Database({
'hostname': 'localhost',
'user': 'user',
'password': 'pass',
'database': 'db'
}).connect(function(error) {
if (error) {
return console.log('MySQL connection error: ' + error);
}
this.execute(…);
});
This is the error I get:
this.execute(…) {
^
TypeError: Object [object Object] has no method 'execute'
at [object Object].<anonymous> (/srv/www/server.js:35:9)
I'm trying to read data stored in a BLOB column. The data is stored in a buffer and converting it to a string doesn't seem to be working:
console.log('Data: ' + rows[0].data.toString('binary'));
Hello, does this library have bindings to mysql_insert_id()?
Thanks,
rgmarcha
How can I close connection only after all queries executed successfully ?
My code is:
new mysql.Database({
hostname: MYSQL_HOST,
user: MYSQL_USER,
password: MYSQL_PASS,
database: MYSQL_DATABASE,
reconnect: false
}).connect(function(error) {
if(error)
return;
var self = this;
for(ticker in info.tickers) {
var tickerInfo = info.tickers[ticker];
this.query().execute(
'some_query_string_here'
function(error, rows) {
if(rows.length == 0)
var query = 'insert ...';
else
var query = 'update...';
self.query().execute(query);
});
}
});
I need to close the connection because I run that code in setInterval(), and if I don`t, after a while there will be a lot of open connections, so the program will crash (with error).
I have this code (approximately)
this.query().
update('users').
set({ connected: true, nodeId: ths.user.clientId}).
where('code = ?', [ currentName ]).
execute(); //or execute(function(rows,cols){ some code })
and I need it to be executed asynchronously. the only way I found to work is that:
this.query.execute(this.query().
update('users').
set({ connected: true, nodeId: ths.user.clientId}).
where('code = ?', [ currentName ]).sql(), //the query in plain text
[], //values for the query - irrelevant since query's been parsed
function(){}, //callback
{ async: false }
);
which is extremely clumsy... is there a way to tell the first query to be asynchronous, and keep the clumsiness out?
I'm having an issue getting the db-mysql library installed through NPM.
uname -r output: Linux nathan-rcsg-dev 2.6.38-11-server #50-Ubuntu SMP Mon Sep 12 21:34:27 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Here's the output of "npm install db-mysql"
npm install -g db-mysql
[email protected] install /usr/local/lib/node_modules/db-mysql
node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
Checking for program mysql_config : /usr/bin/mysql_config
Checking for library mysqlclient_r : no such environment: default
Traceback (most recent call last):
File "/usr/local/bin/node-waf", line 16, in
Scripting.prepare(t, os.getcwd(), VERSION, wafdir)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 145, in prepare
prepare_impl(t, cwd, ver, wafdir)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 135, in prepare_impl
main()
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 188, in main
fun(ctx)
File "/usr/local/bin/../lib/node/wafadmin/Scripting.py", line 241, in configure
conf.sub_config([''])
File "/usr/local/bin/../lib/node/wafadmin/Configure.py", line 221, in sub_config
self.recurse(k, name='configure')
File "/usr/local/bin/../lib/node/wafadmin/Utils.py", line 634, in recurse
f(self)
File "/usr/local/lib/node_modules/db-mysql/wscript", line 38, in configure
conf.check_cxx(lib="mysqlclient_r", errmsg="Missing libmysqlclient_r")
File "/usr/local/bin/../lib/node/wafadmin/Tools/config_c.py", line 567, in check_cxx
return self.check(_k, *_kw)
File "/usr/local/bin/../lib/node/wafadmin/Tools/config_c.py", line 444, in check
ret = self.run_c_code(_k, *_kw)
File "/usr/local/bin/../lib/node/wafadmin/Tools/config_c.py", line 521, in run_c_code
o = bld(features=kw['features'], source=test_f_name, target='testprog')
File "/usr/local/bin/../lib/node/wafadmin/Build.py", line 343, in call
return TaskGen.task_gen(_k, *_kw)
File "/usr/local/bin/../lib/node/wafadmin/TaskGen.py", line 118, in init
self.env = self.bld.env.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
Any ideas?
Hi,
I'm trying to install your module on Ubuntu 11.04.
I have libmysqlclient-dev, and I have mysql_config in my PATH.
mysql_config --include gives me:
-I/usr/include/mysql
running
npm install db-mysql -g produce this error:
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : ok /usr/share/node/lib/node_modules
Checking for node prefix : ok /usr/share/node
Checking for program mysql_config : /usr/bin/mysql_config
Checking for library mysqlclient_r : yes
'configure' finished successfully (2.851s)
Waf: Entering directory `/usr/share/node/lib/node_modules/db-mysql/build'
[ 1/11] cxx: lib/node-db/binding.cc -> build/default/lib/node-db/binding_1.o
In file included from /usr/share/node/include/node/uv.h:40:0,
from /usr/share/node/include/node/node.h:25,
from ../lib/node-db/./binding.h:5,
from ../lib/node-db/binding.cc:2:
/usr/share/node/include/node/uv-unix.h:27:19: fatal error: ev/ev.h: No such file or directory
compilation terminated.
Waf: Leaving directory `/usr/share/node/lib/node_modules/db-mysql/build'
Build failed: -> task failed (err #1):
{task: cxx binding.cc -> binding_1.o}
npm ERR! error installing [email protected] Error: [email protected] install: `node-waf configure build`
npm ERR! error installing [email protected] `sh "-c" "node-waf configure build"` failed with 1
npm ERR! error installing [email protected] at ChildProcess.<anonymous> (/usr/share/node/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:17)
npm ERR! error installing [email protected] at ChildProcess.onexit (child_process.js:246:12)
npm ERR! [email protected] install: `node-waf configure build`
npm ERR! `sh "-c" "node-waf configure build"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.38-8-server
npm ERR! command "node" "/usr/share/node/bin/npm" "install" "db-mysql" "-g"
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/s/npm-debug.log
npm not ok
I´m installing with this:
adam@adam-Parallels-Virtual-Platform:~$ export MYSQL_CONFIG=/usr/bin/mysql_config
adam@adam-Parallels-Virtual-Platform:~$ npm install db-mysql
But I get these errors:
> [email protected] install /home/adam/node_modules/db-mysql
> node-waf configure build
sh: node-waf: not found
npm ERR! error installing [email protected] Error: [email protected] install: `node-waf configure build`
npm ERR! error installing [email protected] `sh "-c" "node-waf configure build"` failed with 127
npm ERR! error installing [email protected] at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:17)
npm ERR! error installing [email protected] at ChildProcess.onexit (child_process.js:192:12)
> [email protected] preuninstall /home/adam/node_modules/db-mysql
> rm -rf build/*
npm ERR! [email protected] install: `node-waf configure build`
npm ERR! `sh "-c" "node-waf configure build"` failed with 127
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.38-10-generic
npm ERR! command "node" "/usr/bin/npm" "install" "db-mysql"
npm ERR! cwd /home/adam
npm ERR! node -v v0.4.9
npm ERR! npm -v 1.0.18
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/adam/npm-debug.log
npm not ok
Before I always got this error on Mac OS X because mysql_config was not there. But I´m sure that mysql_config is in /usr/bin/mysql_config because of this:
adam@adam-Parallels-Virtual-Platform:~$ which mysql_config
/usr/bin/mysql_config
Maybe sh: node-waf: not found
is the problem because this is the first error, but I don´t really know what to do with this. :S
So what´s the problem?
I'm trying to get a datetime object from the database, when saving it is done correctly, but when fetching it, it returns a string, and a very odd one.
for a datetime object which is supposed to be something like this: "2011-06-06 08:32:57"
it returns a string with: "1970-01-19T16:51:45.016Z"
Consider the following code snippet:
var long = 70686626206955;
console.log("long type " + typeof long + " long value " + long);
var query = db.query().insert("table", ["long"],
[{value: long, escape: true}]);
console.log("sql ",query.sql());
it produces:
long type number long value 70686626206955
sql INSERT INTO table
(long
) VALUES (7.06866e+13)
7.06866e+13 is not equivalent to 70686626206955 (precision is lost)
While instelling with npm I run into the following errors
[10/11] cxx: src/mysql_bindings.cc -> build/default/src/mysql_bindings_1.o
../src/connection.cc: In member function ‘virtual void node_db_mysql::Connection::open()’:
../src/connection.cc:70: error: cannot convert ‘uint32_t*’ to ‘const char*’ for argument ‘3’ to ‘int mysql_options(MYSQL*, mysql_option, const char*)’
../src/connection.cc:74: error: cannot convert ‘bool*’ to ‘const char*’ for argument ‘3’ to ‘int mysql_options(MYSQL*, mysql_option, const char*)’
../src/connection.cc:77: error: cannot convert ‘bool*’ to ‘const char*’ for argument ‘3’ to ‘int mysql_options(MYSQL*, mysql_option, const char*)’
../src/connection.cc:80: error: cannot convert ‘uint32_t*’ to ‘const char*’ for argument ‘3’ to ‘int mysql_options(MYSQL*, mysql_option, const char*)’
../src/connection.cc:84: error: cannot convert ‘uint32_t*’ to ‘const char*’ for argument ‘3’ to ‘int mysql_options(MYSQL*, mysql_option, const char*)’
../src/result.cc: In member function ‘virtual node_db_mysql::Result::Column* node_db_mysql::Result::column(uint16_t) const’:
../src/result.cc:150: warning: comparison is always false due to limited range of data type
../lib/node-db/query.cc: In member function ‘std::string node_db::Query::value(v8::Local<v8::Value>, bool, bool) const’:
../lib/node-db/query.cc:1373: warning: passing ‘double’ for argument 1 to ‘std::string node_db::Query::fromDate(uint64_t) const’
I thought there was something with the headers, checked included dir, but that seems fine to me.
-I/usr/include/mysql
Paths seems fine to be too.
Checking for program mysql_config : /usr/bin/mysql_config
Checking for library mysqlclient_r : yes
Tried with EXPORT
setting it to /usr/lib64/mysql/mysql_config
, but that did not do the trick either.
This might be something stupid on my hand, but I'm not seeing it right now :)
Its not possible to update a timestamp col with "NOW()" or i missed something.
connection.query()
.update('xxx')
.set({ 'last_used': "NOW()"}, false)
.where('id = ' + id)
with false set only the col names will no longer be escaped
regards
Justus
The errors start here:
[ 8/11] cxx: src/query.cc -> build/default/src/query_1.o
In file included from ../src/connection.cc:2:
../src/./connection.h:5:25: error: mysql/mysql.h: No such file or directory
[ 9/11] cxx: src/result.cc -> build/default/src/result_1.o
In file included from ../src/result.cc:2:
../src/./result.h:5:25: error: mysql/mysql.h: No such file or directory
In file included from ../src/./connection.h:8,
from ../src/connection.cc:2:
../src/././result.h:16: error: expected ‘,’ or ‘...’ before ‘&’ token
Latest node and npm. Node and mysql installed via homebrew.
ree-1.8.7-2011.03 in wfarr/
› ls /usr/local/Cellar/mysql/5.5.10/include
decimal.h my_compiler.h my_net.h mysql_embed.h plugin_ftparser.h
errmsg.h my_config.h my_pthread.h mysql_time.h sql_common.h
keycache.h my_dbug.h my_sys.h mysql_version.h sql_state.h
m_ctype.h my_dir.h my_xml.h mysqld_ername.h sslopt-case.h
m_string.h my_getopt.h mysql/ mysqld_error.h sslopt-longopts.h
my_alloc.h my_global.h mysql.h plugin.h sslopt-vars.h
my_attribute.h my_list.h mysql_com.h plugin_audit.h typelib.h
ree-1.8.7-2011.03 in wfarr/
› ls /usr/local/Cellar/mysql/5.5.10/include/mysql
client_plugin.h plugin_auth.h service_my_snprintf.h services.h
innodb_priv.h plugin_auth_common.h service_thd_alloc.h
plugin.h plugin_ftparser.h service_thd_wait.h
plugin_audit.h psi/ service_thread_scheduler.h
It looks like it's trying to find mysql.h inside the include/mysql directory instead of at the top-level.
I have a column of type BIT. When using the cast option set to true the result is always '0'. If i disable the cast option the returned value is '\u0000' if the value in the database is set to '0' and '\u0001' if the value is set to '1'.
Looks like a bug, can u confirm?
npm ERR! [email protected] install: node-waf configure build
npm ERR! sh "-c" "node-waf configure build"
failed with 127
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.38-8-server
npm ERR! command "node" "/usr/bin/npm" "install" "db-mysql"
npm ERR! cwd /home/dndavies
npm ERR! node -v v0.4.12
npm ERR! npm -v 1.0.30
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/dndavies/npm-debug.log
npm not ok
Tried it serveral times. copied the example from the website anyway its not working :(
console.log(connection.query()
.update('map_value')
.set({ 'last_used': "NOW()"})
.where('id = ?', [id])
.sql();
returns this
UPDATE map_value
SET last_used
='NOW()' WHERE id = ?
regards
Fantus
Hey mariano,
getting lots of attention :) cool man.. anyway we are developing a POS and where leaning towards nodejs for this, and sadly major customer is on windows, do we need a libmysql includes to this or just setup mysql and use node-db-mysql.js?
hi,
i was wondering if you're planning to implement a REPLACE function so that we don't have to SELECT then INSERT.
cheers
Another segfault: When trying to execute a query before the db has made a connection:
var mysql = require('db-mysql');
var db = new mysql.Database({
hostname: 'host',
user: 'user',
password: 'passw',
database: 'dbname'
});
db.connect(function(error) {
if(error) {
console.log("err");
return console.log(error);
}
});
db.query().select("*").from("clients").execute();
// segfaults
Maybe it's nicer to throw an exception or undefined?
Hey Mariano,
I've being doing a bit of ground work for transactional support in the database layer (sorry for not getting back to you time has not been forthcoming recently). Unfortunately I've run into a bit of a problem and I am struggling to come up with a solution. I'm not sure whether or not the issue lies in the driver, but I'll explain and we can see.
Consider the following scenario:
Table A and table B, where B references A through B.ref_id
As part of an atomic function (i.e. I need a transaction); insert 2 rows into A (lets call them A1 and A2), and 4 rows into B (2 for A1, 2 for A2).
Within my application I am successfully opening a connection and starting a transaction. I iterate over my A-tuples, inserting them as you'd expect using code similar to this:
myATuples.forEach(function(aTuple, index, aTuples) {
//Insert A tuple (returns a promise)
//When promise is fulfilled
myBTuplesForATuple.forEach(bTuple, index, bTuples) {
//Promise.resolve holds the query result (insert ID)
//Set B.ref_id to the insert ID of A
//Insert B tuple
});
});
Nearly every time the inserts for A1 and A2 are sequential and before the inserts for the B tuples. However, that means that my A1 query result gets gobbled as the query result is always the preceeding query. So when I insert B1 I actually reference A2.
Unfortunately there is no way to say what query result belongs to what query object that would allow me to consolidate and map to results correctly.
Any plans to supports "ON DUPLICATE KEY UPDATE" on INSERT queries?
I get the Following error when trying to run a simple example on OS X :
(Not sure if its my setup or a bug, forgive me)
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Unable to load shared library /Users/Timo/nodejstest/node_modules/db-mysql/build/Release/mysql_bindings.node
at Object..node (module.js:463:11)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object. (/Users/Timo/nodejstest/node_modules/db-mysql/db-mysql.js:18:15)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
I got "Error: Wrong number of values to escape" while trying to run the following code. Am I missing something?
var mysql = require('db-mysql');
new mysql.Database({
hostname: 'localhost',
user: 'user',
password: 'password',
database: 'database'
}).connect(function(error) {
if (error) {
return console.log("CONNECTION ERROR: " + error);
} else {
this.query().execute("INSERT INTO test (`test`) VALUES ('?');", ['test value'], function(error, rows) {
if (error) {
console.log(error);
} else {
console.log("ok");
}
});
}
});
Hi,
I got the following issue when doing a npm install db-mysql -g
'configure' finished successfully (0.526s)
Waf: Entering directory `/home/fundare/node-db-mysql/build'
[ 1/11] cxx: lib/node-db/binding.cc -> build/default/lib/node-db/binding_1.o
[ 2/11] cxx: lib/node-db/connection.cc -> build/default/lib/node-db/connection_1.o
[ 3/11] cxx: lib/node-db/exception.cc -> build/default/lib/node-db/exception_1.o
[ 4/11] cxx: lib/node-db/query.cc -> build/default/lib/node-db/query_1.o
[ 5/11] cxx: lib/node-db/result.cc -> build/default/lib/node-db/result_1.o
[ 6/11] cxx: src/connection.cc -> build/default/src/connection_1.o
[ 7/11] cxx: src/mysql.cc -> build/default/src/mysql_1.o
[ 8/11] cxx: src/query.cc -> build/default/src/query_1.o
[ 9/11] cxx: src/result.cc -> build/default/src/result_1.o
[10/11] cxx: src/mysql_bindings.cc -> build/default/src/mysql_bindings_1.o
[11/11] cxx_link: build/default/lib/node-db/binding_1.o build/default/lib/node-db/connection_1.o build/default/lib/node-db/exception_1.o build/default/lib/node-db/query_1.o build/default/lib/node-db/result_1.o build/default/src/connection_1.o build/default/src/mysql_1.o build/default/src/query_1.o build/default/src/result_1.o build/default/src/mysql_bindings_1.o -> build/default/mysql_bindings.node
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.a(functexcept.o): relocation R_X86_64_32 against `std::bad_typeid::~bad_typeid()' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/libstdc++.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
Waf: Leaving directory `/home/fundare/node-db-mysql/build'
Build failed: -> task failed (err #1):
{task: cxx_link binding_1.o,connection_1.o,exception_1.o,query_1.o,result_1.o,connection_1.o,mysql_1.o,query_1.o,result_1.o,mysql_bindings_1.o -> mysql_bindings.node}
I've tried to add the "-fPIC" by modifing wscript but it didn't seem to work at all. Any idea ?
PS: I got this issue on a Debian Squeeze. I worked on my mac.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.