HOME

TheInfoList



OR:

Database Management Library (DBL) is a
relational database management system A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relati ...
(RDBMS) contained in a C++ programming
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
. The DBL
source code In computing, source code, or simply code, is any collection of code, with or without comment (computer programming), comments, written using a human-readable programming language, usually as plain text. The source code of a Computer program, p ...
is available under the terms of the
GNU General Public License The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end user In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ulti ...
. DBL was fully developed within two weeks, as a holiday programming project. It aims to be easy and simple to use for C++ programming.


Design

DBL is a library and becomes an integral part of the application program. Unlike
client–server model The client–server model is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients. Often clients and servers communicate ov ...
database management systems that are standalone
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process, activities that produce a specific se ...
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()


Library structure


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


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


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


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


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


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, a table, and add columns to this table, besides other operations such as printing.


External links

* {{DEFAULTSORT:Database Management Library 2010 software C++ libraries Free database management systems Relational database management systems