Exemple #1
0
SRVRETCODE __declspec(dllexport) xp_HTM_Foo (SRV_PROC* pSrvProc){	
	// declares and initalizations.
	int         paramCount;						// number of parameters passed
    BYTE        bType1, bType2,bType3;			// types of params
    unsigned long cbMaxLen1, cbMaxLen2, cbMaxLen3; // max lengths of params
    unsigned long cbActualLen1, cbActualLen2,cbActualLen3;	// actual lenghts
    BOOL        fNull1, fNull2, fNull3;			// null flags
	char	*	pzCoordinateSpec;				// pointer to the input spec (polar or cartesian)
	INT64		result;							// the result arry that we build locally
	char	 	czErrorMsg [1000] = "IG";		// diagnostic message output
	int			retcode;
	htmSqlInterface htm;						// holds the htm object

	//----------------------------------------------------------------
	// PARSE INPUT AND OUTPUT PARAMS
    // Count the number of parameters.
    paramCount = srv_rpcparams(pSrvProc);
	//
	// DEBUG
	//
    if (3 != paramCount)
		{ printUsageLookup (pSrvProc); retcode = XP_ERROR; goto exit;}

	// Get Coordinates param datatype, and param length information of 
    if (srv_paraminfo(pSrvProc, 1, &bType1, &cbMaxLen1, &cbActualLen1, NULL, &fNull1) == FAIL)
         ErrorExit("srv_paraminfo failed...");

	// Is Coordinate param a character string
	if (bType1 != SRVBIGVARCHAR   && bType1 != SRVBIGCHAR &&
		bType1 != SRVVARCHAR	  && bType1 != SRVCHAR)
		ErrorExit("Coordinate param should be a string.");

	// Is Coordinate param non-null
	if (fNull1 || cbActualLen1 < 1 || cbMaxLen1 <= cbActualLen1) // ##JG1 need zero termination.
		ErrorExit("Coordinate param is null.");

	// Get pointer to Coordinate param
	pzCoordinateSpec = (char *) srv_paramdata (pSrvProc, 1);
	if (pzCoordinateSpec == NULL)
		ErrorExit("Coordinate param is null.");
	pzCoordinateSpec[cbActualLen1] = 0;							// ##JG1  zero terminate the string
 
    // Get OutputBigInt datatype   
    if (srv_paraminfo(pSrvProc, 2, &bType2, &cbMaxLen2, &cbActualLen2, NULL, &fNull2) == FAIL)
         ErrorExit("srv_paraminfo failed to get HTM_ID param");

	// Make sure OutputVector param is a return (OUTPUT) parameter
	if ((srv_paramstatus(pSrvProc,2) & SRV_PARAMRETURN) == FAIL)
		{ ErrorExit("HTM_ID param should be an OUTPUT param"); }

	// Is parameter a big int datatype
	if ((bType2 != SRVINT8) && // this should work but it does not.
		(bType2 != SRVVARCHAR) && (bType2 != SRVBIGVARCHAR) && 
		(bType2 != SRVVARBINARY) && (bType2 != SRVBIGVARBINARY) && 
		(bType2 != SRVBINARY) &&(bType2 != SRVBIGBINARY) &&
		(bType2 != SRVIMAGE) 
		)  { 
 		 ErrorExit( "HTM_ID param should be an OUTPUT param should be BINARY(8)");
		} 

	// Get ErrorMsg param datatype, and param length information  
    if (srv_paraminfo(pSrvProc, 3, &bType3, &cbMaxLen3, &cbActualLen3, NULL, &fNull3) == FAIL)
         ErrorExit("srv_paraminfo failed on ErrorMsg string Param");

	// Is ErrorMsg param a character string
	if (bType3 != SRVBIGVARCHAR   && bType3 != SRVBIGCHAR &&
		bType3 != SRVVARCHAR	  && bType3 != SRVCHAR)
		ErrorExit("ErrorMsg string param should be a string.");

	// Is ErrorMsg param non-null and at least 100 bytes?
	if (cbMaxLen3 < 100)
	{ /*sprintf(czErrorMsg,"\nThe error msg string length is  %d  and max len is %d :\n", cbActualLen3,cbMaxLen3);
  		srv_sendmsg(pSrvProc, SRV_MSG_ERROR, XP_HTM_ERROR, SRV_INFO, 1,
            NULL, 0, (DBUSMALLINT) __LINE__,  czErrorMsg , SRV_NULLTERM);*/
 		ErrorExit("ErrorMsg string param is less than 100 bytes.");
		}

	// Make sure ErrorMsg param is a return (OUTPUT) parameter
	if ((srv_paramstatus(pSrvProc,3) & SRV_PARAMRETURN) == FAIL)
		{ ErrorExit("ErrorMsg string param is must be an output param."); }
  
	/*********************CALL HTM CODE***************************************/
	result = htm.lookupID(pzCoordinateSpec);	// do the lookup to get the HTM_ID
	if (htm.err()) 
		{strcpy(czErrorMsg,htm.error());
		 if (strlen(czErrorMsg) == 0)
			strcpy(czErrorMsg,"HTM code failed to give diagnostic message");
		}	// return error string if there is one.
    /**********************************************************************/ 

	// Permute the Int64 so that it can cast from string to BIGINT in SQL
	Permute(result, (char*) &result);
	// Set the output parameter to the string
    if (srv_paramsetoutput(pSrvProc, 2, (BYTE *) &result, 8, FALSE) == FAIL)
		  		ErrorExit( "srv_paramsetoutput failed on HTM_ID...");
	
    //Set Diagnostic String
	if (srv_paramsetoutput(pSrvProc, 3, (BYTE *) czErrorMsg, strlen(czErrorMsg), FALSE) == FAIL)
				ErrorExit( "srv_paramsetoutput failed on Msg...");

    // Send results complete message the the ODS library.
    srv_senddone(pSrvProc, (SRV_DONE_COUNT | SRV_DONE_MORE), 0, 1);
	retcode = XP_NOERROR;
	// return success to the caller
exit:  
	return(retcode);

}   // end of xp_HTM_Lookup
Exemple #2
0
RETCODE __declspec(dllexport) xp_AsText(SRV_PROC *pSrvProc)
{
#ifdef _DEBUG
// In a debug build, look up the data type name for assistance.
DBCHAR *pdbcDataType = NULL;
int cbDataType = 0;
#endif

	COM_TRY {
	// Count up the number of input parameters.  There should be exactly two.
		if (2 != srv_rpcparams(pSrvProc)) 
			return PRINTUSAGE (pSrvProc);	// Send error message and return

	// Use srv_paraminfo to get data type and length information.
	BYTE bType1, bType2;
	ULONG cbMaxLen1, cbMaxLen2;
	ULONG cbActualLen1, cbActualLen2;
	BOOL fNull1, fNull2;

	// check 1st parameter
		if (FAIL == srv_paraminfo(pSrvProc, 1, &bType1, &cbMaxLen1, &cbActualLen1, NULL, &fNull1))
			return PRINTERROR(pSrvProc, "srv_paraminfo for parameter 1 failed...");

#ifdef _DEBUG
    // A debugging aid. Get the name of the data type of the parameter.
	    pdbcDataType = srv_symbol(SRV_DATATYPE, (int)bType1, &cbDataType);
#endif

	// make sure first parameter is of image datatype (should be geometry)
		if (bType1 != SRVIMAGE)
			return PRINTUSAGE(pSrvProc);

	// check 2nd parameter
		if (FAIL == srv_paraminfo(pSrvProc, 2, &bType2, &cbMaxLen2, &cbActualLen2, NULL, &fNull2))
			return PRINTERROR(pSrvProc, "srv_paraminfo for parameter 2 failed...");

#ifdef _DEBUG
    // A debugging aid. Get the name of the data type of the parameter.
	    pdbcDataType = srv_symbol(SRV_DATATYPE, (int)bType2, &cbDataType);
#endif

	// make sure second parameter is of ntext datatype
		if (bType2 != SRVNVARCHAR && bType2 != SRVBIGVARCHAR)
			return PRINTUSAGE(pSrvProc);

	// make sure second parameter is a return (OUTPUT) parameter
		if (!(srv_paramstatus(pSrvProc, 2) & SRV_PARAMRETURN))
			return PRINTUSAGE(pSrvProc);

	// retrieve geometry
	std::auto_ptr<BYTE> Geometry (new BYTE[cbActualLen1]);

		if (FAIL == srv_paraminfo(pSrvProc, 1, &bType1, &cbMaxLen1, &cbActualLen1, Geometry.get(), &fNull1))
			return PRINTERROR(pSrvProc, "srv_paraminfo(data) for parameter 1 failed...");
	
	// convert geometry to wkt format
	CComBSTR bstrWKT;
	WUnknown Unk (*(GUID *)Geometry.get());
	WPersistMemoryWks PM (Unk);

		THROW_FAILED_HRESULT(PM -> Load (Geometry.get() + sizeof(GUID), cbActualLen1 - sizeof(GUID)));
		THROW_FAILED_HRESULT(PM -> SaveWkt (&bstrWKT, false));

	// set output parameter
	ULONG ulLen = 0;
	BYTE *pOutData = NULL;

		USES_CONVERSION;
		if (SRVNVARCHAR == bType2) {
			pOutData = (BYTE *)bstrWKT.m_str;
			ulLen = min(cbMaxLen2, ULONG(bstrWKT.Length()*sizeof(OLECHAR)));
		} else {
			pOutData = (BYTE *)OLE2A(bstrWKT);
			ulLen = min(cbMaxLen2, ULONG(bstrWKT.Length()));
		}

		if (FAIL == srv_paramsetoutput(pSrvProc, 2, pOutData, ulLen, FALSE))
			return PRINTERROR(pSrvProc, "srv_paramsetoutput for parameter 2 failed...");

		srv_senddone(pSrvProc, SRV_DONE_MORE, 0, 0);

	} COM_CATCH_RETURN(XP_ERROR);
	return XP_NOERROR;
}
Exemple #3
0
SRVRETCODE __declspec(dllexport) xp_HTM_Neighbors (SRV_PROC* pSrvProc) {
	// declares and initializations
	int         paramCount;						// number of parameters passed  
    BYTE        bType1, bType2,bType3;			// types of params
    unsigned long cbMaxLen1, cbMaxLen2, cbMaxLen3; // max lengths of params
    unsigned long cbActualLen1, cbActualLen2,cbActualLen3;	// actual lengths
    BOOL        fNull1, fNull2, fNull3;			// null flags

	char	*	pzCoordinateSpec;				// pointer to the input spec (polar or cartesian)

	char	 	czErrorMsg [1000] = OK_MSG;		// diagnostic message output
	int			retcode;
	INT64		result[MAX_OUTPUT_VECTOR_LENGTH+1]; // the result array that we build locally
	unsigned int len;							// length (in bytes) of output array

	////////////////////
	ValueVector ranges;
	size_t		nRanges;
	htmSqlInterface htm;

	///////////////////////////////////////////////////////
	// zero the memory array
	memset((void *) result, 0, 8*MAX_OUTPUT_VECTOR_LENGTH);
 
	//----------------------------------------------------------------
	// PARSE INPUT AND OUTPUT PARAMS
    // Count the number of parameters.
	paramCount = srv_rpcparams(pSrvProc);

    if (paramCount != 3)
	{  printUsageHTM_Cover(pSrvProc); retcode = XP_ERROR; goto exit;}

	// Get Coordinates param datatype, and param length information of 
    if (srv_paraminfo(pSrvProc, 1, &bType1, &cbMaxLen1, &cbActualLen1, NULL, &fNull1) == FAIL)
         ErrorExit("srv_paraminfo failed...");

	// Is Coordinate param a character string
	if (bType1 != SRVBIGVARCHAR   && bType1 != SRVBIGCHAR &&
		bType1 != SRVVARCHAR	  && bType1 != SRVCHAR)
		ErrorExit("Coordinate param should be a string.");

	// Is Coordinate param non-null
	if (fNull1 || cbActualLen1 < 1 || cbMaxLen1 <= cbActualLen1) // ##JG1 need zero termination.
		ErrorExit("Coordinate param is null.");

	// Get pointer to Coordinate param
	pzCoordinateSpec = (char *) srv_paramdata (pSrvProc, 1);
	if (pzCoordinateSpec == NULL)
		ErrorExit("Coordinate param is null.");
	pzCoordinateSpec[cbActualLen1] = 0;							// ##JG1  zero terminate the string
 
    // Get OutputVector datatype, and param length information  
    if (srv_paraminfo(pSrvProc, 2, &bType2, &cbMaxLen2, &cbActualLen2, NULL, &fNull2) == FAIL)
         ErrorExit("Failed to get type info on HTM Vector param...");

	// Make sure OutputVector param is a return (OUTPUT) parameter
	if ((srv_paramstatus(pSrvProc,2) & SRV_PARAMRETURN) == FAIL)
		{  ErrorExit("HTM Vector param must be an output param"); }

	// Is parameter a big char or varchar datatype
	if (bType2 != SRVBIGVARCHAR   && bType2 != SRVBIGCHAR &&
		bType2 != SRVBIGVARBINARY && bType2 != SRVBIGBINARY &&
		bType2 != SRVIMAGE        && bType2 != SRVVARBINARY)
		{ ErrorExit("HTM Vector param must be an VARBINARY(8000)"); }

    // Is it large enough to hold data
	if (cbMaxLen2 < MAX_OUTPUT_VECTOR_LENGTH)
		ErrorExit("HTM Vector param must be an VARBINARY(8000)...");

	// Get ErrorMsg param datatype, and param length information  
    if (srv_paraminfo(pSrvProc, 3, &bType3, &cbMaxLen3, &cbActualLen3, NULL, &fNull3) == FAIL)
         ErrorExit("Failed to get type info on Error Message param...");

	// Is ErrorMsg param a character string
	if (bType3 != SRVBIGVARCHAR   && bType3 != SRVBIGCHAR &&
		bType3 != SRVVARCHAR	  && bType3 != SRVCHAR)
		ErrorExit("ErrorMsg string param should be a string.");

	// Is ErrorMsg param non-null and at least 100 bytes?
	if (cbMaxLen3 < 100) { 
 		ErrorExit("ErrorMsg string param is less than 100 bytes.");
		}

	// Make sure ErrorMsg param is a return (OUTPUT) parameter
	if ((srv_paramstatus(pSrvProc,3) & SRV_PARAMRETURN) == FAIL)
		{ ErrorExit("ErrorMsg string param is must be an output param."); }

	/*********************CALL HTM CODE***************************************/
	nRanges = htm.intersect1(pzCoordinateSpec,ranges);
	if (htm.err()) {						// if error
		strcpy(czErrorMsg,htm.error());		// pass back error message
		if (strlen(czErrorMsg) == 0)		// make up error message if its missing.
			strcpy(czErrorMsg,"HTM code failed to give diagnostic message");
		len = 0;							// result vector is empty
		}									// end error case
    else if (nRanges > MAX_OUTPUT_VECTOR_LENGTH/2) {
		strcpy(czErrorMsg,					// if vector overflowed (we are in BIG trouble).
			"HTM routines returned more than 500 triangles, overflowed return vector.");
		len = 0;
		}									// end overflow case
	else 
	{									// this is the NO ERROR case
		strcpy(czErrorMsg,OK_MSG);			// construct error message
 		len = nRanges*16;					//  each range is 16 bytes (pair of int64)
		for(size_t i = 0; i < nRanges; i++)	// permute them so that they map to strings
		{
			// Permute(ranges[i].lo, (char*) &result[2*i]);
			// Permute(ranges[i].hi, (char*) &result[2*i+1]);
			Permute(nbr_count++, (char*) &result[2*i]);
			Permute(nbr_count++, (char*) &result[2*i+1]);
		}						 		// end permute
	}	// end no-error case
	/*************************************************************************/

	// Set the output parameter to the string
	if (srv_paramsetoutput(pSrvProc, 2, (BYTE *) result, len, FALSE) == FAIL)
 		  		ErrorExit( "srv_paramsetoutput failed...");

	//Set Diagnostic String
	if (srv_paramsetoutput(pSrvProc, 3, (BYTE *) czErrorMsg, strlen(czErrorMsg), FALSE) == FAIL)
				ErrorExit( "srv_paramsetoutput failed on Msg...");

    // Send results complete message the the ODS library.
    if (srv_senddone(pSrvProc, (SRV_DONE_COUNT | SRV_DONE_MORE), 0, 1) == FAIL)
				ErrorExit( "srv_senddone fail...");  
		 
	 
	retcode = XP_NOERROR;
	// return success to the caller
exit:  
	return(retcode);

}   // end of xp_HTM