Database Management Library

Database Management Library
DBL - Database Management Library
Developer(s) ROCHA, Rodrigo C. O.
Initial release July 2010 (2010-07)
Stable release 1.0 / July 2, 2010; 15 months ago (2010-07-02)
Written in C++
Type RDBMS (embedded)
License GNU General Public License
Website http://sites.google.com/site/rcorcs/download/library https://sourceforge.net/projects/dblibrary/

DBL - Database Management Library is a RDBMS contained in a C++ programming library. The DBL source code is available under the terms of the GNU General Public License.

DBL was developed as a holidays programming project, and it was completely developed within two weeks.

It aims at being easy and simple for C++ programmers to use.

Contents

Design

DBL is a library and becomes an integral part of the application program. Unlike client–server database management systems that are standalone process with which the application program communicates. The application software uses DBL's functionality through function calls.

Sample Programs

Creating a simple database

This is a basic program that creates a simple database. However, as this task must be done usually once, it can be done by the DBL Command-Line Interface.

#include "dbl.h"
 
int main()
{
    path( "D:\\" ); //set the path to the folder where the files will be stored
 
    database db("mydatabase");  //mydatabase is the name of the database
    db.new_tab("customer");  //create a new table called customer in the database
 
    write(db);  //write the database structure into a file
 
    char pkey = 1;
    table *tab = db.get_tab("customer"); //get the table customer from the database
    tab->add_col("cod", INTEGER, 1, pkey);  //add a column called cod to the table customer
    tab->add_col("name", CHARACTER, 32);  //add a column called name to the table customer
    tab->add_col("brithdate", INTEGER, 3);
    tab->add_col("sex", CHARACTER, 1);
    tab->add_col("phone", INTEGER, 1);
    tab->set_structure();
    write(*tab);  //write the table structure into files
    create_data_file(*tab); //create the data file of the table customer
 
    return 0;
}

Inserting data into a table

This is a basic program that inserts a new record in the table.

#include "dbl.h"
 
int main()
{
    path( "D:\\" ); //set the path to the folder where the files will be stored
 
    database db("mydatabase");  //mydatabase is the name of the database
    read(db); //load the database structure
 
    table *tab = db.get_tab("customer"); //get the table customer from the database
    row r( tab->new_row() ); //get a row with the structure of the table customer
 
    int cod = 31415;
    char name[32] = "Charles";
    int birthdate[3] = {27, 6, 2010};
    char sex = 'm';
    int phone = 88123456;
 
    //set the values stored by the row
    r.set(0, &cod);
    r.set(1, name);
    r.set(2, birthdate);
    r.set(3, &sex);
    r.set(4, &phone);
 
    int i = num_row(*tab); //get the number of rows in the data file
 
    //write the row into the data file of the table customer,
    //where i is the index of the new record
    write(*tab, r, i );
 
    return 0;
}

The Library Structure

The Class database

This class stores the database name and its tables. The main functions are:

   char *name(); //get the database name
   char *name(char *dbname); //set the database name
   void new_tab(char *tabname); //create a new table
   table *get_tab(char *tabname); //return the pointer to the table

Useful functions that use the class database are:

   void write(database &db); //write the database structure into a file
   friend void read(database &db); //read the database structure from a file
   friend void del(database &db); //delete the database and its tables files
   friend void print(database &db); //print the database on the screen

The Class table

This class stores the table name and its structure, the columns of the table. The main functions are:

   char *name(); //get the table name
   char *name(char *dbname); //set the table name
   void add_col(column &c); //add a new column to the table
   void add_col(char *col_name, char col_type, int col_len=1, char pkey=0);
   column *get_col(int idx); //get the column by its index
   column *get_col(char *name); //get the column by its name
   int num_col(); //get the number of columns in the table
 
   //finish the structure of the table.
   //This function must be called after adding all columns or after reading the structure of the table from a file
   void set_structure();
 
   row new_row(); //get a new row with the table structure

Useful functions that use the class table are:

   void write(table &t); //write the table structure into a file
   void read(table &t); //read the table structure from a file
   friend void del(table &t); //delete the table files, header and data files
   void print(table &t); //print the table on the screen
   friend std::ostream &operator<<(std::ostream &o, table &t); //print the table structure
   int num_row(table &t); //get the number of rows in the data file of the table

