Thread: Making a Simple Database System

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    648

    Making a Simple Database System

    What I want to do is make a simple database. For my program, I need to register every package into some database. The fields I need with every package are shown in these structs:

    Code:
    struct Dependency
    {
    	char *name;        // or if you want, char name[64];
    	int minVersion;    // bottom range
    	int maxVersion;   // higher range
    };
    struct Package
    {
    	char *name;       // or if you want, char name[64];
    	int version;
    	
    	int importsNum;
    	Dependency *imports;  // array
    };
    This is going to be a local database, probably in some file. I need to search and add items to the database real quickly. A sample query would be:

    Name=”ImagePlugin”
    Version Range=2 to 7

    Then it would search the database and return the most recent version of the struct Package between versions 2 and 7 and with the name ImagePlugin. I could do a real database but I need this to be __cross-platform__ and be able to create, manipulate and search the data from C++ code, well, with no intervention from a person

    My question is: How can I do this in the most efficient, fastest way? If I use files, how do I position the dependencies? In a separate file(s)? If I’m using a real database, which library would I choose?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I would start with getting something that works while keeping cross-platform independance in mind. If you use a binary format, you have to be aware of CPU endian'ness. If you can fit your int's into char's, that would solve that problem. Otherwise you should establish what byte-order your ints will have in the file and use it. You can detect what byte order is used on the machine your running on with code like this:
    Code:
    int a = 0x3;
    char *p = reinterpret_cast<char*>(&a);
        
    if (*p == 3)
       cout << "little-endian" << endl;
    else
       cout << "big-endian" << endl;
    If the byte order of the machin you're running on doesn't match the byte order used in the file, you'll have to reverse the bytes in any integer types you read in. Of course, all this can be avoided by using a text file for the database.

    Get your database working as well as linear searches within the database. If it isn't fast enough, you can implement a persistent hash table for the records in the database. (too much to get into here). Or something more simple like a sorted records table for performing binary searches instead of linear searches.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Database in C++?
    By richard23 in forum C++ Programming
    Replies: 2
    Last Post: 02-20-2008, 08:48 AM
  2. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  3. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  4. Creating a simple database: is my approach OK?
    By m712 in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2002, 02:27 AM
  5. simple database app. in borland c++ builder tutorial
    By kariem2k in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2002, 07:28 AM