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

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.