1640 lines
45 KiB
C++
1640 lines
45 KiB
C++
//---------------------------------------------------------------------------
|
||
#include <vcl.h>
|
||
#pragma hdrstop
|
||
//---------------------------------------------------------------------------
|
||
#include "stdlib.h"
|
||
#include "stdio.h"
|
||
#include "dos.h"
|
||
#include "alloc.h"
|
||
#include "BDEMONTREL.h"
|
||
|
||
char FicheroError[DIM_FICHEROTXT]="";
|
||
|
||
//---------------------------------------------------------------------------
|
||
// Important note about DLL memory management when your DLL uses the
|
||
// static version of the RunTime Library:
|
||
//
|
||
// If your DLL exports any functions that pass String objects (or structs/
|
||
// classes containing nested Strings) as parameter or function results,
|
||
// you will need to add the library MEMMGR.LIB to both the DLL project and
|
||
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
|
||
// if any other projects which use the DLL will be perfomring new or delete
|
||
// operations on any non-TObject-derived classes which are exported from the
|
||
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
|
||
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
|
||
// the file BORLNDMM.DLL should be deployed along with your DLL.
|
||
//
|
||
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
|
||
// ShortString parameters.
|
||
//
|
||
// If your DLL uses the dynamic version of the RTL, you do not need to
|
||
// explicitly add MEMMGR.LIB as this will be done implicitly for you
|
||
//---------------------------------------------------------------------------
|
||
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
|
||
{
|
||
return 1;
|
||
}
|
||
//===============================================================
|
||
// Funcion:
|
||
// IndCampo (dbiTabla* psT,char *pszCampo);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// szCampo - Nombre del campo descriptor.
|
||
//
|
||
// Devuelve: 1..N - Numero del campo descriptor .
|
||
// 0 - Campo desconocido.
|
||
//
|
||
// Description:
|
||
// Devuelve el numero del campo descriptor de entrada.
|
||
//================================================================
|
||
|
||
int IndCampo (dbiTabla* psT,char *pszCampo)
|
||
{
|
||
int nI;
|
||
|
||
nI = 0;
|
||
while ((nI < psT->curProps.iFields) && strcmp ((psT->pFldArray+nI)->szName,pszCampo))
|
||
nI++;
|
||
if (nI == psT->curProps.iFields)
|
||
nI = -1;
|
||
nI++;
|
||
|
||
return (nI);
|
||
}
|
||
|
||
//===============================================================
|
||
// Function:
|
||
// LIBError (char *pszDescError,char *pszContext1,char *pszContext2);
|
||
//
|
||
// Input: pszDescError - Descripcion error
|
||
// pszContext1 - Contexto 1
|
||
// pszContext2 - Contexto 2
|
||
//
|
||
// Description:
|
||
// Visualiza una ventana con informacion sobre el error de libreria.
|
||
// En la version grafica se grabara en logger y se
|
||
// presentara una ventana no bloqueante.
|
||
//================================================================
|
||
/*
|
||
void LIBError (char *pszDescError,char *pszContext1,char *pszContext2)
|
||
{
|
||
/* char szDes [TAMAX_BUFFER_TXT + 1];
|
||
char szHora[TAMAX_HORA+1];
|
||
char szFecha[TAMAX_FECHA+1];
|
||
|
||
CapturaFechaHora(szFecha,szHora);
|
||
Formatea (szDes,sizeof(szDes),
|
||
"%s. 1) %s. 2) %s",
|
||
pszDescError,pszContext1,pszContext2);
|
||
ExcepcionHistoricoTxt(szFecha,szHora,"Error","LIBDBI",szDes,NULL,NULL,NULL,NULL,NULL);
|
||
Formatea (szDes,sizeof(szDes),
|
||
"%s\n1) %s\n2) %s",
|
||
pszDescError,pszContext1,pszContext2);
|
||
poAplicacion->MessageBox(szDes,"Error librer<65>a DBI",MB_OK);
|
||
}*/
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// DBIError(DBIResult CodError);
|
||
//
|
||
// Entrada: CodError - Codigo del error
|
||
//
|
||
// Descripcion:
|
||
// Visualiza una ventana con informacion sobre el error DBI.
|
||
// En la version grafica se grabara en logger y se
|
||
// presentara una ventana no bloqueante.
|
||
//================================================================
|
||
void DBIError (DBIResult CodError)
|
||
{
|
||
DBIResult rslt;
|
||
DBIErrInfo ErrInfo;
|
||
DBIMSG ErrDesc;
|
||
char szDes [TAM_MAX_CADENA];
|
||
|
||
rslt = DbiGetErrorInfo(TRUE,ErrInfo);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (CodError == ErrInfo.iError)
|
||
{
|
||
sprintf (szDes,
|
||
"Error Info %s (%d,%d:%d). 1) %s. 2) %s. 3) %s. 4) %s",
|
||
ErrInfo.szErrCode,CodError,ErrCat(CodError),ErrCode(CodError),
|
||
ErrInfo.szContext[1],ErrInfo.szContext[2],ErrInfo.szContext[3],ErrInfo.szContext[4]);
|
||
if(strcmp(FicheroError,""))
|
||
GenerarError(szDes);
|
||
}
|
||
else
|
||
{
|
||
rslt = DbiGetErrorString(CodError,ErrDesc);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
sprintf(szDes,"Error String %s (%d,%d:%d)",
|
||
ErrDesc,CodError,ErrCat(CodError),ErrCode(CodError));
|
||
if(strcmp(FicheroError,""))
|
||
GenerarError(szDes);
|
||
}
|
||
else
|
||
{
|
||
if(strcmp(FicheroError,""))
|
||
GenerarError("Error Dbidif sin informaci<63>n");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(strcmp(FicheroError,""))
|
||
GenerarError("Error Dbidif sin informaci<63>n");
|
||
}
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// AnsiToNativo (char *pszValorAnsi);
|
||
//
|
||
// Entrada:
|
||
// pszValorAnsi - Valor Ansi a convertir.
|
||
//
|
||
// Devuelve:
|
||
// Valor convertido
|
||
//
|
||
// Descripcion:
|
||
// Convierte una cadena ANSI al lenguaje nativo de la
|
||
// base de datos. Una cadena ANSI es, por ejemplo, la
|
||
// definida internamente en un fichero fuente.
|
||
//================================================================
|
||
|
||
DBIResult AnsiToNativo (char *pszAnsi,char *pszNativo)
|
||
{
|
||
DBIResult rslt;
|
||
void *pLdObj;
|
||
int bDataLoss;
|
||
|
||
rslt = DbiGetLdObj(NULL,pLdObj);
|
||
if (rslt == DBIERR_NONE)
|
||
rslt = DbiAnsiToNative(pLdObj,pszNativo,pszAnsi,0,bDataLoss);
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// InicializarBDE(char *pszIniFile)
|
||
//
|
||
// Entrada: pszIniFile - Nombre fichero de configuracion con extension .CFG
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Inicializa IDAPI indicada.
|
||
//===============================================================
|
||
|
||
DBIResult InicializarBDE(char *pszIniFile)
|
||
{
|
||
DBIResult rslt;
|
||
DBIEnv envr;
|
||
|
||
strcpy (envr.szWorkDir,"");
|
||
strcpy (envr.szIniFile,pszIniFile);
|
||
strcpy (envr.szLang,"");
|
||
strcpy (envr.szClientName,"");
|
||
envr.bForceLocalInit = FALSE;
|
||
|
||
rslt = DbiInit(&envr);
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return rslt;
|
||
}
|
||
//===============================================================
|
||
// Funcion:
|
||
// ConectarBDE(char *pszBaseDatos,hDBIDb *hBaseDatos)
|
||
//
|
||
// Entrada: pszBaseDatos - Nombre base de datos.
|
||
// hDBIDb *hBaseDatos - Puntero a la base de Datos
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Inicializa IDAPI indicada.
|
||
//===============================================================
|
||
|
||
DBIResult ConectarBDE(char *pszBaseDatos,hDBIDb *hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiOpenDatabase(pszBaseDatos,NULL,dbiREADWRITE,dbiOPENSHARED,
|
||
NULL,0,NULL,NULL,*hBaseDatos);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return rslt;
|
||
}
|
||
//===============================================================
|
||
// Funcion:
|
||
// DesconectarBDE (hDBIDb hBaseDatos)
|
||
//
|
||
// Entrada: hDBIDb hBaseDatos - Base de Datos
|
||
//
|
||
// Devuelve: DBIResult.
|
||
//
|
||
// Descripcion:
|
||
// Cierra la Database.
|
||
//================================================================
|
||
DBIResult DesconectarBDE (hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
rslt = DbiCloseDatabase(hBaseDatos);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return rslt;
|
||
}
|
||
//===============================================================
|
||
// Funcion:
|
||
// FinalizarBDE (void)
|
||
//
|
||
// Devuelve: DBIResult.
|
||
//
|
||
// Descripcion:
|
||
// Finaliza el IDAPI.
|
||
//================================================================
|
||
|
||
DBIResult FinalizarBDE (void)
|
||
{
|
||
DBIResult rslt;
|
||
rslt = DbiExit();
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// CargarDirDbf(char *pszDir);
|
||
//
|
||
// Entrada: char *pszDir - puntero al directorio de la base de datos
|
||
// hDBIDb hBaseDatos - Nombre de la base de datos
|
||
//
|
||
// Devuelve: DBIResult.
|
||
//
|
||
// Descripcion:
|
||
// Carga en pszDir el directorio donde se encuentran los
|
||
// dbf para esta base de datos
|
||
//================================================================
|
||
|
||
DBIResult CargarDirBDE (char *pszDir,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiGetDirectory(hBaseDatos,TRUE,pszDir);
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return rslt;
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// AbrirTablaBDE (dbiTabla *psT, char *pszNombreTabla,char *pszNombreTag,bool bExclusivo);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// pszNombreTabla - Nombre de la tabla (sin extensi<73>n).
|
||
// pszNombreTag - Nombre indice de apertura (en orden natural sera NULL).
|
||
// bExclusivo - TRUE si se abre en exclusiva.
|
||
//
|
||
// Devuelve: DBIResult.
|
||
//
|
||
// Descripcion:
|
||
// Abre la tabla indicada, con indice o no activo,
|
||
// en modo exclusivo o no y se posiciona en el primer registro.
|
||
//================================================================
|
||
|
||
DBIResult AbrirTablaBDE (dbiTabla *psT, char *pszNombreTabla,char *pszNombreTag,bool bExclusivo,hDBIDb hBaseDatos)
|
||
{
|
||
int iReproceso;
|
||
char szNombreIndice [DBIMAXTBLNAMELEN+1];
|
||
DBIResult rslt;
|
||
DBIShareMode eModo;
|
||
|
||
psT->bTablaAbierta = FALSE;
|
||
iReproceso = DEF_MAXREPOPENTABLE;
|
||
(bExclusivo ? eModo = dbiOPENEXCL : eModo = dbiOPENSHARED);
|
||
*szNombreIndice = 0;
|
||
if (pszNombreTag)
|
||
{
|
||
strcpy (szNombreIndice,pszNombreTabla);
|
||
strcat (szNombreIndice,DEF_MDXEXT);
|
||
}
|
||
|
||
do
|
||
{
|
||
rslt = DbiOpenTable (hBaseDatos,pszNombreTabla,szDBASE,szNombreIndice,pszNombreTag,
|
||
0,dbiREADWRITE,eModo,xltNONE,FALSE,NULL,psT->hCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
DbiGetCursorProps (psT->hCur, psT->curProps);
|
||
psT->pRecBuf = (PByte) malloc (psT->curProps.iRecBufSize);
|
||
if (psT->pRecBuf)
|
||
{
|
||
psT->pFldArray = (pFLDDesc) malloc (sizeof(FLDDesc) * psT->curProps.iFields);
|
||
if (psT->pFldArray)
|
||
{
|
||
DbiGetFieldDescs (psT->hCur,psT->pFldArray);
|
||
DbiSetProp(psT->hCur,curSOFTDELETEON,TRUE);
|
||
DbiGetNextRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,NULL);
|
||
psT->bTablaAbierta = TRUE;
|
||
}
|
||
else
|
||
{
|
||
rslt = DBIERR_NOMEMORY;
|
||
free (psT->pRecBuf);
|
||
DbiCloseCursor (psT->hCur);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
rslt = DBIERR_NOMEMORY;
|
||
DbiCloseCursor (psT->hCur);
|
||
}
|
||
}
|
||
else
|
||
if (rslt == DBIERR_FILEBUSY)
|
||
{
|
||
iReproceso--;
|
||
Sleep (RETARDO_ABRIR_TABLA);
|
||
}
|
||
}
|
||
while (iReproceso && (rslt == DBIERR_FILEBUSY));
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// CerrarTablaBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Cierra la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult CerrarTablaBDE (dbiTabla* psT)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DBIERR_NONE;
|
||
if (psT->bTablaAbierta)
|
||
{
|
||
free (psT->pFldArray);
|
||
free (psT->pRecBuf);
|
||
rslt = DbiCloseCursor (psT->hCur);
|
||
psT->bTablaAbierta = FALSE;
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// ContarRegBDE (dbiTabla* psT,UINT32 *nRN)
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Salida nRN - Puntero al numero de registros.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Devuelve el numero de registros en la tabla.
|
||
//================================================================
|
||
|
||
DBIResult ContarRegBDE (dbiTabla* psT,int *nRN)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiGetRecordCount(psT->hCur,*nRN);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// NumRegBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Salida nRN - Puntero al numero del registro.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Devuelve el ordinal del registro en curso
|
||
//================================================================
|
||
|
||
DBIResult NumRegBDE (dbiTabla* psT,int *nRN)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiGetRecord(psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
*nRN = (int) psT->recProps.iPhyRecNum;
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// IrRegBDE (dbiTabla* psT,int nNumRec,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// nNumRec - Numero de registro.
|
||
// bRD - TRUE, si esta borrado.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Se posiciona en el registro indicado
|
||
//================================================================
|
||
|
||
DBIResult IrRegBDE (dbiTabla* psT,int nNumRec,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetToRecordNo (psT->hCur,nNumRec);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiGetRecord(psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// EstaRegBorBDE (dbiTabla* psT,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Salida bRD - Puntero al dato.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Devuelve si el registro en curso est<73> marcado para borrar.
|
||
//================================================================
|
||
|
||
DBIResult EstaRegBorBDE (dbiTabla* psT,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiGetRecord(psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// BorrarRegBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Marca el registro en curso para borrar.
|
||
//================================================================
|
||
|
||
DBIResult BorrarRegBDE (dbiTabla* psT)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiDeleteRecord(psT->hCur,psT->pRecBuf);
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// RecRegBorBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Desmarca el registro en curso para borrar.
|
||
//================================================================
|
||
|
||
DBIResult RecRegBorBDE (dbiTabla* psT)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiUndeleteRecord(psT->hCur);
|
||
if(rslt != DBIERR_NONE && rslt!=DBIERR_NA)//10756 El Reg no esta borrado
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// VerBorradosBDE (dbiTabla* psT,bool bON);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// bON - TRUE, los registros marcados son utilizables.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Cambia la propiedad SET DELETED
|
||
//================================================================
|
||
|
||
DBIResult VerBorradosBDE (dbiTabla* psT,bool bON)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetProp(psT->hCur,curSOFTDELETEON,bON);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// IrPrimerRegBDE (dbiTabla* psT,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Se posiciona en el primer registro
|
||
//================================================================
|
||
|
||
DBIResult IrPrimerRegBDE (dbiTabla* psT,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetToBegin (psT->hCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiGetNextRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// IrUltimoRegBDE (dbiTabla* psT,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Se posiciona en el ultimo registro
|
||
//================================================================
|
||
|
||
DBIResult IrUltimoRegBDE (dbiTabla* psT,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetToEnd (psT->hCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiGetPriorRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// IrSiguienteRegBDE (dbiTabla* psT,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Se posiciona en el siguiente registro de la tabla.
|
||
//================================================================
|
||
|
||
DBIResult IrSiguienteRegBDE (dbiTabla* psT,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiGetNextRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE && rslt!=DBIERR_EOF)//8706 Fin de registros
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// IrAnteriorRegBDE (dbiTabla* psT,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Se posiciona en el siguiente registro de la tabla.
|
||
//================================================================
|
||
|
||
DBIResult IrAnteriorRegBDE (dbiTabla* psT,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiGetPriorRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
if(rslt != DBIERR_NONE && rslt!=DBIERR_BOF)//8705 Principio de registros
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// SelIndBDE (dbiTabla* psT,char* szNombreTag);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// szNombreIndice - Nombre del Indice en el que se quiere buscar.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Selecciona el indice en la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult SelIndBDE (dbiTabla* psT,char* szNombreTag)
|
||
{
|
||
char szNombreIndice [DBIMAXTBLNAMELEN+1];
|
||
DBIResult rslt;
|
||
|
||
strcpy (szNombreIndice,psT->curProps.szName);
|
||
strcat (szNombreIndice,DEF_MDXEXT);
|
||
rslt = DbiSwitchToIndex (psT->hCur,szNombreIndice,szNombreTag,NULL,false);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// BuscarValorExactoBDE(dbiTabla *psT,char *pszValor,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// szValor - Valor del Indice a encontrar.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Busca un valor <20>ndice exacto en la tabla y se posiciona en el
|
||
// registro correspondiente.
|
||
//================================================================
|
||
|
||
DBIResult BuscarValorExactoBDE (dbiTabla *psT,char *pszValor,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetToKey (psT->hCur,keySEARCHEQ,true,0,0,(PByte)pszValor);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiGetNextRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE && rslt!=DBIERR_RECNOTFOUND)//8710 no encontro busqueda
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// BuscarValorAproxBDE (dbiTabla *psT,char *pszValor,bool *bRD);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// szValor - Valor del Indice a encontrar.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Busca un valor <20>ndice aproximado en la tabla y se posiciona en el
|
||
// registro correspondiente.
|
||
//================================================================
|
||
|
||
DBIResult BuscarValorAproxBDE (dbiTabla *psT,char *pszValor,bool *bRD)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetToKey (psT->hCur,keySEARCHGEQ,true,0,0,(PByte) pszValor);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiGetNextRecord (psT->hCur,dbiNOLOCK,psT->pRecBuf,&psT->recProps);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
if (bRD)
|
||
*bRD = psT->recProps.bDeleteFlag;
|
||
}
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE && rslt!=DBIERR_RECNOTFOUND)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// BlanquearRegBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Blanquea el registro seleccionado.
|
||
//================================================================
|
||
|
||
DBIResult BlanquearRegBDE (dbiTabla* psT)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiInitRecord (psT->hCur,psT->pRecBuf);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// AnadirRegBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// A<>ade un nuevo registro en blanco en la tabla.
|
||
//================================================================
|
||
|
||
DBIResult AnadirRegBDE (dbiTabla* psT)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiInitRecord (psT->hCur,psT->pRecBuf);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiAppendRecord (psT->hCur,psT->pRecBuf);
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// LeerCampoBDE (dbiTabla* psT,int nInd,char *pszValor,bool *bVacio);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// nInd - Indice del campo que se quiere leer.
|
||
// szValor - Valor del campo leido. Opcional.
|
||
// nLon - sizeof (szValorCampo). Opcional.
|
||
// bVacio - TRUE, si campo vacio. Opcional.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Lee un campo de la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult LeerCampoBDE (dbiTabla* psT,int nInd,char *pszValor, bool *bVacio)
|
||
{
|
||
DBIResult rslt;
|
||
int nV,nLon;
|
||
|
||
nLon=psT->pFldArray[nInd-1].iLen;
|
||
memset (pszValor,0,nLon+1);
|
||
rslt = DbiGetField (psT->hCur,(unsigned short)nInd,psT->pRecBuf,(PByte)pszValor,nV);
|
||
if (rslt == DBIERR_NONE && bVacio)
|
||
*bVacio = (nV == 1);
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// LeerCampoNBDE (dbiTabla* psT,char* szNombre,char *pszValor,bool *bVacio);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// szCampo - Nombre del campo que se quiere leer.
|
||
// szValor - Valor del campo leido. Opcional.
|
||
// nLon - sizeof (szValorCampo). Opcional.
|
||
// bVacio - TRUE, si campo vacio. Opcional.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Lee un campo de la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult LeerCampoNBDE (dbiTabla* psT,char* szCampo,char *pszValor,bool *bVacio)
|
||
{
|
||
return (LeerCampoBDE (psT,IndCampo(psT,szCampo),pszValor,bVacio));
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// ModificarCampoBDE (dbiTabla* psT,int nInd,char *pszValor);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// nInd - Indice del campo que se quiere escribir.
|
||
// szValor - Valor del campo escrito. NULL si se quiere limpiar.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Modifica un campo en la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult ModificarCampoBDE (dbiTabla* psT,int nInd,char *pszValor)
|
||
{
|
||
DBIResult rslt;
|
||
int nLon;
|
||
char *sValor;
|
||
|
||
nLon=psT->pFldArray[nInd-1].iLen;
|
||
sValor=(char*)malloc(nLon);
|
||
memset (sValor,' ',nLon);
|
||
if(nLon>(int)strlen(pszValor))
|
||
strncpy (sValor,pszValor,strlen(pszValor));
|
||
else
|
||
strncpy (sValor,pszValor,nLon);
|
||
|
||
rslt = DbiPutField (psT->hCur,(unsigned short)nInd,psT->pRecBuf,(PByte)sValor);
|
||
if (rslt == DBIERR_NONE)
|
||
rslt = DbiModifyRecord (psT->hCur,psT->pRecBuf,TRUE);
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
free(sValor);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// ModificarCampoNBDE (dbiTabla* psT,char* szNombre,char* pszValor);
|
||
//
|
||
// Input: psT - Puntero a la tabla.
|
||
// szNombre - Nombre del campo que se quiere escribir.
|
||
// szValor - Valor del campo escrito. NULL si se quiere limpiar.
|
||
//
|
||
// Return: DBIResult
|
||
//
|
||
// Description:
|
||
// Modifica un campo en la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult ModificarCampoNBDE (dbiTabla* psT,char *pszNombre,char *pszValor)
|
||
{
|
||
return (ModificarCampoBDE (psT,IndCampo(psT,pszNombre),pszValor));
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// DuplicarRegBDE (dbiTabla* psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Duplica un registro
|
||
//================================================================
|
||
|
||
DBIResult DuplicarRegBDE (dbiTabla* psT)
|
||
{
|
||
DBIResult rslt;
|
||
char *psReg;
|
||
|
||
psReg = (char *) malloc (psT->curProps.iRecBufSize);
|
||
if (psT->pRecBuf)
|
||
{
|
||
memcpy (psReg,psT->pRecBuf,psT->curProps.iRecBufSize);
|
||
rslt = AnadirRegBDE (psT);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
memcpy (psT->pRecBuf,psReg,psT->curProps.iRecBufSize);
|
||
rslt = DbiModifyRecord (psT->hCur,psT->pRecBuf,TRUE);
|
||
}
|
||
free (psReg);
|
||
}
|
||
else
|
||
rslt = DBIERR_NOMEMORY;
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// EliminarBorradosTablaBDE (dbiTabla *psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Empaqueta la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult EliminarBorradosTablaBDE (dbiTabla *psT,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiPackTable(hBaseDatos,psT->hCur,NULL,NULL,TRUE);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// VaciarTablaBDE (dbiTabla *psT);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Vac<61>a la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult VaciarTablaBDE (dbiTabla *psT,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiEmptyTable(hBaseDatos,psT->hCur,NULL,NULL);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// ReindexarTablaBDE (dbiTabla *psT);
|
||
//
|
||
// Entrada: psT- Puntero a latabla
|
||
//
|
||
// Devuevle: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Reindexa la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult ReindexarTablaBDE (dbiTabla *psT)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiRegenIndexes(psT->hCur);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// CopiarTablaBDE (dbiTabla *psT,char *pszNomDestTable);
|
||
//
|
||
// Entrada: tabla
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Copia la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult CopiarTablaBDE (char *pszNomOrigTable,char *pszNomDestTable,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiCopyTable (hBaseDatos,TRUE,pszNomOrigTable,szDBASE,pszNomDestTable);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// RenombrarTablaBDE (char *pszNomOldTable,char *pszNomNewTable);
|
||
//
|
||
// Entrada: tabla
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Renombra la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult RenombrarTablaBDE (char *pszNomOldTable,char *pszNomNewTable,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiRenameTable (hBaseDatos,pszNomOldTable,szDBASE,pszNomNewTable);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// BorrarTablaBDE (char *pszNomTable);
|
||
//
|
||
// Entrada: tabla
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Renombra la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult BorrarTablaBDE (char *pszNomTable,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiDeleteTable (hBaseDatos,pszNomTable,szDBASE);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// CopiarEstruTablaBDE (dbiTabla *psT,char *pszNomDestTable);
|
||
//
|
||
// Entrada: tabla
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Genera una tabla con la estructura de la tabla indicada.
|
||
//================================================================
|
||
|
||
DBIResult CopiarEstruTablaBDE (dbiTabla *psT,char *pszNomDestTabla,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
CRTblDesc DescTabla;
|
||
pIDXDesc pIndArray;
|
||
|
||
pIndArray = (pIDXDesc) malloc (sizeof(IDXDesc) * psT->curProps.iIndexes);
|
||
if (pIndArray)
|
||
{
|
||
rslt = DbiGetIndexDescs (psT->hCur,pIndArray);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
memset (&DescTabla,0,sizeof(CRTblDesc));
|
||
strcpy (DescTabla.szTblName,pszNomDestTabla);
|
||
strcpy (DescTabla.szTblType,szDBASE);
|
||
|
||
DescTabla.iFldCount = psT->curProps.iFields;
|
||
DescTabla.pfldDesc = psT->pFldArray;
|
||
|
||
DescTabla.iIdxCount = psT->curProps.iIndexes;
|
||
DescTabla.pidxDesc = pIndArray;
|
||
|
||
rslt = DbiCreateTable (hBaseDatos,TRUE,DescTabla);
|
||
}
|
||
|
||
free (pIndArray);
|
||
}
|
||
else
|
||
rslt = DBIERR_NOMEMORY;
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// CopiarATextoBDE (dbiTabla* psT,char *pszNomText);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// pszNomText - Nombre fichero texto
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Copia una tabla a un fichero texto.
|
||
//================================================================
|
||
|
||
DBIResult CopiarATextoBDE (dbiTabla* psT,char *pszNomText,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
CRTblDesc DescTxt;
|
||
hDBICur hTxtCur;
|
||
pFLDDesc pTxtFld;
|
||
int NumReg = 0;
|
||
|
||
memset (&DescTxt,0,sizeof (CRTblDesc));
|
||
|
||
strcpy (DescTxt.szTblName,pszNomText);
|
||
strcpy (DescTxt.szTblType,szASCII);
|
||
|
||
rslt = DbiCreateTable (hBaseDatos,TRUE,DescTxt);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiOpenTable (hBaseDatos,pszNomText,"ASCIIDRV",NULL,NULL,0,dbiREADWRITE,
|
||
dbiOPENSHARED,xltFIELD,FALSE,NULL,hTxtCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
pTxtFld = (pFLDDesc) malloc (psT->curProps.iFields * sizeof(FLDDesc));
|
||
if (pTxtFld)
|
||
{
|
||
rslt = DbiTranslateRecordStructure (szDBASE,psT->curProps.iFields,psT->pFldArray,
|
||
szASCII,NULL,pTxtFld,0);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiSetFieldMap (hTxtCur,psT->curProps.iFields,pTxtFld);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiSetToBegin (psT->hCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiSetToBegin (hTxtCur);
|
||
if (rslt == DBIERR_NONE)
|
||
rslt = DbiBatchMove(NULL,psT->hCur,NULL,hTxtCur,batchAPPEND,
|
||
0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,
|
||
NULL,NULL,FALSE,FALSE,NumReg,TRUE);
|
||
}
|
||
}
|
||
}
|
||
free (pTxtFld);
|
||
}
|
||
else
|
||
rslt = DBIERR_NOMEMORY;
|
||
|
||
DbiCloseCursor (hTxtCur);
|
||
}
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// AnadirDesdeTextoBDE (dbiTabla* psT,char *pszNomText);
|
||
//
|
||
// Entrada: psT - Puntero a la tabla.
|
||
// pszNomText - Nombre fichero texto
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Copia a una tabla desde un fichero texto.
|
||
//================================================================
|
||
|
||
DBIResult AnadirDesdeTextoBDE (dbiTabla* psT,char *pszNomText,hDBIDb hBaseDatos)
|
||
{
|
||
DBIResult rslt;
|
||
hDBICur hTxtCur;
|
||
pFLDDesc pTxtFld;
|
||
int NumReg = 0;
|
||
|
||
rslt = DbiOpenTable (hBaseDatos,pszNomText,"ASCIIDRV",NULL,NULL,0,dbiREADWRITE,
|
||
dbiOPENSHARED,xltFIELD,FALSE,NULL,hTxtCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
pTxtFld = (pFLDDesc) malloc (psT->curProps.iFields * sizeof(FLDDesc));
|
||
if (pTxtFld)
|
||
{
|
||
rslt = DbiTranslateRecordStructure (szDBASE,psT->curProps.iFields,psT->pFldArray,
|
||
szASCII,NULL,pTxtFld,0);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiSetFieldMap (hTxtCur,psT->curProps.iFields,pTxtFld);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiSetToBegin (psT->hCur);
|
||
if (rslt == DBIERR_NONE)
|
||
{
|
||
rslt = DbiSetToBegin (hTxtCur);
|
||
if (rslt == DBIERR_NONE)
|
||
rslt = DbiBatchMove(NULL,hTxtCur,NULL,psT->hCur,batchAPPEND,
|
||
0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,
|
||
NULL,NULL,FALSE,FALSE,NumReg,TRUE);
|
||
}
|
||
}
|
||
}
|
||
free (pTxtFld);
|
||
}
|
||
else
|
||
rslt = DBIERR_NOMEMORY;
|
||
|
||
DbiCloseCursor (hTxtCur);
|
||
}
|
||
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// SelecReintBloqueoBDE (int nSegundos);
|
||
//
|
||
// Entrada: nSegundos - N<> de segundos de reintento
|
||
//
|
||
// Devuelve: DBIResult
|
||
//
|
||
// Descripcion:
|
||
// Actualiza el numero de segundos de reintento por bloqueo.
|
||
// No tiene aplicacion en las aperturas de tabla.
|
||
//================================================================
|
||
|
||
DBIResult SelecReintBloqueoBDE (int nSegundos)
|
||
{
|
||
DBIResult rslt;
|
||
|
||
rslt = DbiSetLockRetry ((unsigned short) nSegundos);
|
||
if(rslt != DBIERR_NONE)
|
||
DBIError (rslt);
|
||
|
||
return (rslt);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// void GenerarError(char *Error)
|
||
//
|
||
// Entrada: char *Error - Cadena del Error producido
|
||
//
|
||
// Descripcion:
|
||
// Genera Errores en el fichero de nombre a eleccion por el usuario
|
||
//
|
||
//================================================================
|
||
|
||
void GenerarError(char *Error)
|
||
{
|
||
FILE *fichero;
|
||
char szHora[DIM_HORA+1];
|
||
char szFecha[DIM_FECHA+1];
|
||
|
||
CapturarFechaHora(szFecha,szHora);
|
||
|
||
if(strcmp(FicheroError,""))
|
||
{
|
||
if( (fichero=fopen(FicheroError,"at"))!=NULL)
|
||
{
|
||
fputs(szFecha,fichero);
|
||
fputc(' ',fichero);
|
||
fputs(szHora,fichero);
|
||
fputc(' ',fichero);
|
||
fputs(Error,fichero);
|
||
fputc('\n',fichero);
|
||
fclose(fichero);
|
||
}
|
||
}
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// void CapturarFechaHora(char *pszFecha,char *pszHora)
|
||
//
|
||
// Entrada:
|
||
// char *pszFecha - Puntero a char para la Fecha
|
||
// char *pszHora - Puntero a char para la Hora
|
||
//
|
||
// Descripcion:
|
||
// Formatea la fecha y hora actual
|
||
//
|
||
//================================================================
|
||
|
||
void CapturarFechaHora(char *pszFecha,char *pszHora)
|
||
{
|
||
struct date sfecha;
|
||
struct time shora;
|
||
|
||
getdate(&sfecha);
|
||
sprintf(pszFecha,"%02d/%02d/%4d",sfecha.da_day,sfecha.da_mon,sfecha.da_year);
|
||
|
||
gettime(&shora);
|
||
sprintf(pszHora,"%02d:%02d:%02d",shora.ti_hour,shora.ti_min,shora.ti_sec);
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// bool ComprobarNomFichError(char *Nombre)
|
||
//
|
||
// Entrada:
|
||
// char *Nombre - Nombre del fichero de Error
|
||
//
|
||
// Devuelve:
|
||
// bool - Si es correcto true sino false
|
||
//
|
||
// Descripcion:
|
||
// Comprueba si el nombre del fichero de Error es correcto
|
||
//
|
||
//================================================================
|
||
|
||
bool ComprobarNomFichError(char *Nombre)
|
||
{
|
||
bool bcorrecto;
|
||
if (strlen(Nombre)<49)
|
||
{
|
||
strcpy(FicheroError,Nombre);
|
||
bcorrecto=true;
|
||
}
|
||
else
|
||
bcorrecto=false;
|
||
|
||
return bcorrecto;
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// char * ReservarMemoria(dbiTabla* psT,char *pszCampo)
|
||
//
|
||
// Entrada:
|
||
// dbiTabla* psT - Puntero a la tabla.
|
||
// char *pszCampo - Puntero al Campo.
|
||
//
|
||
// Devuelve:
|
||
// char * - Direccion de la zona de memoria reservada
|
||
//
|
||
// Descripcion:
|
||
// Reserva memoria a la variable con respecto al campo
|
||
//
|
||
//================================================================
|
||
|
||
char * ReservarMemoria(dbiTabla* psT,char *pszCampo)
|
||
{
|
||
int CantidadMemoria;
|
||
char *Memoria;
|
||
|
||
CantidadMemoria=ConseguirLongitud(psT,pszCampo);
|
||
if(CantidadMemoria)
|
||
{
|
||
//Reservamos memoria
|
||
Memoria=(char *)malloc(CantidadMemoria+1);
|
||
memset(Memoria,0,CantidadMemoria+1);
|
||
if(Memoria==NULL)
|
||
GenerarError("Error No hay memoria disponible");
|
||
}
|
||
else Memoria=NULL;
|
||
|
||
return Memoria;
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// void LiberarMemoria(char *Memoria)
|
||
//
|
||
// Entrada:
|
||
// char *Memoria - Variable a liberar.
|
||
//
|
||
// Descripcion:
|
||
// Libera memoria de la variable con respecto al campo
|
||
//
|
||
//================================================================
|
||
|
||
void LiberarMemoria(char *Memoria)
|
||
{
|
||
if(Memoria)
|
||
free(Memoria);
|
||
Memoria=NULL;
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// int ConseguirLongitud(dbiTabla* psT,char *pszCampo)
|
||
//
|
||
// Entrada:
|
||
// dbiTabla* psT - Puntero a la tabla.
|
||
// char *pszCampo - Puntero al Campo.
|
||
//
|
||
// Devuelve:
|
||
// int - Longitud del Campo
|
||
//
|
||
// Descripcion:
|
||
// Consigue la longitud del campo deseado
|
||
//
|
||
//================================================================
|
||
|
||
int ConseguirLongitud(dbiTabla* psT,char *pszCampo)
|
||
{
|
||
int nLon,indice;
|
||
|
||
//Inicializamos longitud
|
||
nLon=0;
|
||
//Buscamos el indice del campo
|
||
indice=IndCampo(psT,pszCampo);
|
||
if(indice)
|
||
{
|
||
//Miramos cuanto mide el campo
|
||
nLon=psT->pFldArray[indice-1].iLen;
|
||
}
|
||
|
||
return nLon;
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// void LeerArrayCampoBDE(dbiTabla *psT,char *pszCampo,char **pszsCampoN, BYTE byRango)
|
||
//
|
||
// Entrada:
|
||
// dbiTabla* psT - Puntero a la tabla.
|
||
// char *pszCampo - Puntero al Campo.
|
||
// char **pszsCampoN - Variable de Array[byRango]
|
||
// BYTE byRango - Numero del Array a[9] seria 9
|
||
//
|
||
// Descripcion:
|
||
// Lee un Array de campo
|
||
//
|
||
//================================================================
|
||
|
||
void LeerArrayCampoBDE(dbiTabla *psT,char *pszCampo,char **pszsCampoN, BYTE byRango)
|
||
{
|
||
int ni;
|
||
char *pszNombreCampo;
|
||
|
||
if(byRango<NUMERO_MAXIMO_ARRAY)
|
||
{
|
||
pszNombreCampo=(char *)malloc(strlen(pszCampo)+2);
|
||
//Leemos valores
|
||
for(ni=1;ni<=byRango;ni++)
|
||
{
|
||
strcpy(pszNombreCampo,pszCampo);
|
||
itoa(ni,pszNombreCampo+strlen(pszCampo),10);
|
||
LeerCampoNBDE(psT,pszNombreCampo,pszsCampoN[ni-1],NULL);
|
||
}
|
||
free(pszNombreCampo);
|
||
}
|
||
else
|
||
GenerarError("Error de programacion: Numero de Array fuera de Rango");
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// void EscribirArrayCampoBDE(dbiTabla *psT,char *pszCampo,char **pszsCampoN, BYTE byRango)
|
||
//
|
||
// Entrada:
|
||
// dbiTabla* psT - Puntero a la tabla.
|
||
// char *pszCampo - Puntero al Campo.
|
||
// char **pszsCampoN - Variable de Array[byRango]
|
||
// BYTE byRango - Numero del Array a[9] seria 9
|
||
//
|
||
// Descripcion:
|
||
// Escribe un Array de Campos
|
||
//
|
||
//================================================================
|
||
|
||
void EscribirArrayCampoBDE(dbiTabla *psT,char *pszCampo,char **pszsCampoN, BYTE byRango)
|
||
{
|
||
int ni;
|
||
char *pszNombreCampo;
|
||
|
||
if(byRango<NUMERO_MAXIMO_ARRAY)
|
||
{
|
||
pszNombreCampo=(char *)malloc(strlen(pszCampo)+2);
|
||
//Escribimos los valores
|
||
for(ni=1;ni<=byRango;ni++)
|
||
{
|
||
strcpy(pszNombreCampo,pszCampo);
|
||
itoa(ni,pszNombreCampo+strlen(pszCampo),10);
|
||
ModificarCampoNBDE(psT,pszNombreCampo,pszsCampoN[ni-1]);
|
||
}
|
||
free(pszNombreCampo);
|
||
}
|
||
else
|
||
GenerarError("Error de programacion: Numero de Array fuera de Rango");
|
||
}
|
||
|
||
//===============================================================
|
||
// Funcion:
|
||
// void CopiarCampo (dbiTabla *pTDestino,char *pszCampoDes,dbiTabla *pTOrigen,char *pszCampoOri)
|
||
//
|
||
// Entrada:
|
||
// dbiTabla *pTDestino - Puntero a la tabla de Destino.
|
||
// char *pszCampoDes - Puntero al Campo de Destino.
|
||
// dbiTabla *pTOrigen - Puntero a la tabla de Origen
|
||
// char *pszCampoOri - Puntero al Campo de Origen.
|
||
//
|
||
// Descripcion:
|
||
// Copia el campo de una tabla en otra
|
||
//
|
||
//================================================================
|
||
|
||
void CopiarCampo (dbiTabla *pTDestino,char *pszCampoDes,dbiTabla *pTOrigen,char *pszCampoOri)
|
||
{
|
||
char *szValor;
|
||
|
||
//Pedimos memoria para la variable
|
||
szValor=ReservarMemoria(pTOrigen,pszCampoOri);
|
||
|
||
//Leemos del Campo Origen
|
||
LeerCampoNBDE (pTOrigen,pszCampoOri,szValor,NULL);
|
||
|
||
//Escribimos en el Campo destino
|
||
ModificarCampoNBDE(pTDestino,pszCampoDes,szValor);
|
||
|
||
//Liberamos la variable
|
||
LiberarMemoria(szValor);
|
||
}
|