/**
* Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved
*
* @file	ai_database.h
*		AI Layer Database Header File
*
* @brief	The internel header file of database module.
*
*/
#ifndef __AI_DATABASE_DBMERGE_H__
#define __AI_DATABASE_DBMERGE_H__

#ifdef __cplusplus
	extern "C"{
#endif

#include "al_database.h"
#include "al_service.h"

/******************************************************************************
 *	Internal Function definition
 ******************************************************************************/
AL_Return_t AI_DB_Store_ATV(AL_DB_EDBType_t eDBType);
AL_Return_t AI_DB_Store_DTV(AL_DB_EDBType_t eDBType);
AL_Return_t AI_DB_SetDefault_ATV(AL_DB_EDBType_t eDBType);
AL_Return_t AI_DB_SetDefault_DTV(AL_DB_EDBType_t eDBType);
AL_Return_t AI_DB_Empty_ATV(AL_DB_EDBType_t eDBType);
AL_Return_t AI_DB_Empty_DTV(AL_DB_EDBType_t eDBType);
AL_Return_t AI_DB_AddRecord(AL_DB_EDBType_t eDBType,
	AL_DB_ERecordType_t eRecType, const al_void * pstRecDetail,
	AL_RecHandle_t hParentHdl, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_GetFistRecord(AL_DB_EDBType_t eDBType,
	AL_DB_ERecordType_t eRecType, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_GetLastRecord(AL_DB_EDBType_t eDBType,
	AL_DB_ERecordType_t eRecType, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_GetNextRecord(AL_RecHandle_t hRefHdl, AL_DB_ERecordType_t eRecType, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_GetPrevRecord(AL_RecHandle_t hRefHdl, AL_DB_ERecordType_t eRecType, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_GetParentRecord(AL_RecHandle_t hRefHdl, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_GetChildRecordNum(AL_RecHandle_t hParentHdl, al_uint32 *puiRecCnt);
AL_Return_t AI_DB_GetChildRecord(AL_RecHandle_t hParentHdl, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_MatchRecord(AL_DB_RecordMatchFunc fRecMatch,
	al_void *pMatchParam, AL_DB_EDBType_t eDBType, AL_DB_ERecordType_t eRecType, al_bool bNext, AL_RecHandle_t *phRecHdl);
AL_Return_t AI_DB_MatchRecordExt(AL_DB_RecordMatchFunc fRecMatch,
	al_void *pMatchParam, AL_DB_EDBType_t eDBType, AL_DB_ERecordType_t eRecType,
	al_bool bAscending, al_uint32 uiSkipNum, AL_RecHandle_t *phRecHdl, al_uint32 *puiRecNum);
AL_Return_t AI_DB_GetRecordType(AL_RecHandle_t hRecHdl,
	AL_DB_EDBType_t *peDBType, AL_DB_ERecordType_t *peRecType);
AL_Return_t AI_DB_MoveRecordToFirst(AL_RecHandle_t hRecHdl);
AL_Return_t AI_DB_MoveRecordToLast(AL_RecHandle_t hRecHdl);
AL_Return_t AI_DB_MoveRecordToFront(AL_RecHandle_t hCurrRecHdl, AL_RecHandle_t hRefRecHdl);
AL_Return_t AI_DB_MoveRecordToBehind(AL_RecHandle_t hCurrRecHdl, AL_RecHandle_t hRefRecHdl);
AL_Return_t AI_DB_SwapRecord(AL_RecHandle_t hCurrRecHdl, AL_RecHandle_t hRefRecHdl);
AL_Return_t AI_DB_RemoveRecord(AL_RecHandle_t hRecHdl);
AL_Return_t AI_DB_GetTotalNum(AL_DB_EDBType_t eDBType,
	AL_DB_ERecordType_t eRecType, al_uint32 *pu32Num);
AL_Return_t AI_DB_SearchChildRecords(AL_DB_RecordMatchFunc fRecMatch,al_void *pMatchParam,
	AL_DB_EDBType_t eDBType, AL_DB_ERecordType_t eRecType, CDBIHandle_t hHdl,
	al_uint32 u32NeedNum, al_uint32 u32SearchOffset, al_uint32 *pu32TotalNum,
	al_uint32 *pu32GotNum, AL_RecHandle_t *pstRecList);
AL_Return_t AI_DB_SearchRecords(AL_DB_RecordMatchFunc fRecMatch,al_void *pMatchParam,
	AL_DB_EDBType_t eDBType, AL_DB_ERecordType_t eRecType, al_uint32 u32NeedNum,
	al_uint32 u32SearchOffset, al_uint32 *pu32TotalNum, al_uint32 *pu32GotNum, AL_RecHandle_t *pstRecList);
AL_Return_t AI_DB_QueryDetail(AL_RecHandle_t hRecHdl, al_void *pDetailData);
AL_Return_t AI_DB_QueryDetailField(AL_RecHandle_t hRecHdl,
	al_uint16 u16ItemOffset, al_uint16 u16ItemBytes, al_void *pItemData);
AL_Return_t AI_DB_QueryDetailFieldByName(AL_RecHandle_t hRecHdl,
	al_uint8 *pItemName, al_void *pItemData);
AL_Return_t AI_DB_UpdateDetail(AL_RecHandle_t hRecHdl, const al_void *pDetailData);
AL_Return_t AI_DB_UpdateDetailField(AL_RecHandle_t hRecHdl,
	al_uint16 u16ItemOffset, al_uint16 u16ItemBytes, al_void *pItemData);
AL_Return_t AI_DB_UpdateDetailFieldByName(AL_RecHandle_t hRecHdl,
	al_uint8 *pItemName, al_void *pItemData);
AL_Return_t AI_DB_GetCapability(AL_DB_EDBType_t eDBType,AL_DBCapability_t *pstCapability);

AL_Return_t AI_DB_SortRecords(AL_DB_EDBType_t eDBType,
	AL_DB_ERecordType_t eRecType, AL_DB_ESortType_t eSortCmd, al_bool bAscending);
AL_Return_t AI_DB_SortRecordsByUser(AL_DB_EDBType_t eDBType,
	AL_DB_ERecordType_t eRecType, AL_DB_RecordUserCmp fRecUserCmpCB);

#ifdef __cplusplus
	}
#endif /* __cplusplus */

#endif /* __AL_DATABASE_H__ */

/*****************************************************************************
** $Rev$
**
*****************************************************************************/
