Custom Database

This is a discussion on Custom Database within the C++ Programming forums, part of the General Programming Boards category; First of all, Hi all, new to the forums Anyway, regarding this thread. I'm currently making a college project based ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    21

    Custom Database

    First of all, Hi all, new to the forums

    Anyway, regarding this thread. I'm currently making a college project based on C++ and in need to design my own database system, if it be stored by file or a client-server application. The only problem is, I've no idea on where to get started regarding the client-server model side of things, if I was to venture down this path.

    However, if I was to use a file-based database system, like, custom.dbase (filename). I would need to write my own methods of storing the data etc, and again im not sure where I should start regarding this. Obviously, being a database, It would need to be secure so the data would need to be encrypted, that part i do believe I could handle with a simple algorithim, however its the actual storage and retreival of the data in the file thats baffling me, as, as far as I know, I would need to reach each line all the way down the text file until i reach the data required/searched for.

    If any of you know of any tutorials regarding this then please let me know, or if you could give me a head start and point me to the information that I would require to get started that would be great to.

    Oh, and for those of you wondering, no, I can't use ADO/SQL etc, it has to my own database structure.

    Thanks.
    AvidGamer

  2. #2
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    You can use the fstream header file to deal with file I/O
    Heres an example (No Encryption):
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main ()
    {
          int number = 10;
          int readnumber;
          ofstream out;
          ifstream in;
    
          out.open ("dbase.db");
          out<< number;
          out.close();
          
         in.open ("dbase.db");
         in>> readnumber;
         in.close();
    
        cout<< readnumber;
        return 0;
    }
    You can read the Cprogramming.com tutorial on File I/O For A More Detailed explanation
    The Link: http://www.cprogramming.com/tutorial/lesson10.html

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    21
    Thanks for the response.

    The file io side of things isnt a problem, its how I would actually store the data. For example if I created a file and stored values such as (before encryption):

    [header1]
    Names=blah,chris.blah,tom
    IP=address'
    comments=sadasd
    lastseen=<date> <time>

    Would there be a quicker way of searching instead of reading the file line by line?

    And also, I would need to parse the data by delimiters, im assuming that strtok would suffice? This database may become extremely large in size, e.g header1 x 150,000 depending on the items entered (got plans to use this in another app if this works), wouldnt searching a file through 150,000x5 lines be extrememly inefficient?

    Thanks Again.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    21
    Also im a little confused on how I would go about editing a record inside the database. I figured I could search to find and read the appropriate record, however, how would I edit the items for each database member?

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Even 150,000 records might not that much to simply load into memory (depending on the size of each individual record) via an STL container of some sort. Searching sequentially record-by-record would be an issue so choosing the appropriate container would help. You would want the searching you perform to be based on a key by which the data is ordered in your container. STL containers such as a map or set automatically order their contents for you based on criteria you define. Internally, they store their contents in a balanced tree type of structure which makes searching very efficient. Modifying the data is just a matter of finding the record within the container and making the changes. Saving this information to the database is done easiest by reading in the complete database into the STL container at program startup, then overwriting the existing file with the whatever contents are in the container after any modifications have been made at the close of the program. During program execution, any changes/addition/deletions are made on the data in memory (stored within the container) and not directly on the data within the file itself.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    21
    Thanks for the information hk_mp5kpdw. I haven't looked into STL containers yet, that was on my list of things to do, guess ill have to bump that up a bit.

    If you could, could you give me a list of beginner based tutorials on the subject? I already know of the one hosted here at cprogramming.com, and will read through it shortly. If anyone else could provide links to any tutorials then it would be appreciated.

    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. literature database: help with planning
    By officedog in forum C++ Programming
    Replies: 1
    Last Post: 01-23-2009, 11:34 AM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  5. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 09:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21