1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
}
|