Skip to Content.
Sympa Menu

freetds - Re: [freetds] Problem connecting to SQL server on linux

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Jeff Dahl <jddahl AT micron.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Problem connecting to SQL server on linux
  • Date: Mon, 25 Sep 2006 13:46:12 -0600

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







Archive powered by MHonArc 2.6.24.

Top of Page