Esempio n. 1
0
int ensureVectorMaterialization(MYSQL * sqlConn, rdbVector * vectorInfo)
{
  /* Build the sql string */
  int length = strlen(sqlTemplateGetReferredViews) + 2*MAX_INT_LENGTH + 1;
  char strGetRefViewsSQL[length];
  sprintf( strGetRefViewsSQL, sqlTemplateGetReferredViews,
	   vectorInfo->metadataID, vectorInfo->metadataID );

  /* Execute the query */
  int success = mysql_query(sqlConn, strGetRefViewsSQL);
  if( success != 0 )
     return 0;

  /* Get the referenced views' ids */
  MYSQL_RES *sqlRes;
  MYSQL_ROW sqlRow;
  sqlRes = mysql_store_result(sqlConn);
  unsigned long int numRes = (unsigned long int)mysql_num_rows(sqlRes);
  unsigned long int viewIDs[numRes];
  int i = 0 ;

  if( numRes != 0 )
  {
     /* Get the view ids from the SQl result*/
     while( (sqlRow = mysql_fetch_row(sqlRes)) != NULL )
     {
        viewIDs[i] = atoi(sqlRow[0]);
	i++;
     }
     mysql_free_result(sqlRes);
  }
  else
  {
     while( (sqlRow = mysql_fetch_row(sqlRes)) != NULL );
     mysql_free_result(sqlRes);
  }

  /* Materialize current vector if a view */
  success = 1;
  if( vectorInfo->isView )
     success *= materializeVectorView(sqlConn, vectorInfo);

  /* Materialize all referenced views */
  for( i = 0 ; i < numRes ; i++ )
  {
     rdbVector *viewVector = newRDBVector();
     int loadSuccess = loadRDBVector(sqlConn, viewVector, viewIDs[i]);
      
     if( loadSuccess )
     {
        success = materializeVectorView(sqlConn, viewVector);
	clearRDBVector(&viewVector);
     }
  }
  return success;
}
Esempio n. 2
0
int materializeLogicVectorView(MYSQL * sqlConn, rdbVector * viewVector)
{
  /* Create the new table */
  rdbVector * newVector = newRDBVector();
  newVector->isView = 0;
  if( !createNewLogicVectorTable(sqlConn, newVector) ) 
     return 0;

  int success = internalMaterializeVectorView(sqlConn, viewVector, newVector);

  clearRDBVector(&newVector);

  return success;
}
Esempio n. 3
0
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;
}