Executing Commands with CachedRowSet
Hi,
Could anyone tell me if it is possible to execute a SQL querry against a cached row set? For example, the cached rowset has been populated with data about Customers with fields Name, Order, PartNo. I wish to retrieve the Name and Order fields for a specific PartNo. Any idea how I would do this?
Thanks
# 1
> Could anyone tell me if it is possible to execute a
> SQL querry against a cached row set?
SQL runs in the database. A cached row set exists on the client computer.
Even if they were on the same computer they would be in different process spaces. So know there is no way to make the magically interact.
> For example, the
> cached rowset has been populated with data about
> Customers with fields Name, Order, PartNo. I wish to
> retrieve the Name and Order fields for a specific
> PartNo. Any idea how I would do this?
1. Extact the part number.
2. Create an appropriate query.
3. Then run a query.
I am guessing you already understand how to do the above.
# 2
I wanted to avoid connected to the DB again to get the information. What I'm doing now is to iterate through the cachedrowset and find the information. Its not very efficient but it'll do the job.
I was thinking of exectuing cachedrowset.toCollection() but I'm not sure how I can work with a collection in order to find the data.
Any ideas?
# 3
> I wanted to avoid connected to the DB again to get
> the information.
Then load it all at the same time.
> What I'm doing now is to iterate
> through the cachedrowset and find the information.
> Its not very efficient but it'll do the job.
>
And why do you think that that isn't efficient?
If you are doing this solely to get something that you already know about then you should be using a single query with a join to return the correct information.
# 4
What I am doing right now is loading all the data at the same time. So I don't need to connect to the DB to fetch the information again.The reason why it is inefficient is that the search has to be performed about 100 or so times all sequentially.
# 5
> What I am doing right now is loading all the data at
> the same time. So I don't need to connect to the DB
> to fetch the information again.
I see.
>
> The reason why it is inefficient is that the search
> has to be performed about 100 or so times all
> sequentially.
Why sequentially?
Use an additional hash. The first time you go through the row set you populate the hash with the key being the part number and whatever other info you want associated with it being the data/value - probably as an array or even another hash.
Then when you want info on a part num you use the hash rather than the row set.
Note that excluding other information 100 times is very small in most terms.