|
<< Click to Display Table of Contents >> C Examples: DbiTranslateRecordStructure |
![]() ![]()
|
Create a new table of the specified type by borrowing a field structure from another table.
The new table is created in the same directory or server as the source table. Return the cursor to the newly created table. This example uses the following input:
fDbiTranslateRecordStructure(hIBCur, "NEWCUST", "INTRBASE", &hTmpCur);
DBIResult fDbiTranslateRecordStructure(hDBICur hSrcCur, pCHAR NewTblName,
pCHAR DrvType, phDBICur phDstCur)
{
DBIResult rslt;
pFLDDesc SrcFldDesc, DestFldDesc;
CURProps CurProps;
CRTblDesc TblDesc;
hDBIDb hTmpDb;
rslt = Chk(DbiGetCursorProps(hSrcCur, &CurProps));
if (rslt != DBIERR_NONE)
return rslt;
SrcFldDesc = (pFLDDesc)malloc(CurProps.iFields * sizeof(FLDDesc));
DestFldDesc = (pFLDDesc)malloc(CurProps.iFields * sizeof(FLDDesc));
rslt = Chk(DbiGetFieldDescs(hSrcCur, SrcFldDesc));
if (rslt != DBIERR_NONE)
return rslt;
rslt = Chk(DbiTranslateRecordStructure(NULL, CurProps.iFields,
SrcFldDesc, DrvType, NULL, DestFldDesc, FALSE));
if (rslt != DBIERR_NONE)
{
free(SrcFldDesc); free(DestFldDesc);
return rslt;
}
memset((void *) &TblDesc , 0, sizeof(CRTblDesc));
strcpy(TblDesc.szTblName, NewTblName);
strcpy(TblDesc.szTblType, DrvType);
TblDesc.iFldCount = CurProps.iFields;
TblDesc.pfldDesc = DestFldDesc;
rslt = Chk(DbiGetObjFromObj(hSrcCur, objDATABASE, &hTmpDb));
if (rslt != DBIERR_NONE)
{
free(SrcFldDesc); free(DestFldDesc);
return rslt;
}
rslt = Chk(DbiCreateTable(hTmpDb, TRUE, &TblDesc));
if (rslt != DBIERR_NONE)
{
free(SrcFldDesc); free(DestFldDesc);
return rslt;
}
rslt = Chk(DbiOpenTable(hTmpDb, NewTblName, DrvType, NULL, NULL, 0, dbiREADWRITE,
dbiOPENSHARED, xltFIELD, FALSE, NULL, phDstCur));
free(SrcFldDesc); free(DestFldDesc);
return rslt;
}