/* --------- Functions to compare with values from a DBVector ---------- */ int compareWithDBVector(MYSQL * sqlConn, rdbVector * resultVector, rdbVector * dataVector, rdbVector * compareVector, char * comparisonOp) { if(dataVector->sxp_type == SXP_TYPE_COMPLEX || compareVector->sxp_type == SXP_TYPE_COMPLEX) return 0; /* Build the sql string */ int size = compareVector->size; int length = strlen(sqlTemplateCompareWDBVector) + strlen(dataVector->tableName) + strlen(compareVector->tableName) + strlen(comparisonOp) + 4*MAX_INT_LENGTH + 1; char strCompareSQL[length]; sprintf( strCompareSQL, sqlTemplateCompareWDBVector, size, size, comparisonOp, dataVector->tableName, compareVector->tableName, size, size ); /* Create the results (logic) view */ resultVector->sxp_type = SXP_TYPE_LOGIC; resultVector->isView = TRUE; resultVector->size = dataVector->size; int success = createNewLogicVectorView(sqlConn, resultVector, strCompareSQL); if( success ) createVectorViewReferences(sqlConn, resultVector, dataVector, compareVector); else resultVector->size = 0; return success; }
int subtractDoubleFromNumericVector(MYSQL * sqlConn, rdbVector * result, rdbVector *input1, double y) { /* Both inputs must either be integers or doubles or logic */ if( input1->sxp_type != SXP_TYPE_INTEGER && input1->sxp_type != SXP_TYPE_DOUBLE && input1->sxp_type != SXP_TYPE_LOGIC ) return 0; /* Build the sql string */ int length = strlen(sqlTemplateSimpleNumericBinary) + strlen(MINUS_SIGN) + strlen(input1->tableName) + MAX_DOUBLE_LENGTH + 1; char *sqlString = malloc( length * sizeof(char) ); sprintf(sqlString, sqlTemplateSimpleNumericBinary, MINUS_SIGN, y, input1->tableName); /* Create the results view */ initRDBVector(&result, 1, 0); result->size = input1->size; int success = 0; success = createNewDoubleVectorView(sqlConn, result, sqlString); free(sqlString); /* Create the view references */ if( success ) createVectorViewReferences(sqlConn, result, input1, input1); else result->size = 0; return success; }
int internalHandleNumericBinOp(MYSQL * sqlConn, rdbVector * result, rdbVector * input1, rdbVector * input2, char * sign, int forceDouble) { /* Both inputs must either be integers or doubles or logic */ if( input1->sxp_type != SXP_TYPE_INTEGER && input1->sxp_type != SXP_TYPE_DOUBLE && input1->sxp_type != SXP_TYPE_LOGIC ) return 0; if( input2->sxp_type != SXP_TYPE_INTEGER && input2->sxp_type != SXP_TYPE_DOUBLE && input2->sxp_type != SXP_TYPE_LOGIC ) return 0; /* Build the sql string and create the view */ char * sqlString; buildNumericBinaryOpsSQL(input1, input2, sign, &sqlString); initRDBVector(&result, 1, 0); result->size = (input1->size > input2->size)? input1->size : input2->size; int success = 0; if( (input1->sxp_type == SXP_TYPE_INTEGER || input1->sxp_type == SXP_TYPE_LOGIC ) && (input2->sxp_type == SXP_TYPE_INTEGER || input2->sxp_type == SXP_TYPE_LOGIC ) && !forceDouble) { success = createNewIntegerVectorView(sqlConn, result, sqlString); } else { success = createNewDoubleVectorView(sqlConn, result, sqlString); } free(sqlString); if( success ) createVectorViewReferences(sqlConn, result, input1, input2); else result->size = 0; return success; }
int internalCompareWithValues(MYSQL * sqlConn, rdbVector * resultVector, rdbVector * dataVector, char * strComparison) { /* Build the sql string */ int length = strlen(sqlTemplateCompareWithValues) + strlen(strComparison) + strlen(dataVector->tableName) + 1; char strCompareSQL[length]; sprintf( strCompareSQL, sqlTemplateCompareWithValues, strComparison, dataVector->tableName ); /* Create the results (logic) view */ resultVector->sxp_type = SXP_TYPE_LOGIC; resultVector->isView = TRUE; resultVector->size = dataVector->size; int success = createNewLogicVectorView(sqlConn, resultVector, strCompareSQL); if( success ) createVectorViewReferences(sqlConn, resultVector, dataVector, dataVector); else resultVector->size = 0; return success; }
int internalHandleComplexBinOp(MYSQL * sqlConn, rdbVector * result, rdbVector * input1, rdbVector * input2, int op) { /* Create some temporary rdbVector objects */ rdbVector * cInput1; rdbVector * cInput2; if( input1->sxp_type == SXP_TYPE_INTEGER || input1->sxp_type == SXP_TYPE_DOUBLE || input1->sxp_type == SXP_TYPE_LOGIC ) { initRDBVector(&cInput1, input1->isView, 1); if( !convertNumericToComplex(sqlConn, input1, cInput1) ) { clearRDBVector(&cInput1); return 0; } } else if( input1->sxp_type == SXP_TYPE_COMPLEX ) { copyRDBVector(&cInput1, input1, 1); } else { return 0; } if( input2->sxp_type == SXP_TYPE_INTEGER || input2->sxp_type == SXP_TYPE_DOUBLE || input2->sxp_type == SXP_TYPE_LOGIC ) { initRDBVector(&cInput2, input2->isView, 1); if( !convertNumericToComplex(sqlConn, input2, cInput2) ) { clearRDBVector(&cInput1); clearRDBVector(&cInput2); return 0; } } else if( input2->sxp_type == SXP_TYPE_COMPLEX ) { copyRDBVector(&cInput2, input2, 1); } else { clearRDBVector(&cInput1); return 0; } /* Build the sql string */ char * sqlString; switch( op ) { case PLUS_OP: buildComplexAddSubSQL(cInput1, cInput2, PLUS_SIGN, &sqlString); break; case MINUS_OP: buildComplexAddSubSQL(cInput1, cInput2, MINUS_SIGN, &sqlString); break; case MULT_OP: buildComplexMultDivSQL(cInput1, cInput2, sqlTemplateComplexMultiply_EQ, sqlTemplateComplexMultiply_NE, &sqlString); break; case DIV_OP: buildComplexMultDivSQL(cInput1, cInput2, sqlTemplateComplexDivide_EQ, sqlTemplateComplexDivide_NE, &sqlString); break; default: clearRDBVector(&cInput1); clearRDBVector(&cInput2); return 0; } initRDBVector(&result, 1, 0); result->size = (cInput1->size > cInput2->size)? cInput1->size : cInput2->size; /* Create the view */ int success = createNewComplexVectorView(sqlConn, result, sqlString); if( success ) createVectorViewReferences(sqlConn, result, cInput1, cInput2); else result->size = 0; /* Clean up */ free(sqlString); clearRDBVector(&cInput1); clearRDBVector(&cInput2); return success; }