Subject | UDF Problem |
---|---|
Author | Robert Tulloch |
Post date | 2004-01-07T05:05:23Z |
Hi:
Previously posted in Borland Interbase General group. No responses.
I have tested the dll with a test probelam and it works fine.
IBConsole - This returns an empty dataset and pops up an error that
connection to database lost.
I have written other udfs and never had a connection lost error before.
Any thoughts appreciated.
--------------------------------------------------------------------
select ProperCaseString(namefirst) from members where id = 428
If I do select without the ProperCaseString() Ok so problem is UDF call.
--------------------------------------------------------------------
External Function which when tested by direct call to function in dll,
returns a proper case string.
DECLARE EXTERNAL FUNCTION PROPERCASESTRING
VARCHAR(80) CHARACTER SET NONE
RETURNS VARCHAR(80) CHARACTER SET NONE
ENTRY_POINT 'fn_ProperCaseString' MODULE_NAME 'strudf';
----------------------------------------------------------------------
and dll code .cpp
String __stdcall fn_ProperCaseString(String CheckString)
{
//Declare and initialze variables
int Pos;
String FirstLetter, WorkWord, ProperCase, WorkString = CheckString;
//If supplied string length = 0, return
//Locate the first word in the string
Pos = WorkString.Pos(" ");
if (Pos == 0)
return WorkString;
while (Pos > 0)
{
//Extract the first word in string and trim blanks
WorkWord = Trim(WorkString.SubString(1, Pos));
//Extract the first letter of the word and delete it from the work word
FirstLetter = WorkWord.SubString(1,1);
WorkWord.Delete(1,1);
//Append Upper case firt letter and lower case word remainder to the
return string
ProperCase = ProperCase + FirstLetter.UpperCase() +
WorkWord.LowerCase() + " ";
//Delete the processed word from the work string
WorkString.Delete(1,Pos);
//Trim any excess blanks from the work string
Trim(WorkString);
//Locate the next word (now again the first) in the supplied string
Pos = WorkString.Pos(" ");
//Check if last word in string and set Pos is so to pick up last word
if ((Pos == 0) && (WorkString.Length() >0))
Pos = WorkString.Length();
}
return ProperCase;
}
//---------------------------------------------------------------------------
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
return 1;
}
-------------------------------------------------------------------------------
dll .h file
#include <stdio.h>
extern "C" __declspec(dllexport) String __stdcall
fn_ProperCaseString(String CheckString);
Previously posted in Borland Interbase General group. No responses.
I have tested the dll with a test probelam and it works fine.
IBConsole - This returns an empty dataset and pops up an error that
connection to database lost.
I have written other udfs and never had a connection lost error before.
Any thoughts appreciated.
--------------------------------------------------------------------
select ProperCaseString(namefirst) from members where id = 428
If I do select without the ProperCaseString() Ok so problem is UDF call.
--------------------------------------------------------------------
External Function which when tested by direct call to function in dll,
returns a proper case string.
DECLARE EXTERNAL FUNCTION PROPERCASESTRING
VARCHAR(80) CHARACTER SET NONE
RETURNS VARCHAR(80) CHARACTER SET NONE
ENTRY_POINT 'fn_ProperCaseString' MODULE_NAME 'strudf';
----------------------------------------------------------------------
and dll code .cpp
String __stdcall fn_ProperCaseString(String CheckString)
{
//Declare and initialze variables
int Pos;
String FirstLetter, WorkWord, ProperCase, WorkString = CheckString;
//If supplied string length = 0, return
//Locate the first word in the string
Pos = WorkString.Pos(" ");
if (Pos == 0)
return WorkString;
while (Pos > 0)
{
//Extract the first word in string and trim blanks
WorkWord = Trim(WorkString.SubString(1, Pos));
//Extract the first letter of the word and delete it from the work word
FirstLetter = WorkWord.SubString(1,1);
WorkWord.Delete(1,1);
//Append Upper case firt letter and lower case word remainder to the
return string
ProperCase = ProperCase + FirstLetter.UpperCase() +
WorkWord.LowerCase() + " ";
//Delete the processed word from the work string
WorkString.Delete(1,Pos);
//Trim any excess blanks from the work string
Trim(WorkString);
//Locate the next word (now again the first) in the supplied string
Pos = WorkString.Pos(" ");
//Check if last word in string and set Pos is so to pick up last word
if ((Pos == 0) && (WorkString.Length() >0))
Pos = WorkString.Length();
}
return ProperCase;
}
//---------------------------------------------------------------------------
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*
lpReserved)
{
return 1;
}
-------------------------------------------------------------------------------
dll .h file
#include <stdio.h>
extern "C" __declspec(dllexport) String __stdcall
fn_ProperCaseString(String CheckString);