Microsoft KB Archive/105101: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 68: Line 68:
     char near *string;
     char near *string;


     dbfcmd (dbproc, "%s", string);
     dbfcmd (dbproc, "%s", string);


                         </pre></li>
                         </pre></li>
Line 79: Line 79:
     char far very_large_string[1500];
     char far very_large_string[1500];


     dbfcmd (dbproc, &quot;%s&quot;, very_large_string);
     dbfcmd (dbproc, "%s", very_large_string);


                         </pre></li></ol>
                         </pre></li></ol>
Line 106: Line 106:
     char far *string;
     char far *string;


     dbfcmd (dbproc, &quot;%s&quot;, string);
     dbfcmd (dbproc, "%s", string);


                         </pre></li>
                         </pre></li>

Latest revision as of 08:44, 20 July 2020

Knowledge Base


PRB: Common Problems Using dbfcmd

Article ID: 105101

Article Last Modified on 3/14/2005



APPLIES TO

  • Microsoft SQL Server 4.21a Standard Edition
  • Microsoft SQL Server 6.5 Standard Edition



This article was previously published under Q105101

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:

  1. 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);
    
                            
  2. 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:

  1. 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:

    1. Medium model DB-Library for MS-DOS requires char near *.
    2. Large model DB-Library for MS-DOS, DB-Library for Windows, and DB-Library for OS/2 require char far *.
    3. 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);
    
                            
  2. 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);
    
                            



Additional query words: 4.20.00 crash hang GP-Fault dblib

Keywords: kbprogramming KB105101