/* initialize rule detecting context */ T_KRContext *kr_context_init(T_KRContextEnv *ptEnv) { T_KRContext *ptContext = kr_calloc(sizeof(T_KRContext)); if (ptContext == NULL) { KR_LOG(KR_LOGERROR, "kr_calloc ptContext failed!"); return NULL; } ptContext->ptEnv = ptEnv; /* reconnect database in thread */ T_DbsEnv *ptDbsEnv = ((T_KRContextEnv *)ptEnv)->ptDbsEnv; ptContext->ptDbsEnv = dbsConnect(ptDbsEnv->dsn, ptDbsEnv->user, ptDbsEnv->pass); if (ptContext->ptDbsEnv == NULL) { KR_LOG(KR_LOGERROR, "dbsConnect [%s] [%s] [%s] failed!", \ ptDbsEnv->dsn, ptDbsEnv->user, ptDbsEnv->pass); kr_free(ptContext); return NULL; } /* construct data */ ptContext->ptData = kr_data_construct(ptEnv->ptParam, ptEnv->dataModule, ptDbsEnv, ptEnv->ptHDICache, kr_data_get_type, kr_data_get_value); if (ptContext->ptData == NULL) { KR_LOG(KR_LOGERROR, "kr_data_construct failed!"); dbsDisconnect(ptContext->ptDbsEnv); kr_free(ptContext); return NULL; } /* construct flow */ return ptContext; }
int main(int argc, char *argv[]) { char hszDBName[128]; char hszDBUser[128]; char hszDBPass[32]; if (getenv("DBUSER") != NULL) { strncpy(hszDBUser, getenv("DBUSER"), sizeof(hszDBUser)); } if (getenv("DBPASS") != NULL) { strncpy(hszDBPass, getenv("DBPASS"), sizeof(hszDBPass)); } if (getenv("DBNAME") != NULL) { strncpy(hszDBName, getenv("DBNAME"), sizeof(hszDBName)); } printf("DBNAME:[%s], DBUSER:[%s], DBPASS:[%s].\n", \ hszDBName, hszDBUser, hszDBPass); dbsenv = dbsConnect(hszDBName, hszDBUser, hszDBPass); if (dbsenv == NULL) { fprintf(stderr, "dbsConnect Failed!\n"); return -1; } dbsRuleCur_test(dbsenv); dbsDatasrcFieldDefSel_test(dbsenv); dbsDisconnect(dbsenv); return 0; }
int main(int argc,char *argv[]) { T_DbsEnv *dbsenv = dbsConnect(\ getenv("DBNAME"), getenv("DBUSER"), getenv("DBPASS")); if (dbsenv == NULL) { fprintf(stderr, "dbsDbConnect Failed!"); return -1; } /* int ret = 0; T_SetCfgIns stSetCfgIns = {0}; stSetCfgIns.lInSetId = 1; strcpy(stSetCfgIns.caInElementValue, "haha"); strcpy(stSetCfgIns.caInElementDesc, "hehe"); ret = dbsSetCfgIns(dbsenv, &stSetCfgIns); if (ret != 0) { fprintf(stderr, "insert bad merchant[%s] failed[%d] [%d][%s][%s]\n", stSetCfgIns.caInElementValue, ret, dbsenv->sqlcode, dbsenv->sqlstate, dbsenv->sqlerrmsg); dbsRollback(dbsenv); } dbsCommit(dbsenv); fprintf(stdout, "insert bad merchant[%s]\n", stSetCfgIns.caInElementValue); */ dbsDisconnect(dbsenv); return 0; }
int main(int argc, char *argv[]) { int ret = -1; /* Parse Arguments */ ret = kr_parse_arguments(argc, argv); if (ret != 0) { fprintf(stderr, "kr_parse_arguments failed!\n"); return -1; } /* Connect database */ dbsenv = dbsConnect(getenv("DBNAME"), getenv("DBUSER"), getenv("DBPASS")); if (dbsenv == NULL) { fprintf(stderr, "dbsConnect [%s] [%s] [%s] failed!\n", getenv("DBNAME"), getenv("DBUSER"), getenv("DBPASS")); return -1; } /* generate define file */ if (gstArgs.gen_define) { ret = kr_traversal_datasrc("define"); if (ret != 0) { fprintf(stderr, "kr_traversal_datasrc define failed!\n"); goto clean; } } /* generate source file */ if (gstArgs.gen_source) { ret = kr_traversal_datasrc("source"); if (ret != 0) { fprintf(stderr, "kr_traversal_datasrc source failed!\n"); goto clean; } } /* Create Makefile */ if (gstArgs.gen_makefile) { ret = kr_generate_makefile(); if (ret != 0) { fprintf(stderr, "kr_generate_makefile failed!\n"); goto clean; } } clean: /*Disconnect database*/ dbsDisconnect(dbsenv); return ret; }
/* initialize rule detecting context */ T_KRContext *kr_context_init(T_KRContextEnv *ptEnv) { T_KRContext *ptContext = kr_calloc(sizeof(T_KRContext)); if (ptContext == NULL) { KR_LOG(KR_LOGERROR, "kr_calloc ptContext failed!"); return NULL; } ptContext->ptEnv = ptEnv; /* reconnect database in thread */ T_DbsEnv *dbsenv = ((T_KRContextEnv *)ptEnv)->ptDbs; ptContext->ptDbs = dbsConnect(dbsenv->dsn, dbsenv->user, dbsenv->pass); if (ptContext->ptDbs == NULL) { KR_LOG(KR_LOGERROR, "dbsConnect [%s] [%s] [%s] failed!", \ dbsenv->dsn, dbsenv->user, dbsenv->pass); kr_free(ptContext); return NULL; } ptContext->ptArg = kr_calloc(sizeof(T_KRContextArg)); if (ptContext->ptArg == NULL) { KR_LOG(KR_LOGERROR, "kr_calloc ptContext->ptArg failed!"); dbsDisconnect(ptContext->ptDbs); kr_free(ptContext); return NULL; } ptContext->ptDym = kr_dynamicmem_init(ptEnv->ptShm, \ ptEnv->dataModule, ptEnv->ruleModule); if (ptContext->ptDym == NULL) { KR_LOG(KR_LOGERROR, "kr_dynamicmem_init failed!"); dbsDisconnect(ptContext->ptDbs); kr_free(ptContext->ptArg); kr_free(ptContext); return NULL; } return ptContext; }