[unixODBC-support] driver logging

Eric Sharkey sharkey at netrics.com
Tue Mar 1 21:10:49 GMT 2005


> the start of dm_log_write contains
> 
>     if ( !log_info.log_flag && !ODBCSharedTraceFlag )
>         return;
> 
> So if logging is off there is no call to sprintf.

I'm talking about driver logging, not driver manager logging.

If you look at, for example, SQLConnect.c in unixODBC/Drivers/template:

  [copyright notice, Peter Harvey, LGPL, yada yada yada ]

  #include "driver.h"

  SQLRETURN SQLConnect(	SQLHDBC        hDrvDbc,
						SQLCHAR        *szDataSource,
						SQLSMALLINT    nDataSourceLength,
						SQLCHAR        *szUID,
						SQLSMALLINT    nUIDLength,
						SQLCHAR        *szPWD,
						SQLSMALLINT    nPWDLength
                          )
  {
	HDRVDBC 	hDbc	= (HDRVDBC)hDrvDbc;
    char    	szDATABASE[INI_MAX_PROPERTY_VALUE+1];
    char    	szHOST[INI_MAX_PROPERTY_VALUE+1];
    char    	szPORT[INI_MAX_PROPERTY_VALUE+1];
    char    	szFLAG[INI_MAX_PROPERTY_VALUE+1];

    /* SANITY CHECKS */
    if( SQL_NULL_HDBC == hDbc )
		return SQL_INVALID_HANDLE;

	sprintf((char*) hDbc->szSqlMsg, "hDbc=$%08lX 3zDataSource=(%s)", hDbc, szDataSource );
	logPushMsg( hDbc->hLog, __FILE__, __FILE__, __LINE__, LOG_WARNING, LOG_WARNING,(char*) hDbc->szSqlMsg );


The sprintf is done unconditionally.

If logPushMsg took variable arguments, the last two lines could look like :

	logPushMsg( hDbc->hLog, __FILE__, __FILE__, __LINE__, LOG_WARNING, LOG_WARNING,
                    "hDbc=$%08lX 3zDataSource=(%s)",hDbc, szDataSource );

And then logPushMsg() could be a noop if logging is not on.

Eric



More information about the unixODBC-support mailing list