-rw-r--r-- | src/util/check_error.c | 13 | ||||
-rw-r--r-- | src/util/sqlinfoprint.c | 73 | ||||
-rw-r--r-- | src/util/sqlinfoprint.h | 15 |
3 files changed, 100 insertions, 1 deletions
diff --git a/src/util/check_error.c b/src/util/check_error.c index dbe5b8f..cd00439 100644 --- a/src/util/check_error.c +++ b/src/util/check_error.c @@ -1,10 +1,16 @@ #include <GL/glut.h> #include <error.h> #include <errno.h> +#include "sqlinfoprint.h" +extern struct sqlca sqlca; void -check_error (const char *filename, unsigned int linenum) +check_error (const char *filename, const unsigned int linenum) { + + /* + * Check for an error from the OpenGL API. + */ GLenum errCode = glGetError (); if (errCode != GL_NO_ERROR) { @@ -13,5 +19,10 @@ check_error (const char *filename, unsigned int linenum) "OpenGL Error %s", errString); } + /* + * Check for an error from the Database API. + */ + sqlinfoprint ("DB Error", &sqlca, filename, linenum); + return; } diff --git a/src/util/sqlinfoprint.c b/src/util/sqlinfoprint.c new file mode 100644 index 0000000..8e0ae07 --- a/dev/null +++ b/src/util/sqlinfoprint.c @@ -0,0 +1,73 @@ +#include "sqlinfoprint.h" +#include <sql.h> +#include <string.h> +#include <stdio.h> + +int +sqlinfoprint (char *appMsg, struct sqlca *pSqlca, + const char *file, const unsigned int line) +{ + int rc = 0; + char sqlInfo[1024]; + char sqlInfoToken[1024]; + char sqlstateMsg[1024]; + char errorMsg[1024]; + + if (pSqlca->sqlcode != 0 && pSqlca->sqlcode != 100) + { + strcpy (sqlInfo, ""); + if (pSqlca->sqlcode < 0) + { + sprintf (sqlInfoToken, "\n---- error report ----\n"); + strcat (sqlInfo, sqlInfoToken); + } + else + { + sprintf (sqlInfoToken, "\n---- warning report ----\n"); + strcat (sqlInfo, sqlInfoToken); + } + + sprintf (sqlInfoToken, " app. message = %s\n", appMsg); + strcat (sqlInfo, sqlInfoToken); + sprintf (sqlInfoToken, " line = %i\n", line); + strcat (sqlInfo, sqlInfoToken); + sprintf (sqlInfoToken, " file = %s\n", file); + strcat (sqlInfo, sqlInfoToken); + sprintf (sqlInfoToken, " SQLCODE = %li\n", pSqlca->sqlcode); + strcat (sqlInfo, sqlInfoToken); + /* get error message */ + rc = sqlaintp (errorMsg, 1024, 80, pSqlca); + /* return code is the length of the errorMsg string */ + if (rc > 0) + { + sprintf (sqlInfoToken, " %s\n", errorMsg); + strcat (sqlInfo, sqlInfoToken); + } + + /* get SQLSTATE message */ + rc = sqlogstt (sqlstateMsg, 1024, 80, pSqlca->sqlstate); + if (rc == 0) + { + sprintf (sqlInfoToken, "%s", sqlstateMsg); + strcat (sqlInfo, sqlInfoToken); + } + + if (pSqlca->sqlcode < 0) + { + sprintf (sqlInfoToken, "--- end error report ---\n"); + strcat (sqlInfo, sqlInfoToken); + printf ("%s", sqlInfo); + return 1; + } + else + { + sprintf (sqlInfoToken, "-- - end warning report-- - \n "); + strcat (sqlInfo, sqlInfoToken); + printf ("%s", sqlInfo); + return 0; + } + + } + + return 0; +} diff --git a/src/util/sqlinfoprint.h b/src/util/sqlinfoprint.h new file mode 100644 index 0000000..984694b --- a/dev/null +++ b/src/util/sqlinfoprint.h @@ -0,0 +1,15 @@ +#ifndef SQLINFOPRINT_H +#define SQLINFOPRINT_H + +#include "sqlca.h" + +/* + * Report SQL error messages. Based on code from: + * http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.apdv.embed.doc/doc/c0005779.html + */ +int sqlinfoprint (char *appMsg, + struct sqlca *pSqlca, + const char *file, + const unsigned int line); + +#endif // SQLINFOPRINT_H |