/*************************************************************************** * Licensed Materials - Property of HCL Technologies * * "Restricted Materials of HCL" * * HCL Informix ODBC Application * * Copyright HCL 2020 All rights reserved. * * Title: SmartTrigger.c * * Description: Direct Push Data/Smart Trigger ODBC application * * Author : Sheshnarayan Agrawal * *** TODO : 1. Support commented options in the help menu. * *************************************************************************** */ #include #include #include #ifndef NO_WIN32 #include #include #include #endif /*NO_WIN32*/ #include "infxcli.h" #define ERRMSG_LEN 200 /* Max number of tables demo program can handle */ #define MAXTAB 20 #define SQL_STMT_LEN 8192 #define IDS_MAX_LEN 1024 #define JSON_DATA_LEN 8192 /* Display length of the column values */ #define DISPLAY_LEN 31 #define NAMELEN 100 #define MAXARGSIZE 512 #define DB_OBJECT_LENGTH 128 #define SQL_QUERY_LENGTH 8192 SQLCHAR defDsn[] = "SmartTrigger"; SQLINTEGER no_of_tab = -1; SQLINTEGER no_of_own = -1; SQLINTEGER no_of_sel = -1; SQLINTEGER max_ops = 0; SQLINTEGER maxrecs = 1; //bigint txnid = 0; SQLINTEGER detach = 0; SQLINTEGER join = 0; SQLINTEGER delete = 0; SQLINTEGER timeout = 300; SQLINTEGER max_recs_per_read = 1; SQLINTEGER showData = 1; SQLSMALLINT tableCounter = 0; SQLSMALLINT ownerCounter = 0; SQLSMALLINT selectCounter = 0; SQLSMALLINT dbCounter = 0; SQLSMALLINT lableCounter = 0; /* Test related variables */ SQLCHAR datafile[512] = { 0 }; SQLHDBC hdbc; SQLHENV henv; SQLINTEGER sesID; SQLCHAR outfile[DB_OBJECT_LENGTH+1] = { 0 }; SQLCHAR dsnName[NAMELEN + 1] = { 0 }; typedef struct tagIfmxRegisterTrigger { void(*callback) (char *jsonOutBuf); SQLINTEGER sessionID; SQLCHAR *tableName; //Max value length 128 SQLCHAR *ownerName; //Max value length 128 SQLCHAR *dbName; //Max value length 128 SQLCHAR *sqlQuery; //Max value length 32K SQLCHAR *label; //Max value length 128 BOOL isDetachable; //Default False BOOL isDelete; //Default True SQLINTEGER timeOut; //Default 120 secs SQLINTEGER joinSessionID; //Default 0 SQLSMALLINT maxRecsPerRead; //Default 1 SQLINTEGER maxPendingOperations; //Default 0 } IFMX_SMART_TRIGGER; struct InputData { SQLSMALLINT myCount; SQLCHAR tableName[DB_OBJECT_LENGTH + 1]; SQLCHAR ownerName[DB_OBJECT_LENGTH + 1]; SQLCHAR dbName[DB_OBJECT_LENGTH + 1]; SQLCHAR sqlQuery[SQL_QUERY_LENGTH + 1]; SQLCHAR pdLable[DB_OBJECT_LENGTH + 1]; }; struct InputData inputValues[MAXTAB]; SQLINTEGER checkError (SQLRETURN rc, SQLSMALLINT handleType, SQLHANDLE handle, SQLCHAR* errmsg) { SQLRETURN retcode = SQL_SUCCESS; SQLSMALLINT errNum = 1; SQLCHAR sqlState[6]; SQLINTEGER nativeError; SQLCHAR errMsg[ERRMSG_LEN]; SQLSMALLINT textLengthPtr; if ((rc != SQL_SUCCESS) && (rc != SQL_SUCCESS_WITH_INFO)) { while (retcode != SQL_NO_DATA) { retcode = SQLGetDiagRec (handleType, handle, errNum, sqlState, &nativeError, errMsg, ERRMSG_LEN, &textLengthPtr); if (retcode == SQL_INVALID_HANDLE) { fprintf (stderr, "checkError function was called with an invalid handle!!\n"); return 1; } if ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO)) fprintf (stderr, "ERROR: %d: %s : %s \n", nativeError, sqlState, errMsg); errNum++; } fprintf (stderr, "%s\n", errmsg); return 1; /* all errors on this handle have been reported */ } else return 0; /* no errors to report */ } void Usage(char *progname) { fprintf(stdout, "\tVersion : 1.0 29 March 2018\n"); //fprintf(stdout, "\tUsage : %s [-DSN ] -D -T -O -S
-O -S
\n"); fprintf(stdout, "\t-S[-Select]