|
|
Comments and Discussions
|
|
 |

|
Before running the exe, added environment variable path "C:\BDE32", but it was failing at DBInit,please reply
|
|
|
|

|
I've got an error "Trying to load multiple IDAPIxx.DLL" when running this class with another process using the BDE. I was able to solve this problem if I placed my program in the BDE installation folder (in my case, it is "C:\Program Files\Common Files\Borland Shared\BDE", but it could be different.) I understand that this is not the best solution but this is all I could come up with... I welcome any suggestions.
|
|
|
|

|
ur code help me so. i used it easy and with no problem.thank u very much.
|
|
|
|

|
I am trying to open a table that is password protected. I have adjusted the code in CBdeDatabase::OpenDatabase
to allow for a password.
I have added the password value in the function DbiOpenDatabase as parameter 5.
What am I missing?
Where can I find the documentation of the function
DbiOpenDatabase?
|
|
|
|

|
Use DbiOpenDatabase without password. If the database opend successfully use DbiAddPassword(pszPassword) to set the password.
|
|
|
|

|
My table has a field with data type NUMBER(5,0)in ORACLE but BDE convert it to FloatField with precision 15, so I have problem about programming with C++Builder.
|
|
|
|

|
struct IDAPI_CALLS_FUNCTION
{
DBIResult (DBIFN *pfnDbiInitFn)(UINT16,pDBIEnv);
DBIResult (DBIFN *pfnDbiGetBookMark)(hDBICur,pCHAR);
DBIResult (DBIFN *pfnDbiCfgGetRecord)(hDBICfg hCfg,pCHAR pszCfgPath,pUINT16 pnFields,pFLDDesc pfldDesc,pBYTE pRecBuf);
DBIResult (DBIFN *pfnDbiCfgAddRecord)(hDBICfg hCfg,pCHAR pszCfgPath,UINT16 nFields,pFLDDesc pfldDesc,pBYTE pRecBuf);
DBIResult (DBIFN *pfnDbiCfgModifyRecord)(hDBICfg hCfg,pCHAR pszCfgPath,UINT16 nFields,pFLDDesc pfldDesc,pBYTE pRecBuf);
};
static const LPCSTR IDAPI_NAME_FUNCTION[] =
{
"DbiInitFn",
"DbiGetBookMark",
"DbiCfgGetRecord",
"DbiCfgAddRecord",
"DbiCfgModifyRecord"
};
static HINSTANCE IDAPI_INSTANCE = 0;
static IDAPI_CALLS_FUNCTION IDAPI_CALLS;
#if defined(DbiInit)
#undef DbiInit
#endif
#define DbiInit(p) IDAPI_CALLS.pfnDbiInitFn(DBIINTFVER,(p))
BOOL FreeIdapi()
{
if (!IDAPI_INSTANCE) return 0;
return FreeLibrary(IDAPI_INSTANCE);
}
BOOL LoadIdapi()
{
if (IDAPI_INSTANCE) return 1;
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Borland\\Database Engine",0,
KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) return 0;
int i;
char string[260];
DWORD type, size = sizeof(string);
LONG Res = RegQueryValueEx(hKey,"DLLPATH",NULL,&type,(LPBYTE)string,&size);
RegCloseKey(hKey);
if (Res != ERROR_SUCCESS || type != REG_SZ) return 0;
i = lstrlen(string);
if (i <= 0 || i >= 248) return 0;
if (string[i-1]!='\\') string[i++] = '\\';
lstrcpy(&string[i],"IDAPI32.DLL");
IDAPI_INSTANCE = LoadLibrary(string);
if (!IDAPI_INSTANCE) return 0;
FARPROC* lpfp = (FARPROC*)&IDAPI_CALLS;
for(i = 0; i < sizeof(IDAPI_CALLS_FUNCTION) / sizeof(FARPROC); i ++)
{
lpfp[i] = GetProcAddress(IDAPI_INSTANCE,IDAPI_NAME_FUNCTION[i]);
if (lpfp[i] == NULL)
{
FreeIdapi();
return 0;
}
}
return 1;
}
|
|
|
|

|
Hey Friends
I want to execute an SQL Statement and get the resultset to use it.Can someone sugget a way with some sample code if possible.
|
|
|
|

