Document Type | Technical Information
Category | Interface/Integration
Document Number | TIITI017
Overview
When connecting to a remote DB using SQL, you must pay attention to firewall settings, compile environment, and environment variable restoration.
Additionally, guidance on example code and configuration is provided.
Method
Precautions
- You must disable the firewall settings on the remote DB to allow connection.
- The include path in tbpc.cfg must be accurate to prevent errors where header files cannot be found during precompile.
- Check compile options per OS to ensure a proper executable file is created.
- If you do not revert TB_SID back to the original local DB after testing, local DB connection and control may become impossible.
Example Code and Configuration
test.tbc Source (Refer to kss)
This is an example of connecting to a remote DB using ESQL and querying data.
#include <stdio.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
#define USERPASS "tibero/tmax"
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR userpass[20] = {strlen(USERPASS), USERPASS};
char col3_value[100];
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT :userpass;
memset(col3_value, 0x00, sizeof(col3_value));
if ( sqlca.sqlcode != 0 ) {
printf(" Connection Fail ( SQLCODE : %d ) !! \n\n", sqlca.sqlcode );
}
else {
printf(" Connected to Tibero as user tibero \n\n");
EXEC SQL
select col3
into :col3_value
from esql_tmp1
where col1 = 1;
printf("[result] col3 : [%s]\n", col3_value);
}
EXEC SQL COMMIT WORK RELEASE;
return 0;
}Compile Options (Linux 64bit)
The compile command required to build the ESQL program.
gcc -o test test.c -L$TB_HOME/client/lib -ltbertl -ltbcli -lpthread -lm -I$TB_HOME/client/include
tbpc.cfg
The red-colored lines need to be reset according to your environment.
#------------------------------------------------------------------------------ # # /home/autodist/build_160708_1952/tibero5/client/config/tbpc.cfg # # tbESQL Configuration file for Preprocessor # # Each command should be specified in a single line by itself terminated by # a newline. # Lines starting with a # character are comments which are ignored. # # Generated at Fri Jul 8 10:18:43 KST 2016 # #------------------------------------------------------------------------------ INCLUDE=$TB_HOME/client/include INCLUDE=/usr/lib/gcc/x86_64-redhat-linux/4.4.4/include/ INCLUDE=/usr/include