Subject Re: UDF Unloaded
Author philcaetano
I understand how UDF's work. I know its on the server side etc.

Maybe I should have been more clear. What I want to know is how long
does the UDF stay "ALIVE" on the server.

What I'm doing is the following:

I have and database that contains a large amount of small data.

Large meaning that I need to insert over 10000 to 100000 in 1
transaction. Do this takes too long to run with insert SQLs.

What I did (And it does work) is I create a 3 UDFs.
one is InsertData(ID: Integer; DATA: BLOB); The blob contains the
entire data of thousands of records in binary format. When I call
insert it will insert all this data into a Inmemory variable that
contains all the information (TList of ^Records)

I then have another UDF that will get the count data GetBlockCount(ID)
: Cardinal and another one that says GetData(ID : Integer; var

I then use those two commands in a stored procedure to do all the
inserts of the data at the serverside. The stored procedure is
started from the client (threaded). Which allows the client to do
other tasks while this data is being created.

The speed result is many many times faster than if I did the inserts
from the client.

This is why I want to know if the udf can get unloaded before I call
the other two commands. Since the time from insert and when the
stored procedure is called is almost instance I'm pretty sure this is ok.

There might be another approach by using a server app and doing that,
but it just seems to work nicely using the udf.

Hope this is clear.

--- In, Helen Borrie <helebor@...> wrote:
> At 10:08 AM 14/12/2006, you wrote:
> >Hi,
> >
> >I wanted to know when are UDF's unloaded? I'm doing something "risky"
> >where I have a internal variable counter in the udf and I noticed the
> >UDF is unloaded when the user disconnects,
> UDFs live in libraries. A library is loaded *by the server* the
> first time a client calls a function in that library. It is not
> loaded by the client and it is not unloaded "when the user
> disconnects" - unless, of course, the "user" is the embedded server
> A UDF is a *function*. It takes inputs from the caller and returns a
> scalar result. A UDF must not be used as though it were a process or
> procedure. If you are using a UDF to maintain some value that's
> intended to be altered there by successive function calls then you
> are asking for trouble, i.e. corrupted memory, leakage, server
crash, etc.
> >but I wanted to know what
> >if I had a UDF function that is doing something that isn't completed
> >yet when the user disconnects?
> A UDF wouldn't be "doing something that isn't completed yet". A lost
> client connection is an issue (separate) for the server but not for a
> UDF. The UDF itself has no awareness of the client. The client has
> made a request to the server that causes the server to invoke the
> external function. The server waits for the result, sends the result
> to an output buffer and frees any memory it had allocated for the
> function call.
> ./heLen