BREW数据库应用简介
来源:互联网 发布:卫龙旗舰店淘宝被黑 编辑:程序博客网 时间:2024/05/16 14:02
BREW数据库是一种简单的关系型数据库,无多任务,无多用户,多记录。它提供给开发者三个接口:IDBMgr,IDatabase,IDBRecord。
IDBMgr接口用于创建、打开、和删除数据库。IDatabase接口用户创建和访问数据库中的记录。IDBRecord接口用户访问、更新数据库记录中的域。
下面是一些常用的数据库操作:
1、创建新数据库代码:
IDBMgr * pIDBMgr = NULL;
IDatabase * pIDatabase = NULL;
boolean bCreate = TRUE;
ISHELL_CreateInstance(pIShell, AEECLSID_DBMGR, (void **)&pIDBMgr);
if (pIDBMgr == NULL)
return;
if ((pIDatabase = IDBMGR_OpenDatabase (pIDBMgr, pszFile, bCreate)) == NULL)
{
// Opened an already existing database.
}
else
{
// Create an database.
}
2、打开数据库代码:
IDBMgr * pIDBMgr = NULL;
IDatabase * pIDatabase = NULL;
boolean bCreate = FALSE;
ISHELL_CreateInstance(pIShell, AEECLSID_DBMGR, (void **)&(*pIDBMgr));
if (pIDBMgr == NULL)
return;
if (((*pIDatabase) = IDBMGR_OpenDatabase ((*pIDBMgr), pszFile, bCreate)) == NULL)
{
// Opened an already existing database.
}
else
{
// Opened an database.
}
3、关闭数据库代码:
// IDATABASE_Release closes the open database files, and frees
// any memory associated with the database.
if (pIDatabase)
{
IDATABASE_Release (pIDatabase);
}
// Release IDBMgr object. This step needs to be done
// only if no further use of the IDBMgr object is needed.
if (pIDBMgr)
{
IDBMGR_Release (pIDBMgr);
}
4、创建一条记录代码:
boolean CreateOneRecord(IDatabase * pIDatabase, AEEDBField * dbField, int nNumfields)
{
IDBRecord * pIDBRecord = NULL;
// IDATABASE_CreateRecord: creates a new database record with the fields
// specified by pDBFields.
if ((pIDBRecord = IDATABASE_CreateRecord (pIDatabase, dbField, nNumfields)) != NULL)
{
// Successfully created a database record.
// Release record
IDBRECORD_Release (pIDBRecord);
return TRUE;
}
else
{
//Create DB Record Failed
}
return FALSE;
}
dbField指向数据库记录域,nNumfields是域的个数。可以创建一个这样的记录:
代码:
{
AEEDBField dbField[3];
int nNumfields = 3;
const char firstName [] = "John";
const char lastName [] = "Smith";
const char address [] = "123 First Street, USA";
AEEDBFieldType fieldType;
AEEDBFieldName fieldName;
// Data fill values used to create a database record.
// The parameter dbField is a three item array of type
// AEEDBField. Each array item corresponds to three fields
// of the record.
dbField[0].fName = AEEDBFIELD_FIRSTNAME;
dbField[0].fType = AEEDB_FT_STRING;
dbField[0].pBuffer = (void *)firstName;
dbField[0].wDataLen = STRLEN (firstName);
dbField[1].fName = AEEDBFIELD_LASTNAME;
dbField[1].fType = AEEDB_FT_STRING;
dbField[1].pBuffer = (void *)lastName;
dbField[1].wDataLen = STRLEN (lastName);
dbField[2].fName = AEEDBFIELD_ADDRESS;
dbField[2].fType = AEEDB_FT_STRING;
dbField[2].pBuffer = (void *)address;
dbField[2].wDataLen = STRLEN (address);
return CreateOneRecord(pIDatabase, dbField, 3);
}
5、获取记录个数代码:
uint32 GetRecordCount(IDatabase * pIDatabase)
{
// IDATABASE_GetRecordCount: returns the number of records in the
// database specified. This gives the number of records in the
// database prior to creating any records in the database.
return IDATABASE_GetRecordCount (pIDatabase);
}
6、读取记录域代码:
boolean GetRecordByID(IDatabase * pIDatabase, uint16 u16RecID)
{
IDBRecord * pIDBRec1 = NULL;
AEEDBFieldType fType;
AEEDBFieldName fName;
uint16 fLen;
byte * data = NULL;;
// This will reset the record Index to 0.
IDATABASE_Reset (pIDatabase);
// IDATABASE_GetRecordByID: returns a pointer to the record whose
// record ID is specified.
pIDBRec1 = IDATABASE_GetRecordByID (pIDatabase, u16RecID);
// Get the raw data of the field
for(;;)
{
// Get record 1 first field and display it
fType = IDBRECORD_NextField (pIDBRec1, &fName, &fLen);
data = IDBRECORD_GetField (pIDBRec1, &fName, &fType, &fLen);
if (data != NULL)
{
switch(fName)
{
case AEEDBFIELD_FIRSTNAME;
break;
case AEEDBFIELD_LASTNAME;
break;
case AEEDBFIELD_ADDRESS;
break;
default:
break;
}
}
else
{
break; //break for
}
}
// Now remove record 1.
IDBRECORD_Release(pIDBRec1);
return TRUE;
}
IDBMgr接口用于创建、打开、和删除数据库。IDatabase接口用户创建和访问数据库中的记录。IDBRecord接口用户访问、更新数据库记录中的域。
下面是一些常用的数据库操作:
1、创建新数据库代码:
IDBMgr * pIDBMgr = NULL;
IDatabase * pIDatabase = NULL;
boolean bCreate = TRUE;
ISHELL_CreateInstance(pIShell, AEECLSID_DBMGR, (void **)&pIDBMgr);
if (pIDBMgr == NULL)
return;
if ((pIDatabase = IDBMGR_OpenDatabase (pIDBMgr, pszFile, bCreate)) == NULL)
{
// Opened an already existing database.
}
else
{
// Create an database.
}
2、打开数据库代码:
IDBMgr * pIDBMgr = NULL;
IDatabase * pIDatabase = NULL;
boolean bCreate = FALSE;
ISHELL_CreateInstance(pIShell, AEECLSID_DBMGR, (void **)&(*pIDBMgr));
if (pIDBMgr == NULL)
return;
if (((*pIDatabase) = IDBMGR_OpenDatabase ((*pIDBMgr), pszFile, bCreate)) == NULL)
{
// Opened an already existing database.
}
else
{
// Opened an database.
}
3、关闭数据库代码:
// IDATABASE_Release closes the open database files, and frees
// any memory associated with the database.
if (pIDatabase)
{
IDATABASE_Release (pIDatabase);
}
// Release IDBMgr object. This step needs to be done
// only if no further use of the IDBMgr object is needed.
if (pIDBMgr)
{
IDBMGR_Release (pIDBMgr);
}
4、创建一条记录代码:
boolean CreateOneRecord(IDatabase * pIDatabase, AEEDBField * dbField, int nNumfields)
{
IDBRecord * pIDBRecord = NULL;
// IDATABASE_CreateRecord: creates a new database record with the fields
// specified by pDBFields.
if ((pIDBRecord = IDATABASE_CreateRecord (pIDatabase, dbField, nNumfields)) != NULL)
{
// Successfully created a database record.
// Release record
IDBRECORD_Release (pIDBRecord);
return TRUE;
}
else
{
//Create DB Record Failed
}
return FALSE;
}
dbField指向数据库记录域,nNumfields是域的个数。可以创建一个这样的记录:
代码:
{
AEEDBField dbField[3];
int nNumfields = 3;
const char firstName [] = "John";
const char lastName [] = "Smith";
const char address [] = "123 First Street, USA";
AEEDBFieldType fieldType;
AEEDBFieldName fieldName;
// Data fill values used to create a database record.
// The parameter dbField is a three item array of type
// AEEDBField. Each array item corresponds to three fields
// of the record.
dbField[0].fName = AEEDBFIELD_FIRSTNAME;
dbField[0].fType = AEEDB_FT_STRING;
dbField[0].pBuffer = (void *)firstName;
dbField[0].wDataLen = STRLEN (firstName);
dbField[1].fName = AEEDBFIELD_LASTNAME;
dbField[1].fType = AEEDB_FT_STRING;
dbField[1].pBuffer = (void *)lastName;
dbField[1].wDataLen = STRLEN (lastName);
dbField[2].fName = AEEDBFIELD_ADDRESS;
dbField[2].fType = AEEDB_FT_STRING;
dbField[2].pBuffer = (void *)address;
dbField[2].wDataLen = STRLEN (address);
return CreateOneRecord(pIDatabase, dbField, 3);
}
5、获取记录个数代码:
uint32 GetRecordCount(IDatabase * pIDatabase)
{
// IDATABASE_GetRecordCount: returns the number of records in the
// database specified. This gives the number of records in the
// database prior to creating any records in the database.
return IDATABASE_GetRecordCount (pIDatabase);
}
6、读取记录域代码:
boolean GetRecordByID(IDatabase * pIDatabase, uint16 u16RecID)
{
IDBRecord * pIDBRec1 = NULL;
AEEDBFieldType fType;
AEEDBFieldName fName;
uint16 fLen;
byte * data = NULL;;
// This will reset the record Index to 0.
IDATABASE_Reset (pIDatabase);
// IDATABASE_GetRecordByID: returns a pointer to the record whose
// record ID is specified.
pIDBRec1 = IDATABASE_GetRecordByID (pIDatabase, u16RecID);
// Get the raw data of the field
for(;;)
{
// Get record 1 first field and display it
fType = IDBRECORD_NextField (pIDBRec1, &fName, &fLen);
data = IDBRECORD_GetField (pIDBRec1, &fName, &fType, &fLen);
if (data != NULL)
{
switch(fName)
{
case AEEDBFIELD_FIRSTNAME;
break;
case AEEDBFIELD_LASTNAME;
break;
case AEEDBFIELD_ADDRESS;
break;
default:
break;
}
}
else
{
break; //break for
}
}
// Now remove record 1.
IDBRECORD_Release(pIDBRec1);
return TRUE;
}
- BREW数据库应用简介
- Brew开发简介
- BREW中的应用定价
- BREW应用自动安装
- BREW后台应用
- brew菜单应用学习体会
- BREW 数据库接口
- Brew ---- 数据库操作
- 《深入BREW开发》——第五章 BREW简介
- BREW应用移植的体会
- Brew 后台应用开发(转载)
- 数据库技术在BREW中的应用
- Brew手机安装应用经验
- Brew上的应用开发
- BREW应用的分发流程
- BREW应用的空中下载
- BREW 应用的开发流程
- BREW 应用的交叉编译
- 如何让变参能够为空
- 怎样发表文章网站才会来流量
- CPU内部寄存器(ebp,esp等)
- powerbuilder的C/S结构程序部署为基于.net的
- MyEclipse快捷键大全
- BREW数据库应用简介
- dotproject 的安装和配置
- 谁能告诉我该怎么办?
- js 读写文件
- 如何使用 RBAC 组件实现访问控制
- 生活的理想,就是为了理想的生活
- SQL大全(很强大)第一部分
- 实施前的动员会4.13
- SQL大全(很强大)第二部分