-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/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; +} |