Note: The included ctsql.node and ctsqlapi.dll are 64-bit only!
Prerequisites
Make sure you have Node.js, npm, and Python installed on your computer. Python is used for building ffi-napi. To verify this, type the following commands into a shell:
node -v
npm -v
python -V
Node.js and npm are installed from the same package, which is available from Node.js.org. Node.js version 10 or later is required.
Python can be downloaded from the Python.org website.
The first time you use this tutorial, npm may need to build the ffi-napi module. For this to work properly, your computer should have a compiler installed on it. On Linux, this is usually g++. On Windows this is usually the Visual C++ Build Tools. Note that the Windows version of the Node.js installer might have already installed these tools for you.
Installing the Node-RED Node
To install the FairCom SQL Node-RED node:
node -v
npm -v
python -V (upper-case “V”)
Node.js and npm are installed from the same package, which is available from Node.js.org. Node.js version 12 or later is required. We are not compatible with Node.js version 8 or 10.
Python can be downloaded from Python.org.
sudo npm install -g --unsafe-perm node-red
On Windows, this is usually the following folder: C:\Users\my_name\.node-red
On Linux, this is usually the following folder: ~\.node-red
If this folder is missing, you might have to start and stop Node-RED once, by using the following command in a command shell, for example:
> node-red
After Node-RED fully starts up, press <Ctrl+C> or close the command prompt to terminate it.
npm --prefix . install <path to node-red-contrib-ctreesql folder>
In the above command, <path to node-red-contrib-ctreesql> is the full path to the node-red-contrib-ctreesql folder which is in the drivers\node-red.sql folder. For example:
C:\FairCom\c-treeEDGE.Win.Server.x86.64bit.v11.8.1.580\drivers\node-red.sql\node-red-contrib-ctreesql.
The first time you run this command, it will download packages, so be sure your computer is connected to the Internet. Also, the first time, it may need to build ffi-napi.
On Windows, this will make a "node-red-contrib-ctreesql" item appear in your C:\Users\my_name\.node-red\node_modules folder.
> node-red
Watch the console output for an error that looks like the following:
[warn] [node-red-contrib-ctreesql/ctreeSQL] Could not find ctsqlapi library. Neither on path nor locally.
If you see this error, you will have to make a DLL or shared library available to the OS. On Windows, you will have to edit the PATH to contain a reference to the drivers\ctree.drivers\bin directory of your FairCom product. For example:
set PATH=%PATH;%C:\FairCom\c-treeEDGE.Win.Server.x86.64bit.v11.8.1.580\drivers\ctree.drivers\bin
On many Linux-based operating systems, copying drivers/ctree.drivers/lib/libctsqlapi.so into /usr/lib (/usr/lib64 for CentOS) and running ldconfig will make the library available. Make sure Read and Execute permissions are granted to the library.
You should now see a new node, called ctreeSQL, under the "storage" section.
Set Host to 127.0.0.1.
Set Port to 6597, or to whatever the SQL_PORT is in your FairCom product's ctsrvr.cfg configuration file.
Set User to “ADMIN” and set Password to “ADMIN”.
Set Database to “ctreeSQL”.
(You can ignore the Query Type setting for now.)
select * from admin.syscolumns
You can leave the payload set to "timestamp".
Click DONE.
Troubleshooting:
Error "ctsqlConnectError: ctsql failed to connect with error -20212"
The most common cause of this run-time error is the FairCom Database Engine is not running on your machine. The most likely cause is that the c-tree evaluation license times out after 3 hours and shuts down the server. The solution is to restart the server. See Starting the FairCom Database Engine.
Note: If you are using a self-signed certificate, Node-RED may reject the connection because it is considered unauthorized and Node-RED will show a SELF_SIGNED_CERT_IN_CHAIN error on the console. To work around this, set the NODE_TLS_REJECT_UNAUTHORIZED environment variable to 0, and restart Node-RED.
Example for Unix:
$ export NODE_TLS_REJECT_UNAUTHORIZED=0
$ node red.js -v push2omnibus.json