Connecting to DB2 from Node.js on Linux-platform

2019-04-11 10:23发布

I am trying to connect to DB2 from a node.js application. I have decided to use the db2 node module. The instructions for installing db2.js first tell you to install node-gyp like this:

sudo npm install -g node-gyp

That seems to have worked for me.
Then I try to install db2.js with this command:

sudo npm install -g db2

Then I get this error:

...
cc1plus: error: unrecognized command line option "-std=c++0x"
...
gyp ERR! node -v v0.10.9
gyp ERR! node-gyp -v v0.9.6

Looking at the prereqs for node-gyp, it says I need gcc. Doing a man on gcc on my system shows that the -std option is only supporting some really old compilers like c++98, gnu99, etc. I have gcc version 4.1.2 20080704 (Red Hat 4.1.2-50).

So I have a few questions. Is there another way to connect to db2 from node? If I continue with db2.js, then what do I need to do now, upgrade my gcc or install a c++0x compiler? (I think that's C++ version 11).

Wish me luck.

EDIT:

I am having trouble upgrading gcc on my linux server, so I tried installing on my raspberry pi as a test:

sudo npm install -g node-gyp
cd /usr/lib/node_modules
sudo git clone https://github.com/herzi/db2.js.git
sudo node-gyp configure
sudo node-gyp build

On the last command I get this error:

In file included from ../src/binding.cc:3:0:
../src/connection.hh:6:20: fatal error: sqlcli.h: No such file or directory
compilation terminated.

I am guessing that's the DB2 Client header file, so I probably need to install that also.

EDIT 2

I installed gcc on my system in a different directory. Then I changed the symlinks in /usr/bin for gcc and g++ to point at my new gcc and g++ (inside gcc). Now I get the same sqlcli.h error that I get on my pi. Time to get the DB2 Client.

Meh. I have db2 client 9.1.2. I need 9.7 according to some searching in the db2 binding.gyp file.

EDIT 3

I installed "IBM Data Server Runtime Client V9.7", but it does not have sqlcli.h in the /opt/IBM/db2/V9.7/include folder! I have a V9.1.3 on a different machine which does have a include folder. So I installed "IBM Data Server Client 9.7" using an old blog post of mine to help me. Now I am getting an error from the node-gyp build that strcmp was not declared. I bet I need to set a lib include or node environment var.

3条回答
来,给爷笑一个
2楼-- · 2019-04-11 10:29

You can add the include files for string functions (e.g. #include <cstring>) into src/connection.cc. That should enable the string functions; maybe you need to replace strcmp() with std::strcmp() then.

查看更多
祖国的老花朵
3楼-- · 2019-04-11 10:30

You should be connecting to your DB2 database with IBM's node module. It will definitely work for linux, but for OS X you need to check out this question: How to connect to DB2 SQL database with node JS?.

查看更多
等我变得足够好
4楼-- · 2019-04-11 10:31

OK. I ended up forking the git repo for db2.js and contributing some work to the project. Now I can compile it. Hopefully once there is a pull I will also be able to install with npm with no editing of source and manual building.

I found out the prereqs:

  • gcc
  • g++
  • DB2 Connect or Client V9.7 (NOT Runtime Client, it is missing sqlcli.h)
  • node-gyp
  • node.js (obviously)

Thanks herzi for creating db2.js in the first place!

查看更多
登录 后发表回答