CPDB.Net  [fr]  [en] 
News  Downloads  Forum
5- Functions of modification of a database




Introduction

With CPDB, you can dynamically create a structured database and add, modify or remove the records which it contains. Usually, these treatments requires tens of lines of code.



To create a CPDB database


Here an example which shows with which facility you can create a CPDB database:





// Create user base
Err errNo;
if (!CPDB_DatabaseExist("USERS"))
{
errNo = CPDB_CreateDatabase(0, "USERS", 'CPDB',
"NUM=INT;NAME=STRING[20];SURNAME=STRING[20];GROUP=SHORTINT");
}

The data base is thus created in only one line of code.


The mask of description is described in detail in the documentation of CPDB_CreateDatabase.


Add a record

The addition of a record is carried out in only one line of code :





// Create a new record
Err errNo;
errNo = CPDB_AddRecord(handle);

The variable "handle" corresponds to the handle of a beforehand open database.


If no record had been read previously, then a blank recording is created, if not, the new record is a copy of the currently record readed (or modified).


To be sure to create a blank record use function CPDB_Clear.


To delete a record, use the fonction CPDB_DeleteRecord.



Modification of a record


The fields of a record can by the use of the functions CPDB_WriteShortInt, CPDB_WriteInt, CPDB_WriteLongInt et CPDB_WriteString.


Once the modified fields, the record should either be updated by CPDB_updateRecord, or to create a new record by CPDB_AddRecord.





Err errNo;


// Update the fields of a record
CPDB_Clear(handle);
errNo = CPDB_WriteInt(handle, "NUM", iNum);
errNo = CPDB_WriteString(handle, "NAME", sName);
errNo = CPDB_WriteShortInt(handle, "GROUP", iGroup);

if ( bAddMode )
{
// Create a new record
errNo = CPDB_AddRecord(handle);
}
else
{
// Modification of the current record
errNo = CPDB_UpdateRecord(handle);
}


More informations


CPDB_AddRecord


CPDB_CreateDatabase


CPDB_WriteShortInt


CPDB_WriteInt


CPDB_WriteLongInt


CPDB_WriteString


CPDB_UpdateRecord


CPDB_Clear


CPDB_DeleteRecord


Creation date : 01/10/2003 @ 06:41
Last update : 01/10/2003 @ 07:31
Category : CPDB library
Page read 9657 times

Top


GuppY - http://www.freeguppy.org/
Site running with GuppY v3.1 - GNU Public License - © 2002-2024

Page loaded in 0.02 second