Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion IscDbc/JString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const char* JString::getString()
return (string) ? string : "";
}

JString::operator const char* ()
JString::operator const char* () const
{
/**************************************
*
Expand Down
2 changes: 1 addition & 1 deletion IscDbc/JString.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class JString

void Format (const char*, ...);
const char *getString();
operator const char*();
operator const char*() const;
JString& operator = (const char *string);
JString& operator = (const JString& string);
JString& operator+=(const char *string);
Expand Down
10 changes: 5 additions & 5 deletions IscDbc/SQLError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ SQLError::~SQLError () throw()

}

int SQLError::getSqlcode ()
int SQLError::getSqlcode () const
{
/**************************************
*
Expand All @@ -128,7 +128,7 @@ int SQLError::getSqlcode ()
return sqlcode;
}

int SQLError::getFbcode ()
int SQLError::getFbcode () const
{
/**************************************
*
Expand All @@ -144,7 +144,7 @@ int SQLError::getFbcode ()
return fbcode;
}

const char *SQLError::getText ()
const char *SQLError::getText () const
{
/**************************************
*
Expand All @@ -160,7 +160,7 @@ const char *SQLError::getText ()
return text;
}

SQLError::operator const char* ()
SQLError::operator const char* () const
{
/**************************************
*
Expand Down Expand Up @@ -193,7 +193,7 @@ SQLError::SQLError( int code, __int64 codefb, const char * txt, ...)
fbcode = (int) codefb;
}

const char* SQLError::getTrace()
const char* SQLError::getTrace() const
{
return stackTrace;
}
Expand Down
10 changes: 5 additions & 5 deletions IscDbc/SQLError.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ class SQLError : public SQLException
public:
virtual int release();
virtual void addRef();
virtual const char* getTrace();
virtual const char* getTrace() const;
SQLError (int sqlcode, __int64 fbcode, const char *text, ...);
SQLError (SqlCode sqlcode, const char *text, ...);
SQLError (Stream *trace, SqlCode code, const char *txt,...);
~SQLError() throw();

virtual int getFbcode ();
virtual int getSqlcode ();
virtual const char *getText();
virtual int getFbcode () const;
virtual int getSqlcode () const;
virtual const char *getText() const;

//void Delete();
operator const char*();
operator const char*() const;

int fbcode;
int sqlcode;
Expand Down
8 changes: 4 additions & 4 deletions IscDbc/SQLException.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class DllExport SQLException : public std::exception
public:
//virtual void addRef() = 0;
//virtual int release() = 0;
virtual int getFbcode () = 0;
virtual int getSqlcode () = 0;
virtual const char *getText() = 0;
virtual const char *getTrace() = 0;
virtual int getFbcode () const = 0;
virtual int getSqlcode () const = 0;
virtual const char *getText() const = 0;
virtual const char *getTrace() const = 0;
};

}; // end namespace IscDbcLibrary
Expand Down
112 changes: 76 additions & 36 deletions OdbcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,10 +1026,14 @@ SQLRETURN OdbcConnection::sqlNativeSql( SQLCHAR * inStatementText, SQLINTEGER te
outText = (const char *)tempNative;

}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
SQLException &exception = (SQLException&)ex;
postError( "HY000", exception );
postError("HY000", ex);
return SQL_ERROR;
}
catch (const std::exception &ex)
{
postError("HY000", ex);
return SQL_ERROR;
}

Expand Down Expand Up @@ -1125,20 +1129,28 @@ SQLRETURN OdbcConnection::sqlDisconnect()
if (connection->getTransactionPending())
return sqlReturn (SQL_ERROR, "25000", "Invalid transaction state");

auto handle_error = [&](const char* state, auto& ex) -> SQLRETURN
{
postError("01002", ex);
connection = NULL;
connected = false;
return SQL_SUCCESS_WITH_INFO;
};

try
{
connection->commit();
releaseObjects();
connection = NULL;
connected = false;
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
SQLException &exception = (SQLException&)ex;
postError ("01002", exception);
connection = NULL;
connected = false;
return SQL_SUCCESS_WITH_INFO;
return handle_error("01002", ex);
}
catch (const std::exception &ex)
{
return handle_error("01002", ex);
}

return sqlSuccess();
Expand Down Expand Up @@ -1632,6 +1644,21 @@ SQLRETURN OdbcConnection::connect(const char *sharedLibrary, const char * databa
{
Properties *properties = NULL;

// Shared rollback for both catch handlers below. `connection` may be
// NULL if createConnection() itself threw before assignment, so it has
// to be checked before close().
auto rollbackPartialConnect = [&]() {
if ( env->envShare )
env->envShare = NULL;
if ( properties )
properties->release();
if ( connection )
{
connection->close();
connection = NULL;
}
};

try
{
connection = createConnection();
Expand Down Expand Up @@ -1709,19 +1736,15 @@ SQLRETURN OdbcConnection::connect(const char *sharedLibrary, const char * databa
WcsToMbs = connection->getConnectionWcsToMbs();
MbsToWcs = connection->getConnectionMbsToWcs();
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
SQLException &exception = (SQLException&)ex;
if ( env->envShare )
env->envShare = NULL;

if ( properties )
properties->release();

connection->close();
connection = NULL;

return sqlReturn( SQL_ERROR, "08004", exception.getText(), exception.getSqlcode() );
rollbackPartialConnect();
return sqlReturn( SQL_ERROR, "08004", ex.getText(), ex.getSqlcode() );
}
catch (const std::exception &ex)
{
rollbackPartialConnect();
return sqlReturn( SQL_ERROR, "08004", ex.what(), 0 );
}

connected = true;
Expand All @@ -1746,10 +1769,14 @@ SQLRETURN OdbcConnection::sqlEndTran(int operation)
connection->rollbackAuto();
}
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
SQLException &exception = (SQLException&)ex;
postError ("S1000", exception);
postError ("S1000", ex);
return SQL_ERROR;
}
catch (const std::exception &ex)
{
postError ("S1000", ex);
return SQL_ERROR;
}

Expand All @@ -1764,10 +1791,14 @@ SQLRETURN OdbcConnection::sqlExecuteCreateDatabase(const char * sqlString)
{
connection->sqlExecuteCreateDatabase( sqlString );
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
postError( "HY000", ex );
return SQL_ERROR;
}
catch (const std::exception &ex)
{
SQLException &exception = (SQLException&)ex;
postError( "HY000", exception );
postError( "HY000", ex );
return SQL_ERROR;
}

Expand Down Expand Up @@ -2178,10 +2209,13 @@ void OdbcConnection::initUserEvents( PODBC_EVENTS_BLOCK_INFO infoEvents )
userEventsInterfase->events = infoEvents->events;
userEventsInterfase->count = infoEvents->count;
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
SQLException &exception = (SQLException&)ex;
postError( "HY000", exception );
postError( "HY000", ex );
}
catch (const std::exception &ex)
{
postError( "HY000", ex );
}
}

Expand All @@ -2199,10 +2233,13 @@ void OdbcConnection::updateResultEvents( char *updated )
nextNameEvent->changed = userEvents->isChanged( i );
}
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
postError( "HY000", ex );
}
catch (const std::exception &ex)
{
SQLException &exception = (SQLException&)ex;
postError( "HY000", exception );
postError( "HY000", ex );
}
}

Expand All @@ -2212,10 +2249,13 @@ void OdbcConnection::requeueEvents()
{
userEvents->queEvents( userEventsInterfase );
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
postError( "HY000", ex );
}
catch (const std::exception &ex)
{
SQLException &exception = (SQLException&)ex;
postError( "HY000", exception );
postError( "HY000", ex );
}
}

Expand Down
39 changes: 24 additions & 15 deletions OdbcDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,14 @@ SQLRETURN OdbcDesc::sqlGetDescField(int recNumber, int fieldId, SQLPOINTER ptr,
return returnStringInfo (ptr, bufferLength, lengthPtr, (char*)string);

}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
SQLException &exception = (SQLException&)ex;
postError ("HY000", exception);
postError ("HY000", ex);
return SQL_ERROR;
}
catch (const std::exception &ex)
{
postError ("HY000", ex);
return SQL_ERROR;
}

Expand Down Expand Up @@ -1216,10 +1220,14 @@ SQLRETURN OdbcDesc::sqlGetDescRec( SQLSMALLINT recNumber,
*scalePtr = record->scale;
*nullablePtr = record->nullable;
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
postError ("HY000", ex);
return SQL_ERROR;
}
catch (const std::exception &ex)
{
SQLException &exception = (SQLException&)ex;
postError ("HY000", exception);
postError ("HY000", ex);
return SQL_ERROR;
}

Expand All @@ -1245,13 +1253,10 @@ SQLRETURN OdbcDesc::sqlSetDescRec( SQLSMALLINT recNumber,
if ( bDefined == false )
return sqlReturn (SQL_ERROR, "HY091", "Invalid descriptor field identifier");

if (recNumber)
{
if ( recNumber > headCount )
return sqlReturn (SQL_NO_DATA_FOUND, "HY021", "Inconsistent descriptor information");
if ( recNumber > headCount )
return sqlReturn (SQL_NO_DATA_FOUND, "HY021", "Inconsistent descriptor information");

record = getDescRecord (recNumber);
}
record = getDescRecord (recNumber);

try
{
Expand All @@ -1264,10 +1269,14 @@ SQLRETURN OdbcDesc::sqlSetDescRec( SQLSMALLINT recNumber,
record->octetLengthPtr = stringLengthPtr;
record->indicatorPtr = indicatorPtr;
}
catch ( std::exception &ex )
catch (const SQLException &ex)
{
postError ("HY000", ex);
return SQL_ERROR;
}
catch (const std::exception &ex)
{
SQLException &exception = (SQLException&)ex;
postError ("HY000", exception);
postError ("HY000", ex);
return SQL_ERROR;
}

Expand Down
Loading