
Learn Remote Data Objects
Quote:
> Since you have trialed and errored your way through RDO (I have begun
>but not yet reached Master Status.. ;)), could you help me with a problem??
>I have a functioning RDO application running on an NT server but would
>like to make the routines more re-usable. I am therefore created a library
>of routines that I am putting in a class for re-use. I had discovered to
>evils of automatic prepared statements and the need to get rid of them
>once they were no longer needed. Now that I am putting this code in
>a class I come to need to determine exactly WHICH PreparedStatment
>was used to generated a passed ResultSet. I have searched and
>searched. I thought it would be the hStmt parameter but that does not
>seem to match when I pass a simple test to the class, ie: one ResultSet
>created by one PreparedStatement on a connection.
>Any clues as to how to determine the PreparedStatement to close when
>attempting to close a specific ResultSet? Hopefully it will not be too
>obvious and therefore openly displaying my inability to find things in the
>docs...
>Thanks to anyone who can help.
>D.M.(Mike) Mattix
>Monsanto Company
>Luling, LA 70070
Mike,
I am a long way frm master status - I've just been through some of the
mill! :-)
There are a number of ways of doing this and I am working from memory
rather than having refreshed my mind from the code:
a. Loop through the rdopreparedstatements collection using the name
attribute: so-
for each ps in {rdoConnection name}.rdopreparedstatements
if ps.name = "Select * from Orders" then
ps.close
end if
next ps
b. Number all rdopreparedstatements as they are created: so
dim iPsOrders as integer
set iPsOrders to -1 at start and end of scope
if iPsOrders = -1 then
Set PsOrders = {rdoConnection name}.CreatePreparedStatement
("", "Select * from Orders))
iPsOrders = {rdoConnection name}.rdopreparedstatements.Count
-1
endif
you can then close by testing iPsOrders and then closing (and setting
the flag back to -1 or everything will get out of sync) if a positive
value. This has the added advantage of not recreating the
rdoPreparedstatement every time the code runs past it as it will only
fire if iPsOrders is set. If you have too many ps going at once you
will fill SQL Server tempdb (Are you using SQLServer?) or your project
database and slow things up. Use sp_who to see what is active at any
time. You will get quite a shock when you see storedprocedures (which
is what rdoprepared statements create - temporary ones that is ) still
opened which you should have closed.
We use 'b' above with all rdoresultsets loaded from preparedstatements
so that the resultsets are not reloaded (and the count incremented)
every time the code is passed. You need to close both the prepared
statement and the resultsets which are loaded from them when they go
out of scope. They will stay on the server / workstation otherwise.
You can use 'a' for this as well if you wish but it is very texty
(but see below about resource files). It is however the safest way.
In you case I would set a number for each prepared statement and
resultset. We close all ps and rs when we have finished with them and
move on to another part of the program ie when we get back to a blank
mdiForm. Your idea sounds interesting but do check every now again by
looping through the collections and printing out the names or
msgboxing them to ensure that the close algorithm is working properly.
BTW we use a Visual C++ resource file for all our prepared statement
string and then call:
Set PsOrders = {rdoConnection name}.CreatePreparedStatement ("",
LoadResString(51))
This is much more memory efficient and avoids the same string
appearing all over the place as team members create new ones. It acts
as a good catalog. If you are using the names technique you can then
test in the close loop at 'a' above using:
if ps.name = LoadResString(51) then
Hell - I've gone on a bit but hope it helps - I apologise if there are
any errors in the above syntax - the project is on NT and this is
being written in '95 and I'd have to reboot. Let me know if I can help
further - I am leading a team writing a Police Internal Affairs system
for up to 43 UK Police Forces and its all on RD0 and working! Devil
take the Unbelievers! :-)
Doug
--
Doug Gibbard,
Lincoln England