[freetds] Problem connecting to SQL server on linux

Jeff Dahl jddahl at micron.com
Mon Sep 25 15:46:12 EDT 2006


Frederik Teerlinck wrote:
> Isn't there a way to get more information back then just 'SQL_ERROR'?
>   
Here's my SQLException class:

    #ifndef SQLEXCEPTION_H
    #define SQLEXCEPTION_H
    #include <string>
    #include <stdexcept>
    #include "sql.h"

    #define MAX_MESSAGE_LEN 512

    class SQLException : public exception
    {
     public:
      SQLException( std::string = "" );
      SQLException( SQLSMALLINT, SQLHANDLE );
      ~SQLException( ) throw( );
      const char *what( ) const throw( );

     protected:
      std::string message;
    };
    #endif


    //  sqlexception.cpp

    #include "sqlexception.h"

    SQLException::SQLException( std::string m )
    {
      message = ( "SQLException: " + m );
    }

    SQLException::SQLException( SQLSMALLINT handleType, SQLHANDLE handle )
    {
      int i = 1;
      short int msgLen;
      unsigned char msg[MAX_MESSAGE_LEN];
      SQLRETURN ret;

      while(( ret = SQLGetDiagField( handleType, handle, i,
    SQL_DIAG_MESSAGE_TEXT, msg, MAX_MESSAGE_LEN, &msgLen )) != SQL_NO_DATA )
        {
          if( i > 1 )
        {
          message += "\n\t";
        }
          message += (std::string)"SQLException: " + (char *)msg;
          i++;
        }
    }

    SQLException::~SQLException( ) throw( )
    {

    }

    const char *SQLException::what( ) const throw( )
    {
      return message.c_str( );
    }

HTH






More information about the FreeTDS mailing list