The Class row

This class stores the columns of the table and the data to be stored in the data file. The main functions are:

   void set(int idx, storage &s); //set the storage of a column by its index
   void set(int idx, void* v); //set the value to be stored in a column by its index
   storage *get(int idx); //get the storage from the a column by its index

Useful functions that use the class row are:

   void write(table &t, row &r, int idx); //write the data in the data file of the table
   void read(table &t, row &r, int idx); //read the data from the data file of the table
   void del(char *file, table &t, int idx); //delete the data from the data file of the table

The Class storage

This class stores the column and a value for that column. The main functions are:

   char *value(); //get the value being stored by the object
   void value(void *val); //set the value to be stored
   void value(char *val); //set the value to be stored, a C-style string and all functions of the class column.

Useful functions that use the class storage are:

   int get_int(storage &s); //get the integer being stored
   char get_char(storage &s); //get the char being stored
   bool get_bool(storage &s); //get the bool being stored
   float get_float(storage &s); //get the float being stored
   double get_double(storage &s); //get the double being stored

The Class column

This class stores the name and the structure of a column. The main functions are:

   char *name(); //get the name of the column
   char *name(char *n); //set the name of the column
   char type(); //get the type of the column
   char type(char t); //set the type of the column
   int length(); //get the length of the array that the column can hold
   int length(int len); //set the length of the array that the column can hold, len>0
   void pkey(char b); //set if the column is the primary key or not (0 is false, 1 is true)
   char pkey(); //get if the column is the primary key or not
   int total_size(); //get the total size, in bytes, that the column can hold

The Class index

This class stores the indexes of a table. The main functions are:

   int seek(void *val); //look for a value in the indexes
   int seek(char *val); //look for a C-style string in the indexes

Useful functions that use the class index are:

   void write(table &t, index &idx); //write the indexes of a table into a file
   void read(index &idx); //read the indexes from a file

DBL Command-Line Interface

By the DBL Command-Line Interface program one can create a database, create a table and add columns to this table, besides others operations such as printing.

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Database management system — Ein Datenbanksystem (DBS) ist ein System zur elektronischen Datenverwaltung. Die wesentliche Aufgabe eines DBS ist es, große Datenmengen effizient, widerspruchsfrei und dauerhaft zu speichern und benötigte Teilmengen in unterschiedlichen,… …   Deutsch Wikipedia

  • Comparison of relational database management systems — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • List of relational database management systems — See DBMS for a shorter list of “typical”, representative database management systems.Current software*4th Dimension *Adabas D *Alpha Five *Apache Derby *CA Datacom *CSQL *Daffodil database *Dataphor *DB2 *Derby aka Java DB *EnterpriseDB… …   Wikipedia

  • Gemstone Database Management System — Infobox programming language name = GemStone Database Management System paradigm = Application framework year = 1991 typing = designer = implementations = dialects = influenced by = Smalltalk,Object oriented programming influenced = J2EEGemStone… …   Wikipedia

  • Library science — is an interdisciplinary science incorporating the humanities, law and applied science to study topics related to libraries, the collection, organization, and dissemination of information resources, and the political economy of information.… …   Wikipedia

  • Database transaction — A transaction comprises a unit of work performed within a database management system (or similar system) against a database, and treated in a coherent and reliable way independent of other transactions. Transactions in a database environment have …   Wikipedia

  • Database schema — A depiction of MediaWiki database schema. A database schema (pronounced skee ma, /ˈski.mə/) of a database system is its structure described in a formal language supported by the database management system (DBMS) and refers to the organization of… …   Wikipedia

  • library — /luy brer ee, breuh ree, bree/, n., pl. libraries. 1. a place set apart to contain books, periodicals, and other material for reading, viewing, listening, study, or reference, as a room, set of rooms, or building where books may be read or… …   Universalium

  • Library — Reading room redirects here. For other uses, see Reading room (disambiguation). For other uses, see Library (disambiguation). Reading room of the library at the University of Graz, in Austria …   Wikipedia

  • Database Console Commands (Transact-SQL) — The Database Console Commands (DBCC) are a series of statements in Transact SQL programming language to check the physical and logical consistency of a Microsoft SQL Server database.[1] These commands are also used to fix existing issues.[1] They …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”