Database Management Library

Origem: Wikipédia, a enciclopédia livre.
DBL - Database Management Library
Desenvolvedor ROCHA, Rodrigo C. O.
Versão estável 1.0 (2 de julho de 2010; há 13 anos)
Licença GNU General Public License
Página oficial http://sites.google.com/site/rcorcs/download/library http://sourceforge.net/projects/dblibrary/

DBL - Database Management Library é uma biblioteca em linguagem C++ que implementa um Gestor de Banco de dados relacional. A biblioteca DBL source code está sob termos da GNU General Public License.


Design[editar | editar código-fonte]

DBL é uma biblioteca que se torna parte integral do software aplicativo. Diferentemente de um SGBDR client–server que é um processo independente com o qual o aplicativo se comunica. O software aplicativo faz uso das funcionalidades da biblioteca DBL através de subrotina, que reduz a latência de acessos ao banco de dados pois chamadas à funções dentro de um mesmo processo são muito mais eficientes que em uma comunicação entre processos.

Programas de Exemplo[editar | editar código-fonte]

Criando um banco de dados simples[editar | editar código-fonte]

Este e um programa básico que cria um banco de dados simples. Entretanto, por ser uma tarefa que geralmente é realizada apenas uma vez, pode ser feita pelo 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;
}

Inserindo um registro em uma tabela[editar | editar código-fonte]

Este é um programa basico que insere um novo registro na tabela.

#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;
}

DBL Command-Line Interface[editar | editar código-fonte]

Pelo programa DBL Command-Line Interface pode-se criar banco de dados, criar tabelas e adicionar colunas à uma tabela, além de outras operações tais como mostrar na tela a estrutura dos banco de dados e tabelas.