CONDITION TBL_DeleteTable(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList, const char* tableName) { TBL_CONTEXT* tc; char* dbName; /*char *tableName;*/ int foundit; char deleteCommand[2048]; PGresult* res; PGconn* conn; #ifdef CTN_USE_THREADS THR_ObtainMutex(FAC_TBL); #endif tc = G_ContextHead; foundit = 0; while (tc != (TBL_CONTEXT *) NULL) { if (tc == (TBL_CONTEXT *) (*handle)) { dbName = tc->databaseName; /*tableName = tc->tableName;*/ conn = (PGconn*)tc->dbSpecific; foundit = 1; break; } tc = tc->next; } if (!foundit) { #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return COND_PushCondition(TBL_ERROR(TBL_BADHANDLE), "TBL_Delete"); } strcpy(deleteCommand, "DELETE FROM "); strcat(deleteCommand, tableName); if ((criteriaList != (TBL_CRITERIA *) NULL) && (criteriaList->FieldName != 0)) { strcat(deleteCommand, " WHERE "); addCriteria(criteriaList, deleteCommand); } strcat(deleteCommand, ";" ); res = PQexec(conn, deleteCommand); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, PQresultErrorMessage(res)); fprintf(stderr, "<%s>\n", deleteCommand); exit(1); } PQclear(res); #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return TBL_NORMAL; }
DatabaseRule::DatabaseRule( XMLNode* ruleNode ) : m_ruleScore( 0 ) { m_ruleName = getStringXMLAttribute( ruleNode, "name", "noRule" ); XMLNode* criteriaListNode = ruleNode->FirstChildElement( "Criteria" ); for( XMLNode* criteriaNode = criteriaListNode->FirstChildElement( "Criterion" ); criteriaNode; criteriaNode = criteriaNode->NextSiblingElement("Criterion") ) { addCriteria( criteriaNode ); } XMLNode* responseNode = ruleNode->FirstChildElement( "Response" ); m_responseName = getStringXMLAttribute( responseNode, "name", "noname" ); }
CONDITION TBL_SelectTable(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList, TBL_FIELD * fieldList, long *count, CONDITION(*callback) (), void *ctx, const char* tableName) { TBL_CONTEXT* tc; TBL_FIELD* fp; char tabcol[100]; char* dbName; int i; int ret; int FoundTextorBinary; int foundit; char selectCommand[2048]; long realcount; long * lp; PGresult* res; PGconn* conn; int nTuples; #ifdef CTN_USE_THREADS THR_ObtainMutex(FAC_TBL); #endif tc = G_ContextHead; foundit = 0; while (tc != (TBL_CONTEXT *) NULL) { if (tc == (TBL_CONTEXT *) (*handle)) { dbName = tc->databaseName; /*tableName = tc->tableName;*/ conn = (PGconn*)tc->dbSpecific; foundit = 1; break; } tc = tc->next; } if (!foundit) { #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return COND_PushCondition(TBL_ERROR(TBL_BADHANDLE), "TBL_Select"); } strcpy(selectCommand, "SELECT "); addFieldNames(fieldList, selectCommand); strcat(selectCommand, " FROM " ); strcat(selectCommand, tableName); if ((criteriaList != (TBL_CRITERIA *) NULL) && (criteriaList->FieldName != 0)) { strcat(selectCommand, " WHERE "); addCriteria(criteriaList, selectCommand); } strcat(selectCommand, ";" ); if (count != (long *) NULL) lp = count; else lp = &realcount; *lp = 0; res = PQexec(conn, selectCommand); if (PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr, PQresultErrorMessage(res)); fprintf(stderr, "<%s>\n", selectCommand); exit(1); } nTuples = PQntuples(res); for (i = 0; i < nTuples; i++) { (*lp)++; extractFieldResults(res, i, fieldList); if (callback != NULL) { if (callback(fieldList, *lp, ctx) != TBL_NORMAL) { PQclear(res); #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return COND_PushCondition(TBL_ERROR(TBL_EARLYEXIT), "TBL_Select"); } } } PQclear(res); #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return TBL_NORMAL; }
/* TBL_Update ** ** Purpose: ** This updates existing records in the named table. ** ** Parameter Dictionary: ** TBL_HANDLE **handle: The pointer for the database/table pair ** to be accessed for modification. This table must be open. ** TBL_CRITERIA *criteriaList: Contains the list of criteria to ** select those records that should be updated. ** TBL_FIELD *fieldList: Contains a list of the keyword/value ** pairs to be used to modify the selected records. ** ** Return Values: ** TBL_NORMAL: normal termination. ** TBL_BADHANDLE: The handle passed to the routine was invalid. ** TBL_DBNOEXIST: The database specified does not exist. ** TBL_NOFIELDLIST: No keyword/value pairs were specified for update. ** TBL_UPDATEFAILED: The insert operation failed most probably from ** a bad specification in the fieldList. This error ** return could result from a misspelled keyword, etc. ** ** Notes: ** Nothing unusual. ** ** Algorithm: ** The records which match the (ANDED) criteria in criteriaList ** are retreived and updated with the information contained in ** fieldList. Only the fields contained in fieldList will be ** updated by this call. */ CONDITION TBL_Update(TBL_HANDLE ** handle, const TBL_CRITERIA * criteriaList, TBL_UPDATE * updateList) { TBL_CONTEXT* tc; TBL_FIELD* fp; char tabcol[100]; char* dbName; char *tableName; int i; int ret; int FoundTextorBinary; int foundit; char updateCommand[2048]; PGresult* res; PGconn* conn; int nTuples; #ifdef CTN_USE_THREADS THR_ObtainMutex(FAC_TBL); #endif tc = G_ContextHead; foundit = 0; while (tc != (TBL_CONTEXT *) NULL) { if (tc == (TBL_CONTEXT *) (*handle)) { dbName = tc->databaseName; tableName = tc->tableName; conn = (PGconn*)tc->dbSpecific; foundit = 1; break; } tc = tc->next; } if (!foundit) { #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return COND_PushCondition(TBL_ERROR(TBL_BADHANDLE), "TBL_Update"); } strcpy(updateCommand, "UPDATE "); strcat(updateCommand, tableName); strcat(updateCommand, " SET "); addUpateValues(updateList, updateCommand); if ((criteriaList != (TBL_CRITERIA *) NULL) && (criteriaList->FieldName != 0)) { strcat(updateCommand, " WHERE "); addCriteria(criteriaList, updateCommand); } strcat(updateCommand, ";" ); res = PQexec(conn, updateCommand); if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, PQresultErrorMessage(res)); fprintf(stderr, "<%s>\n", updateCommand); exit(1); } PQclear(res); #ifdef CTN_USE_THREADS THR_ReleaseMutex(FAC_TBL); #endif return TBL_NORMAL; }