3

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.

5
  • 1
    Why the down vote? This is almost the same question as Connecting DB2 from Node.js on Windows-platform which has 3 up votes. Commented Jul 31, 2013 at 3:01
  • 1
    Just upgrade your gcc compiler. Not sure why minus. There are always different ways to do something and no one knows what is "best way" for you. Commented Jul 31, 2013 at 4:13
  • FYI, this is now officially a rabbit hole. I really want to do this, but I don't know how fast any progress will come. Commented Jul 31, 2013 at 13:28
  • Looks like my next steps are: Build gcc on the linux server. And for grins, install DB2 Client on my pi. Commented Jul 31, 2013 at 13:46
  • Dang. Building gcc is epic! It's been building for hours. Commented Aug 7, 2013 at 19:50

3 Answers 3

2

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?.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure when the API was updated, maybe it was shortly after you looked that they were working on this API. None the less, I'm happy to help, although it was a little bit delayed.
1

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.

1 Comment

Thanks herzi! db2.js is great.
1

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.