Palamedes
asked on
Use a database or not use a database?
Howdy all,
I have been writing a program for quite some time now and have come to a dilemma. I have way more information than I could ever hard code into the program. I have a lot of information that needs to be stored in some manner. I’m just not sure how to store it in such a way that it will be easy for me to pass that information on to the end users of my application, AND easy for me to access and change.
Here’s the deal, there will be about 12 main pieces. Each with about 100 sub pieces of information, each sub piece has about 100 fields of information associated to each one. Each one of those pieces can be a integer or a string or.. well you get the idea..
Now its not random.. I know exactly what information I have to store, its just a matter of figuring out how to store it. This has been the killer of my app up to date.
Can anyone give me a clue as to how to do this? What would be the best method? My main concern here is keeping the program itself small, and keeping the number of associated files down to a minimum. I don’t want to have to pass out any cumbersome database.
Any examples and ideas are always appreciated.. Thanks
-Pal (Delphi 5)
PS. I am completely database illiterate so keep it simple please.. thanks.
I have been writing a program for quite some time now and have come to a dilemma. I have way more information than I could ever hard code into the program. I have a lot of information that needs to be stored in some manner. I’m just not sure how to store it in such a way that it will be easy for me to pass that information on to the end users of my application, AND easy for me to access and change.
Here’s the deal, there will be about 12 main pieces. Each with about 100 sub pieces of information, each sub piece has about 100 fields of information associated to each one. Each one of those pieces can be a integer or a string or.. well you get the idea..
Now its not random.. I know exactly what information I have to store, its just a matter of figuring out how to store it. This has been the killer of my app up to date.
Can anyone give me a clue as to how to do this? What would be the best method? My main concern here is keeping the program itself small, and keeping the number of associated files down to a minimum. I don’t want to have to pass out any cumbersome database.
Any examples and ideas are always appreciated.. Thanks
-Pal (Delphi 5)
PS. I am completely database illiterate so keep it simple please.. thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may use a db or not.
If you use a db, the fields should be:
owner, id, data(s)
here, you build a tree in db. Owner field shows the master's id. id is the current record's unique number. (you can create it by incrementing some value). Data can be string or other types. This is a little hard to establish, but you can add lot's of different datas allocated in different items.
Another way is using directories and normal files for each data. You create 12 directories, and some files, some new directories containing other files or directories on the disk... The extention of the file can represent the data type. This will minimize the code.
The most complicated, but the fastest and the one I like most is using TCollection object.
You create a collection item class that holds one data (a variant) and some other children. Write loader and storer methods. TCollection will store the tree on a stream, the stream stores it on a file. Thats all.
Also you should write an editor for it :)
If you use a db, the fields should be:
owner, id, data(s)
here, you build a tree in db. Owner field shows the master's id. id is the current record's unique number. (you can create it by incrementing some value). Data can be string or other types. This is a little hard to establish, but you can add lot's of different datas allocated in different items.
Another way is using directories and normal files for each data. You create 12 directories, and some files, some new directories containing other files or directories on the disk... The extention of the file can represent the data type. This will minimize the code.
The most complicated, but the fastest and the one I like most is using TCollection object.
You create a collection item class that holds one data (a variant) and some other children. Write loader and storer methods. TCollection will store the tree on a stream, the stream stores it on a file. Thats all.
Also you should write an editor for it :)
Hi Again Palamedes,
I think denizcan wrote good ideas .. but it seems to be defficult for the begginners ..
using TCollection is a good Idea but it needs an advanced steps.
I think denizcan wrote good ideas .. but it seems to be defficult for the begginners ..
using TCollection is a good Idea but it needs an advanced steps.
Hi Palamedes,
You can use INI file like this:
[Main Item 1]
Piece1=value
Piece2=value
.....
[Main Item 2]
Piece1=value
and so on.
In program:
var
IniFile : TIniFile;
IniName : String;
sPiece : String;
begin
IniName := 'c:\myini.ini';
IniFile := TIniFile.Create(IniName);
.....
sPiece := TIniFile.ReadString('Main Item 2', 'Piece1', '');
.....
IniFile.Free;
end;
I think it's functional as TIniFile object has many useful methods.
File to use - 1 (one);
Easy to manipulate manualy - text file;
Easy to read and write via program;
Regards, Geo
You can use INI file like this:
[Main Item 1]
Piece1=value
Piece2=value
.....
[Main Item 2]
Piece1=value
and so on.
In program:
var
IniFile : TIniFile;
IniName : String;
sPiece : String;
begin
IniName := 'c:\myini.ini';
IniFile := TIniFile.Create(IniName);
.....
sPiece := TIniFile.ReadString('Main Item 2', 'Piece1', '');
.....
IniFile.Free;
end;
I think it's functional as TIniFile object has many useful methods.
File to use - 1 (one);
Easy to manipulate manualy - text file;
Easy to read and write via program;
Regards, Geo
ASKER
I have been getting errors when trying to reject answers.. Internal server error.. *sigh* Lets try this one more time..
ASKER
Yeah!! It finally worked..
Okay
Geobul, I have tried the INI file route.. The INI file ended up being massive and unwieldy.. However, it may be the best way to do it.. not sure..
HamidHossan, I understand the concept, its just a matter of actually doing that in Delphi..
Denzican, I actually have a working model of the directory system on one of my servers. A webpage that has a very large database uses grep and perl to sort through it in that manner. Again, I understand the concept, its just a matter of making this work in Delhpi. (And personally the directory system wont work for me here.. thanks)
-Pal
Okay
Geobul, I have tried the INI file route.. The INI file ended up being massive and unwieldy.. However, it may be the best way to do it.. not sure..
HamidHossan, I understand the concept, its just a matter of actually doing that in Delphi..
Denzican, I actually have a working model of the directory system on one of my servers. A webpage that has a very large database uses grep and perl to sort through it in that manner. Again, I understand the concept, its just a matter of making this work in Delhpi. (And personally the directory system wont work for me here.. thanks)
-Pal
ASKER
I like the XML file idea the best I think.. Could you give an example?
Take a look at http://www.pbe.com/SourceWorks/XMLWorks/ where there is an example of Delphi code for reading and writing XML files along with other resources about XML. Most of the implemntations these days don't actually directly read or write to the XML file, but use the parser that comes free in a dll with MSIE 5 (one came with 4 also, but it is almost crippled).
There is also an excellent component published in Delphi Magazine, www.itecuk.com, but I'm not sure if the source is available to non-subscribers.
I like XML also, but using it will be challange. I think it will be more than worth it, though.
There is also an excellent component published in Delphi Magazine, www.itecuk.com, but I'm not sure if the source is available to non-subscribers.
I like XML also, but using it will be challange. I think it will be more than worth it, though.
I Think you MUST use a database .. I am not sure about your data .. but I think you will need 1 Tabel to finish your work..
you must have three fields like:
Main, Sub, Data
mark Main and sub as Index using (*) on paradox tabel.
save all your data like:
Main1, Sub1, Data1
Main1, Sub1, Data2
....
Main1, Sub1, Data100
then ..
Main1, Sub2, Data1
Main1, Sub2, Data2
....
Main1, Sub2, Data100
and so on until you finish to:
Main12, Sub100, Data100
save all your data as STRING and use StrToInt() and IntToStr to save and read data.
use Tabel1.FindKey() to search through your tabel with Main(x) and Sub(x).
I AM WAITING YOUR REPLY
BEST REGARDS
HAMIDHOSSAIN