1 /********************************************************************/
2 /* */
3 /* sql_base.c Basic database functions. */
4 /* Copyright (C) 2017 Thomas Mertes */
5 /* */
6 /* This file is part of the Seed7 Runtime Library. */
7 /* */
8 /* The Seed7 Runtime Library is free software; you can */
9 /* redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation; either version 2.1 of the License, or (at your */
12 /* option) any later version. */
13 /* */
14 /* The Seed7 Runtime Library is distributed in the hope that it */
15 /* will be useful, but WITHOUT ANY WARRANTY; without even the */
16 /* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
17 /* PURPOSE. See the GNU Lesser General Public License for more */
18 /* details. */
19 /* */
20 /* You should have received a copy of the GNU Lesser General */
21 /* Public License along with this program; if not, write to the */
22 /* Free Software Foundation, Inc., 51 Franklin Street, */
23 /* Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* */
25 /* Module: Seed7 Runtime Library */
26 /* File: seed7/src/sql_base.c */
27 /* Changes: 2017 Thomas Mertes */
28 /* Content: Basic database functions. */
29 /* */
30 /********************************************************************/
31
32 #define LOG_FUNCTIONS 0
33 #define VERBOSE_EXCEPTIONS 0
34
35 #include "version.h"
36
37 #include "stdlib.h"
38 #include "stdio.h"
39 #include "string.h"
40 #include "stdarg.h"
41
42 #include "common.h"
43 #include "heaputl.h"
44
45 #undef EXTERN
46 #define EXTERN
47 #define DO_INIT
48 #include "sql_base.h"
49
50
51
dbLibError(const char * funcName,const char * dbFuncName,const char * format,...)52 void dbLibError (const char *funcName, const char *dbFuncName,
53 const char *format, ...)
54
55 {
56 va_list ap;
57
58 /* dbLibError */
59 dbError.funcName = funcName;
60 dbError.dbFuncName = dbFuncName;
61 dbError.errorCode = 0;
62 va_start(ap, format);
63 vsnprintf(dbError.message, DB_ERR_MESSAGE_SIZE, format, ap);
64 va_end(ap);
65 } /* dbLibError */
66
67
68
dbInconsistentMsg(const char * funcName,const char * dbFuncName,const char * file,int line)69 void dbInconsistentMsg (const char *funcName, const char *dbFuncName,
70 const char *file, int line)
71
72 { /* dbInconsistentMsg */
73 dbLibError(funcName, dbFuncName, "Db interface inconsistent: %s(%d)",
74 file, line);
75 } /* dbInconsistentMsg */
76
77
78
dllErrorMessage(const char * funcName,const char * dbFuncName,const char * dllList[],memSizeType dllListLength)79 void dllErrorMessage (const char *funcName, const char *dbFuncName,
80 const char *dllList[], memSizeType dllListLength)
81
82 {
83 unsigned int pos;
84 memSizeType dllNamesSize = 0;
85 char *dllNames;
86 char *currPos;
87
88 /* dllErrorMessage */
89 for (pos = 0; pos < dllListLength; pos++) {
90 dllNamesSize += strlen(dllList[pos]) + 2; /* 2 chars for comma and space */
91 } /* for */
92 if (ALLOC_CSTRI(dllNames, dllNamesSize)) {
93 currPos = dllNames;
94 currPos[0] = '\0';
95 for (pos = 0; pos < dllListLength; pos++) {
96 currPos += sprintf(currPos, "%s, ", dllList[pos]);
97 } /* for */
98 if (currPos != dllNames) {
99 currPos[-2] = '\0';
100 } /* if */
101 dbLibError(funcName, dbFuncName,
102 "Searching for dynamic libraries failed: %s\n", dllNames);
103 logError(printf("%s: Searching for dynamic libraries failed: %s\n",
104 dbFuncName, dllNames););
105 UNALLOC_CSTRI(dllNames, dllNamesSize);
106 } /* if */
107 } /* dllErrorMessage */
108