summaryrefslogtreecommitdiffstats
Unidiff
-rw-r--r--src/util/check_error.c13
-rw-r--r--src/util/sqlinfoprint.c73
-rw-r--r--src/util/sqlinfoprint.h15
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 @@
1#include <GL/glut.h>1#include <GL/glut.h>
2#include <error.h>2#include <error.h>
3#include <errno.h>3#include <errno.h>
4#include "sqlinfoprint.h"
5extern struct sqlca sqlca;
46
5void7void
6check_error (const char *filename, unsigned int linenum)8check_error (const char *filename, const unsigned int linenum)
7{9{
10
11 /*
12 * Check for an error from the OpenGL API.
13 */
8 GLenum errCode = glGetError ();14 GLenum errCode = glGetError ();
9 if (errCode != GL_NO_ERROR)15 if (errCode != GL_NO_ERROR)
10 {16 {
@@ -13,5 +19,10 @@ check_error (const char *filename, unsigned int linenum)
13 "OpenGL Error %s", errString);19 "OpenGL Error %s", errString);
14 }20 }
1521
22 /*
23 * Check for an error from the Database API.
24 */
25 sqlinfoprint ("DB Error", &sqlca, filename, linenum);
26
16 return;27 return;
17}28}
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 @@
1#include "sqlinfoprint.h"
2#include <sql.h>
3#include <string.h>
4#include <stdio.h>
5
6int
7sqlinfoprint (char *appMsg, struct sqlca *pSqlca,
8 const char *file, const unsigned int line)
9{
10 int rc = 0;
11 char sqlInfo[1024];
12 char sqlInfoToken[1024];
13 char sqlstateMsg[1024];
14 char errorMsg[1024];
15
16 if (pSqlca->sqlcode != 0 && pSqlca->sqlcode != 100)
17 {
18 strcpy (sqlInfo, "");
19 if (pSqlca->sqlcode < 0)
20 {
21 sprintf (sqlInfoToken, "\n---- error report ----\n");
22 strcat (sqlInfo, sqlInfoToken);
23 }
24 else
25 {
26 sprintf (sqlInfoToken, "\n---- warning report ----\n");
27 strcat (sqlInfo, sqlInfoToken);
28 }
29
30 sprintf (sqlInfoToken, " app. message = %s\n", appMsg);
31 strcat (sqlInfo, sqlInfoToken);
32 sprintf (sqlInfoToken, " line = %i\n", line);
33 strcat (sqlInfo, sqlInfoToken);
34 sprintf (sqlInfoToken, " file = %s\n", file);
35 strcat (sqlInfo, sqlInfoToken);
36 sprintf (sqlInfoToken, " SQLCODE = %li\n", pSqlca->sqlcode);
37 strcat (sqlInfo, sqlInfoToken);
38 /* get error message */
39 rc = sqlaintp (errorMsg, 1024, 80, pSqlca);
40 /* return code is the length of the errorMsg string */
41 if (rc > 0)
42 {
43 sprintf (sqlInfoToken, " %s\n", errorMsg);
44 strcat (sqlInfo, sqlInfoToken);
45 }
46
47 /* get SQLSTATE message */
48 rc = sqlogstt (sqlstateMsg, 1024, 80, pSqlca->sqlstate);
49 if (rc == 0)
50 {
51 sprintf (sqlInfoToken, "%s", sqlstateMsg);
52 strcat (sqlInfo, sqlInfoToken);
53 }
54
55 if (pSqlca->sqlcode < 0)
56 {
57 sprintf (sqlInfoToken, "--- end error report ---\n");
58 strcat (sqlInfo, sqlInfoToken);
59 printf ("%s", sqlInfo);
60 return 1;
61 }
62 else
63 {
64 sprintf (sqlInfoToken, "-- - end warning report-- - \n ");
65 strcat (sqlInfo, sqlInfoToken);
66 printf ("%s", sqlInfo);
67 return 0;
68 }
69
70 }
71
72 return 0;
73}
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 @@
1#ifndef SQLINFOPRINT_H
2#define SQLINFOPRINT_H
3
4#include "sqlca.h"
5
6/*
7 * Report SQL error messages. Based on code from:
8 * http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.apdv.embed.doc/doc/c0005779.html
9 */
10int sqlinfoprint (char *appMsg,
11 struct sqlca *pSqlca,
12 const char *file,
13 const unsigned int line);
14
15#endif // SQLINFOPRINT_H

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.