The information in this article applies to:
- Microsoft SQL Server Programmer's Toolkit, version 4.2
SYMPTOMS
A DB-Library application fails when calling dbfcmd, or dbfcmd does not
work as expected.
CAUSE
Two common situations are often the cause of dbfcmd problems:
- The dbfcmd function takes a variable number of parameters in
params..., as can be seen be examining the dbfcmd function prototype
in SQLDB.H:
extern RETCODE SQLAPI dbfcmd(DBPROCESS *, CHAR *, ...);
The lack of a complete function prototype means that a C/C++ compiler
cannot perform any automatic conversion on the params... values before
passing them to dbfcmd.
Passing params... variables that do not match the types and sizes
specified in the cmdstring format string can cause problems. For
example, DB-Library requires far pointers to strings when %s is used,
so the following code is incorrect:
DBPROCESS *dbproc;
char near *string;
dbfcmd (dbproc, "%s", string);
- As documented under the Limitations section of dbfcmd in the
Programmer's Reference for C, dbfcmd picks the maximum of 1024 and the
string length of cmdstring * 2 to allocate dynamic working buffer
space.
Passing params... values that are very large in comparison to the size
of cmdstring can cause problems. For example, the following code is
incorrect:
DBPROCESS *dbproc;
char far very_large_string[1500];
dbfcmd (dbproc, "%s", very_large_string);
WORKAROUND
The above situations can be resolved as follows:
- The application must ensure that the params... variable types and
sizes match those specified in the cmdstring format string. In
particular when %s is used:
a. Medium model DB-Library for MS-DOS requires char near *.
b. Large model DB-Library for MS-DOS, DB-Library for Windows, and
DB-Library for OS/2 require char far *.
c. DB-Library for Windows NT requires a char *.
For example, the following DB-Library for Windows code is correct:
DBPROCESS *dbproc;
char far *string;
dbfcmd (dbproc, "%s", string);
- If the params... values are very large in comparison to the size
of cmdstring, simply use dbcmd to add these large values.
For example, the following code is correct:
DBPROCESS *dbproc;
char far very_large_string[1500];
dbcmd (dbproc, very_large_string);
|