static HB_ERRCODE sqlbaseOpen( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo ) { HB_ERRCODE errCode; pArea->ulConnection = pOpenInfo->ulConnection ? pOpenInfo->ulConnection : s_ulConnectionCurrent; if ( pArea->ulConnection == 0 || pArea->ulConnection > s_ulConnectionCount || ! s_pConnection[ pArea->ulConnection - 1 ] ) { hb_errRT_SQLBASE( EG_OPEN, ESQLDD_NOTCONNECTED, "Not connected", NULL ); return HB_FAILURE; } if ( pArea->area.uiFieldCount ) /* This should not happen (in __dbTrans()), because RDD is registered with RDT_FULL */ return HB_FAILURE; pArea->pConnection = s_pConnection[ pArea->ulConnection - 1 ]; pArea->pConnection->uiAreaCount++; pArea->pSDD = pArea->pConnection->pSDD; /* filename is a query */ pArea->szQuery = hb_strdup( pOpenInfo->abName ); errCode = pArea->pSDD->Open( pArea ); if ( errCode == HB_SUCCESS ) { errCode = SUPER_OPEN( ( AREAP ) pArea, pOpenInfo ); } if( errCode != HB_SUCCESS ) { SELF_CLOSE( ( AREAP ) pArea ); return HB_FAILURE; } return SELF_GOTOP( ( AREAP ) pArea ); }
static HB_ERRCODE sqlbaseCreate( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo ) { PHB_ITEM pItemEof, pItem; HB_USHORT uiCount; HB_BOOL bError; pArea->ulConnection = pOpenInfo->ulConnection ? pOpenInfo->ulConnection : s_ulConnectionCurrent; if( pArea->ulConnection > s_ulConnectionCount || ( pArea->ulConnection && ! s_pConnection[ pArea->ulConnection - 1 ] ) ) { hb_errRT_SQLBASE( EG_OPEN, ESQLDD_NOTCONNECTED, "Not connected", NULL ); return HB_FAILURE; } if( pArea->ulConnection ) { pArea->pConnection = s_pConnection[ pArea->ulConnection - 1 ]; pArea->pConnection->uiAreaCount++; pArea->pSDD = pArea->pConnection->pSDD; } else pArea->pSDD = &sddNull; pItemEof = hb_itemArrayNew( pArea->area.uiFieldCount ); bError = HB_FALSE; for( uiCount = 0; uiCount < pArea->area.uiFieldCount; uiCount++ ) { LPFIELD pField = pArea->area.lpFields + uiCount; switch( pField->uiType ) { case HB_FT_STRING: { char * pStr; pStr = ( char * ) hb_xgrab( pField->uiLen + 1 ); memset( pStr, ' ', pField->uiLen ); pStr[ pField->uiLen ] = '\0'; pItem = hb_itemPutCL( NULL, pStr, pField->uiLen ); hb_xfree( pStr ); break; } case HB_FT_MEMO: pItem = hb_itemPutC( NULL, NULL ); break; case HB_FT_INTEGER: if( pField->uiDec ) pItem = hb_itemPutND( NULL, 0.0 ); else pItem = hb_itemPutNI( NULL, 0 ); break; case HB_FT_LONG: if( pField->uiDec ) pItem = hb_itemPutND( NULL, 0.0 ); else pItem = hb_itemPutNL( NULL, 0 ); break; case HB_FT_FLOAT: pItem = hb_itemPutND( NULL, 0.0 ); break; case HB_FT_DOUBLE: pItem = hb_itemPutND( NULL, 0.0 ); break; case HB_FT_DATE: pItem = hb_itemPutDS( NULL, NULL ); break; case HB_FT_LOGICAL: pItem = hb_itemPutL( NULL, HB_FALSE ); break; default: pItem = hb_itemNew( NULL ); bError = HB_TRUE; break; } hb_arraySetForward( pItemEof, uiCount + 1, pItem ); hb_itemRelease( pItem ); if( bError ) break; } if( bError ) { hb_itemClear( pItemEof ); hb_itemRelease( pItemEof ); hb_errRT_SQLBASE( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", NULL ); SELF_CLOSE( ( AREAP ) pArea ); return HB_FAILURE; } pArea->ulRecCount = 0; pArea->pRow = ( void ** ) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( void * ) ); pArea->pRowFlags = ( HB_BYTE * ) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( HB_BYTE ) ); pArea->ulRecMax = SQLDD_ROWSET_RESIZE; *( pArea->pRow ) = pItemEof; pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED; pArea->fFetched = HB_TRUE; if( SUPER_CREATE( ( AREAP ) pArea, pOpenInfo ) != HB_SUCCESS ) { SELF_CLOSE( ( AREAP ) pArea ); return HB_FAILURE; } return SELF_GOTOP( ( AREAP ) pArea ); }
/* * Open a data store in the WorkArea. */ static HB_ERRCODE hb_sdfOpen( SDFAREAP pArea, LPDBOPENINFO pOpenInfo ) { PHB_ITEM pError = NULL; PHB_FNAME pFileName; HB_ERRCODE errCode; HB_USHORT uiFlags; HB_BOOL fRetry; char szFileName[ HB_PATH_MAX ]; char szAlias[ HB_RDD_MAX_ALIAS_LEN + 1 ]; HB_TRACE( HB_TR_DEBUG, ( "hb_sdfOpen(%p,%p)", pArea, pOpenInfo ) ); pArea->fShared = HB_TRUE; /* pOpenInfo->fShared; */ pArea->fReadonly = HB_TRUE; /* pOpenInfo->fReadonly; */ if( pOpenInfo->cdpId ) { pArea->area.cdPage = hb_cdpFindExt( pOpenInfo->cdpId ); if( ! pArea->area.cdPage ) pArea->area.cdPage = hb_vmCDP(); } else pArea->area.cdPage = hb_vmCDP(); uiFlags = ( pArea->fReadonly ? FO_READ : FO_READWRITE ) | ( pArea->fShared ? FO_DENYNONE : FO_EXCLUSIVE ); pFileName = hb_fsFNameSplit( pOpenInfo->abName ); /* Add default file name extension if necessary */ if( hb_setGetDefExtension() && ! pFileName->szExtension ) { PHB_ITEM pFileExt = hb_itemPutC( NULL, NULL ); SELF_INFO( &pArea->area, DBI_TABLEEXT, pFileExt ); pFileName->szExtension = hb_itemGetCPtr( pFileExt ); hb_fsFNameMerge( szFileName, pFileName ); hb_itemRelease( pFileExt ); } else { hb_strncpy( szFileName, pOpenInfo->abName, sizeof( szFileName ) - 1 ); } /* Create default alias if necessary */ if( ! pOpenInfo->atomAlias && pFileName->szName ) { const char * szName = strrchr( pFileName->szName, ':' ); if( szName == NULL ) szName = pFileName->szName; else ++szName; hb_strncpyUpperTrim( szAlias, szName, sizeof( szAlias ) - 1 ); pOpenInfo->atomAlias = szAlias; } hb_xfree( pFileName ); /* Try open */ do { pArea->pFile = hb_fileExtOpen( szFileName, NULL, uiFlags | FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME | FXO_NOSEEKPOS, NULL, pError ); if( ! pArea->pFile ) { if( ! pError ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_OPEN ); hb_errPutSubCode( pError, EDBF_OPEN_DBF ); hb_errPutOsCode( pError, hb_fsError() ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_OPEN ) ); hb_errPutFileName( pError, szFileName ); hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); } fRetry = ( SELF_ERROR( &pArea->area, pError ) == E_RETRY ); } else fRetry = HB_FALSE; } while( fRetry ); if( pError ) hb_itemRelease( pError ); if( ! pArea->pFile ) return HB_FAILURE; errCode = SUPER_OPEN( &pArea->area, pOpenInfo ); if( errCode != HB_SUCCESS ) { SELF_CLOSE( &pArea->area ); return HB_FAILURE; } hb_sdfInitArea( pArea, szFileName ); /* Position cursor at the first record */ return SELF_GOTOP( &pArea->area ); }
/* * Create a data store in the specified WorkArea. */ static HB_ERRCODE hb_sdfCreate( SDFAREAP pArea, LPDBOPENINFO pCreateInfo ) { HB_ERRCODE errCode; PHB_FNAME pFileName; PHB_ITEM pError = NULL; HB_BOOL fRetry; char szFileName[ HB_PATH_MAX ]; HB_TRACE( HB_TR_DEBUG, ( "hb_sdfCreate(%p,%p)", pArea, pCreateInfo ) ); pArea->fShared = HB_FALSE; /* pCreateInfo->fShared; */ pArea->fReadonly = HB_FALSE; /* pCreateInfo->fReadonly */ if( pCreateInfo->cdpId ) { pArea->area.cdPage = hb_cdpFindExt( pCreateInfo->cdpId ); if( ! pArea->area.cdPage ) pArea->area.cdPage = hb_vmCDP(); } else pArea->area.cdPage = hb_vmCDP(); pFileName = hb_fsFNameSplit( pCreateInfo->abName ); if( hb_setGetDefExtension() && ! pFileName->szExtension ) { PHB_ITEM pItem = hb_itemPutC( NULL, NULL ); SELF_INFO( &pArea->area, DBI_TABLEEXT, pItem ); pFileName->szExtension = hb_itemGetCPtr( pItem ); hb_fsFNameMerge( szFileName, pFileName ); hb_itemRelease( pItem ); } else { hb_strncpy( szFileName, pCreateInfo->abName, sizeof( szFileName ) - 1 ); } hb_xfree( pFileName ); /* Try create */ do { pArea->pFile = hb_fileExtOpen( szFileName, NULL, FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE | FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME | FXO_NOSEEKPOS, NULL, pError ); if( ! pArea->pFile ) { if( ! pError ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_CREATE ); hb_errPutSubCode( pError, EDBF_CREATE_DBF ); hb_errPutOsCode( pError, hb_fsError() ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CREATE ) ); hb_errPutFileName( pError, szFileName ); hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); } fRetry = ( SELF_ERROR( &pArea->area, pError ) == E_RETRY ); } else fRetry = HB_FALSE; } while( fRetry ); if( pError ) hb_itemRelease( pError ); if( ! pArea->pFile ) return HB_FAILURE; errCode = SUPER_CREATE( &pArea->area, pCreateInfo ); if( errCode != HB_SUCCESS ) { SELF_CLOSE( &pArea->area ); return errCode; } hb_sdfInitArea( pArea, szFileName ); /* Position cursor at the first record */ return SELF_GOTOP( &pArea->area ); }