Solved

ATL collection using database

Posted on 2001-07-12
9
176 Views
Last Modified: 2006-11-17
Hi,
I have implemented a collection in ATL.
"People" is the collection "Man" is an item of the collection.

In the database i have a table People and so, each record in the table is a Man.
I use ADO to access my database.

And my ATL collection have to support multithread.

On each item of the collection, you can Set and Get properties.

The problem i have is on how i get the data of my items. I can't store the data directly in the "Man" object because if another client have changeed the name for instance, the state of my object will be incorrect for other clients.

So, i have to get the data in the database each time the client access a property of an item. And it disturbs me a lot because it implies each item to have a recordset, to go and get the data in the database.

So 70000 items --> 70000 recordsets, i think it is not acceptable.

So my question is, what is the current and efficient way to implement a collection that manages table of a database?

Thanks!




0
Comment
Question by:FMayis
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:missionImpossible
ID: 6277348
I don't know if I really got it, but you don't need to have one recordset per item. You can use one recordset per client. The recordset in your case should be a "Dynamic"-recordset type. This is a representation of a dynamic cursor, which shows every changes of other users on the fly. See also MSDN.

0
 
LVL 6

Expert Comment

by:snoegler
ID: 6280083
>> So my question is, what is the current and efficient way to implement a collection that manages table
of a database?

A database :)
Databases are specifically designed for handling this. By putting a 'container' around a database table, all benefits of a database are lost (as long as you want a generic container) (or you are going to re-implement SQL which is specifically designed for doing all time critical tasks within the highly optimized database engine).
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6280828
I agree wish snoeglar let the database be the main store of your collection - if you need to hand it out do a select * and generate your collection on that and pass it on - or you can pass out single items, subsets or the whole thing - if an item needs to check its state (dirtyness) then you can either check with a flag (eg timestamp of last update) or just get the whole thing.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 6280844
>> as long as you want a generic container
i meant:
>> as long as you want a simple container
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:FMayis
ID: 6284868
Hi,
I do agree, the database is the main store of the collection.

For the moment i did a select * and then use the generated recordset to implement my collection.

and doing a SELECT * implies loading in memeory lot of things not needed. If a user works with an item and i have some thousand in the database, then lot of memories are lost for nothing.

So,what is the best compromise(performance time, memory size) between loading all, or making a request on each access to data of an item property.

0
 
LVL 2

Accepted Solution

by:
missionImpossible earned 200 total points
ID: 6284908
1. if you need all data of a row (select *), to get it once is quite more performant, as to access the data in multiple access.
But sometimes it could be clever to fetch data lazy: F.ex if your user needs only in 5% of all use cases all the data, you can fetch this data only if he really needs it. in 95% of the cases you can get only the  data he needs and your app will be more performant. It depends on what the user needs.

2. if the user don't needs to access all rows (at the same time), filter your select, to get only one or few rows of data.
0
 

Author Comment

by:FMayis
ID: 6285255
The collection will be used like follows

for i = 1 to Count
    item=col.GetItem(i)
    item.GetName //or anyother property
next

or

item = col.GetItem("Name")
//and then get all properties of the item


I think that getting data when needs will be more performant.

0
 
LVL 6

Expert Comment

by:snoegler
ID: 6285262
What about a collection like this:

MyColl.Init "SELECT * from customer";
For Each Elem in MyColl
  Print Elem("Name"), Elem("Street"), Elem("Zip")
Next

This reminds me of something :)
0
 

Author Comment

by:FMayis
ID: 6368723
Sorry for elapsed time!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now