|
If you use GetFieldAsString to receive a big BLOB field, you may get an error! Now I have modified the code, see below:
CString CBdeDatabase::GetFieldAsString(UINT16 nFieldNumber, BOOL* pbBlank)
{
// Throw an exception if database is in Edit mode
if (!CheckValidCursor("Failed to get field value.")) return "";
if (!CheckNotEditMode("Failed to get field value.")) return "";
DBIResult dbiResult = DBIERR_NONE;
CString strValue;
CString strError;
CURProps curProps; // Table Properties
pFLDDesc pFldDesc = NULL; // field information
pBYTE pRecBuf = NULL; // Record Buffer
int nBdeExError = 0;
// get the cursor properties for the table
dbiResult = DbiGetCursorProps(m_hCursor, &curProps);
if (dbiResult != DBIERR_NONE)
{
strError.Format("Failed to get cursor properties.");
throw new CBdeException(dbiResult, m_szTableName, m_szDatabaseName, strError);
return "";
}
// make sure the field number is valid
if (nFieldNumber < 1 || nFieldNumber > curProps.iFields)
{
strError.Format("Invalid field index %d. Valid numbers are between 1 and %d.",
nFieldNumber, curProps.iFields);
throw new CBdeException(DBIERR_NONE, BDEEXERR_INVALIDFIELDINDEX,
m_szTableName, m_szDatabaseName, strError);
return "";
}
// allocate memory for the field descriptors
pFldDesc = (pFLDDesc)malloc(curProps.iFields * sizeof(FLDDesc));
if (pFldDesc == NULL)
{
// Throw exception for DBIERR_NOMEMORY
throw new CBdeException(DBIERR_NOMEMORY);
return "";
}
dbiResult = DbiGetFieldDescs(m_hCursor, pFldDesc);
if (dbiResult != DBIERR_NONE)
{
free(pFldDesc);
strError.Format("Failed to retrieve field information.");
throw new CBdeException(dbiResult, m_szTableName, m_szDatabaseName, strError);
return "";
}
// save the size and type of the field
UINT16 nSize = pFldDesc[nFieldNumber-1].iLen;
UINT16 nFieldType = pFldDesc[nFieldNumber-1].iFldType;
UINT16 nFieldSubType = pFldDesc[nFieldNumber-1].iSubType;
UINT16 nUnits = pFldDesc[nFieldNumber-1].iUnits2;
free(pFldDesc); // clean up the field descriptor
pFldDesc = NULL;
// allocate the record buffer for the table
pRecBuf = (pBYTE) malloc(curProps.iRecBufSize * sizeof(BYTE));
if (pRecBuf == NULL)
{
strError.Format("Insufficient memory to get field number %d.", nFieldNumber);
throw new CBdeException(DBIERR_NOMEMORY, m_szTableName, m_szDatabaseName, strError);
return "";
}
// fill the record buffer with information
dbiResult = DbiGetRecord(m_hCursor, dbiNOLOCK, pRecBuf, NULL);
if (dbiResult != DBIERR_NONE)
{
free(pRecBuf);
strError.Format("Failed to get record information.");
throw new CBdeException(dbiResult, m_szTableName, m_szDatabaseName, strError);
return "";
}
// allocate memory for the string buffer to recieve data
pBYTE pDestBuf = NULL;
// if field type is BLOB, then size is get by call DbiGetBlobSize
if (nFieldType != fldBLOB)
{
pDestBuf = (pBYTE)malloc(nSize * sizeof(BYTE));
memset(pDestBuf, 0, nSize * sizeof(BYTE));
if (pDestBuf == NULL)
{
// Throw memory exception here
free(pRecBuf);
strError.Format("Failed to get record information.");
throw new CBdeException(DBIERR_NOMEMORY, m_szTableName, m_szDatabaseName, strError);
return "";
}
}
// get the actual field value
switch (nFieldType)
{
case fldBYTES: // Bytes
case fldZSTRING: // String
{
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)pDestBuf, pbBlank);
strValue.Format("%s", (char*)pDestBuf);
break;
}
case fldFLOAT:
{
double f;
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)&f, pbBlank);
if (*pbBlank == FALSE)
{
if (nFieldSubType == fldstMONEY)
{
strValue.Format("$%.2lf", f);
}
else
{
strValue.Format("%g", f);
}
}
break;
}
case fldBCD:
{
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf,
(pBYTE)pDestBuf, pbBlank);
if (*pbBlank == FALSE)
{
double lfFloat;
DbiBcdToFloat((FMTBcd *)pDestBuf, &lfFloat);
strValue.Format("%.*lf", nUnits, lfFloat);
}
break;
}
case fldDATE:
{
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf,
(pBYTE)pDestBuf, pbBlank);
if (*pbBlank == FALSE)
{
// Here is a difficult situation...
// dates are returned as 4 bytes, but in the 32-bit world
// the DATE type is 8 bytes. Typcasting directly to DATE
// does not work. We have to type cast to 32 bit int, then
// to 64-bit int, and then to DATE
INT32 n32 = (*(INT32 *)pDestBuf);
strValue = FormatDate(n32);
}
break;
}
case fldTIME:
{
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf,
(pBYTE)pDestBuf, pbBlank);
if (*pbBlank == FALSE)
{
strValue = FormatTime(*(TIME *)pDestBuf);
}
break;
}
case fldTIMESTAMP:
{
// size of timestamp is 8
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf,
(pBYTE)pDestBuf, pbBlank);
if (*pbBlank == FALSE)
{
TIMESTAMP dt = *(TIMESTAMP*)pDestBuf;
strValue = FormatTimeStamp(dt);
}
break;
}
case fldINT16:
{
INT16 n;
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)&n, pbBlank);
if (*pbBlank == FALSE)
{
strValue.Format("%d", n);
}
break;
}
case fldUINT16:
{
UINT16 n;
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)&n, pbBlank);
if (*pbBlank == FALSE)
{
strValue.Format("%d", n);
}
break;
}
case fldINT32:
{
INT32 n;
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)&n, pbBlank);
if (*pbBlank == FALSE)
{
strValue.Format("%d", n);
}
break;
}
case fldUINT32:
{
UINT32 n;
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)&n, pbBlank);
if (*pbBlank == FALSE)
{
strValue.Format("%d", n);
}
break;
}
case fldBOOL:
{
dbiResult = DbiGetField(m_hCursor, nFieldNumber, pRecBuf, (pBYTE)pDestBuf, pbBlank);
if (*pbBlank == FALSE)
{
if (*(BYTE*)pDestBuf == 0) strValue = "FALSE";
else strValue = "TRUE";
}
break;
}
case fldBLOB: // NOTE: This does not work on dBase files.
{
if (nFieldSubType == fldstMEMO)
{
UINT32 ulBlobSize; // Size of the BLOB
ASSERT(pDestBuf == NULL);
// Open the blob
dbiResult = DbiOpenBlob(m_hCursor, pRecBuf, nFieldNumber, dbiREADONLY);
if (dbiResult != DBIERR_NONE) break;
// Determine the size of the BLOB.
dbiResult = DbiGetBlobSize(m_hCursor, pRecBuf, nFieldNumber, &ulBlobSize);
if (dbiResult != DBIERR_NONE) break;
// This is modified by Roseking
// Alloc the memory for BLOB field
pDestBuf = (pBYTE)malloc(ulBlobSize * sizeof(BYTE) + 1);
memset(pDestBuf, 0, ulBlobSize * sizeof(BYTE));
if (pDestBuf == NULL)
break;
// Get the BLOB from the table.
dbiResult = DbiGetBlob(m_hCursor, pRecBuf, nFieldNumber, 0,
ulBlobSize, (pBYTE)pDestBuf, &ulBlobSize);
pDestBuf[ulBlobSize] = '\0';
strValue.Format("%s", pDestBuf);
DbiFreeBlob(m_hCursor, pRecBuf, nFieldNumber);
if (dbiResult != DBIERR_NONE) break;
}
else
{
// Handle non-memo formats here
nBdeExError = BDEEXERR_UNSUPPORTEDBLOBTYPE;
}
break;
}
default:
{
nBdeExError = BDEEXERR_UNSUPPORTEDFIELDTYPE;
break;
}
} // end of swtich
// process the final error codes
if (dbiResult != DBIERR_NONE || nBdeExError != 0)
{
// Throw exception here
strError.Format("Failed to retrieve data for field %d.",
nFieldNumber);
free(pRecBuf);
free(pDestBuf);
throw new CBdeException(dbiResult, nBdeExError, m_szTableName,
m_szDatabaseName, strError);
return "";
}
free(pRecBuf);
free(pDestBuf);
return strValue;
}
|
|
|
|

|
When I open another BDE app,the demo doesn't work!
It throw error say "Try to load multiple IDAPIxx.DLL"
why?
and only open the demo ,it does.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
| Type | Article |
| Licence | |
| First Posted | 17 Nov 1999 |
| Views | 162,009 |
| Bookmarked | 41 times |
|
|