~ubuntu-branches/ubuntu/hardy/psqlodbc/hardy

« back to all changes in this revision

Viewing changes to environ.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2007-03-05 22:28:19 UTC
  • mfrom: (3.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20070305222819-95d0rzmt2ah6dwwc
Tags: 1:08.01.0200-2.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Fix the signature of SQLGetData on 64-bit architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 */
15
15
 
16
16
#include "environ.h"
17
 
 
18
17
#include "connection.h"
19
18
#include "dlg_specific.h"
20
19
#include "statement.h"
48
47
         * should work.
49
48
         */
50
49
        if (globals.socket_buffersize <= 0)
 
50
        {
 
51
                initialize_global_cs();
51
52
                getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
 
53
        }
52
54
 
53
55
        *phenv = (HENV) EN_Constructor();
54
56
        if (!*phenv)
89
91
        strcpy(szSqlState, EN_is_odbc3(env) ? ver3str : ver2str);
90
92
}
91
93
 
92
 
#define DRVMNGRDIV      511
93
 
/*              Returns the next SQL error information. */
94
 
RETCODE         SQL_API
95
 
PGAPI_StmtError(        HSTMT hstmt,
96
 
                        SWORD   RecNumber,
97
 
                        UCHAR FAR * szSqlState,
98
 
                        SDWORD FAR * pfNativeError,
99
 
                        UCHAR FAR * szErrorMsg,
100
 
                        SWORD cbErrorMsgMax,
101
 
                        SWORD FAR * pcbErrorMsg,
 
94
PG_ErrorInfo    *ER_Constructor(SDWORD errnumber, const char *msg)
 
95
{
 
96
        PG_ErrorInfo    *error;
 
97
        Int4            aladd, errsize;
 
98
 
 
99
        if (DESC_OK == errnumber)
 
100
                return NULL;
 
101
        if (msg)
 
102
        {
 
103
                errsize = strlen(msg);
 
104
                aladd = errsize;
 
105
        }
 
106
        else
 
107
        {
 
108
                errsize = -1;
 
109
                aladd = 0;
 
110
        }
 
111
        error = (PG_ErrorInfo *) malloc(sizeof(PG_ErrorInfo) + aladd);
 
112
        if (error)
 
113
        {
 
114
                memset(error, 0, sizeof(PG_ErrorInfo));
 
115
                error->status = errnumber;
 
116
                error->errorsize = errsize;
 
117
                if (errsize > 0)
 
118
                        memcpy(error->__error_message, msg, errsize);
 
119
                error->__error_message[aladd] = '\0';
 
120
                error->recsize = -1;
 
121
        }
 
122
        return error;
 
123
}
 
124
void
 
125
ER_Destructor(PG_ErrorInfo *self)
 
126
{
 
127
        if (self->__error_message)
 
128
                free(self->__error_message);
 
129
        free(self);
 
130
}
 
131
 
 
132
#define DRVMNGRDIV      511
 
133
/*              Returns the next SQL error information. */
 
134
RETCODE         SQL_API
 
135
ER_ReturnError(PG_ErrorInfo *error,
 
136
                SWORD   RecNumber,
 
137
                UCHAR FAR * szSqlState,
 
138
                SDWORD FAR * pfNativeError,
 
139
                UCHAR FAR * szErrorMsg,
 
140
                SWORD cbErrorMsgMax,
 
141
                SWORD FAR * pcbErrorMsg,
 
142
                UWORD flag)
 
143
{
 
144
        /* CC: return an error of a hstmt  */
 
145
        BOOL            partial_ok = ((flag & PODBC_ALLOW_PARTIAL_EXTRACT) != 0),
 
146
                        clear_str = ((flag & PODBC_ERROR_CLEAR) != 0);
 
147
        const char      *msg;
 
148
        SWORD           msglen, stapos, wrtlen, pcblen;
 
149
 
 
150
        if (!error)
 
151
                return SQL_NO_DATA_FOUND;
 
152
        msg = error->__error_message;
 
153
        mylog("ER_GetError: status = %d, msg = #%s#\n", error->status, msg);
 
154
        msglen = (SWORD) strlen(msg);
 
155
        /*
 
156
         *      Even though an application specifies a larger error message
 
157
         *      buffer, the driver manager changes it silently.
 
158
         *      Therefore we divide the error message into ...
 
159
         */
 
160
        if (error->recsize < 0)
 
161
        {
 
162
                if (cbErrorMsgMax > 0)
 
163
                        error->recsize = cbErrorMsgMax - 1; /* apply the first request */
 
164
                else
 
165
                        error->recsize = DRVMNGRDIV;
 
166
        }
 
167
        if (RecNumber < 0)
 
168
        {
 
169
                if (0 == error->errorpos)
 
170
                        RecNumber = 1;
 
171
                else
 
172
                        RecNumber = 2 + (error->errorpos - 1) / error->recsize;
 
173
        }
 
174
        stapos = (RecNumber - 1) * error->recsize;
 
175
        if (stapos > msglen)
 
176
                return SQL_NO_DATA_FOUND;
 
177
        pcblen = wrtlen = msglen - stapos;
 
178
        if (pcblen > error->recsize)
 
179
                pcblen = error->recsize;
 
180
        if (0 == cbErrorMsgMax)
 
181
                wrtlen = 0;
 
182
        else if (wrtlen >= cbErrorMsgMax)
 
183
        {
 
184
                if (partial_ok)
 
185
                        wrtlen = cbErrorMsgMax - 1;
 
186
                else if (cbErrorMsgMax <= error->recsize)
 
187
                        wrtlen = 0;
 
188
                else
 
189
                        wrtlen = error->recsize;
 
190
        }
 
191
        if (wrtlen > pcblen)
 
192
                wrtlen = pcblen;
 
193
        if (NULL != pcbErrorMsg)
 
194
                *pcbErrorMsg = pcblen;
 
195
 
 
196
        if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
 
197
        {
 
198
                memcpy(szErrorMsg, msg + stapos, wrtlen);
 
199
                szErrorMsg[wrtlen] = '\0';
 
200
        }
 
201
 
 
202
        if (NULL != pfNativeError)
 
203
                *pfNativeError = error->status;
 
204
 
 
205
        if (NULL != szSqlState)
 
206
                strncpy(szSqlState, error->sqlstate, 6);
 
207
 
 
208
        mylog("      szSqlState = '%s',len=%d, szError='%s'\n", szSqlState, pcblen, szErrorMsg);
 
209
        if (clear_str)
 
210
        {
 
211
                error->errorpos = stapos + wrtlen;
 
212
                if (error->errorpos >= msglen)
 
213
                        ER_Destructor(error);
 
214
        }
 
215
        if (wrtlen == 0)
 
216
                return SQL_SUCCESS_WITH_INFO;
 
217
        else
 
218
                return SQL_SUCCESS;
 
219
}
 
220
 
 
221
#define DRVMNGRDIV      511
 
222
/*              Returns the next SQL error information. */
 
223
RETCODE         SQL_API
 
224
PGAPI_StmtError(        HSTMT hstmt, 
 
225
                        SWORD RecNumber,
 
226
                        SQLCHAR *szSqlState, 
 
227
                        SQLINTEGER *pfNativeError,
 
228
                        SQLCHAR *szErrorMsg, 
 
229
                        SQLSMALLINT cbErrorMsgMax,
 
230
                        SQLSMALLINT *pcbErrorMsg, 
102
231
                        UWORD flag)
103
232
{
104
233
        /* CC: return an error of a hstmt  */
133
262
        /*
134
263
         *      Even though an application specifies a larger error message
135
264
         *      buffer, the driver manager changes it silently.
136
 
         *      Therefore we divide the error message into ... 
 
265
         *      Therefore we divide the error message into ...
137
266
         */
138
267
        if (stmt->error_recsize < 0)
139
268
        {
151
280
        }
152
281
        stapos = (RecNumber - 1) * stmt->error_recsize;
153
282
        if (stapos > msglen)
154
 
                return SQL_NO_DATA_FOUND; 
 
283
                return SQL_NO_DATA_FOUND;
155
284
        pcblen = wrtlen = msglen - stapos;
156
285
        if (pcblen > stmt->error_recsize)
157
286
                pcblen = stmt->error_recsize;
158
287
        if (0 == cbErrorMsgMax)
159
 
                wrtlen = 0; 
 
288
                wrtlen = 0;
160
289
        else if (wrtlen >= cbErrorMsgMax)
161
290
        {
162
291
                if (partial_ok)
163
292
                        wrtlen = cbErrorMsgMax - 1;
164
293
                else if (cbErrorMsgMax <= stmt->error_recsize)
165
294
                        wrtlen = 0;
166
 
                else 
 
295
                else
167
296
                        wrtlen = stmt->error_recsize;
168
297
        }
169
298
        if (wrtlen > pcblen)
182
311
 
183
312
        if (NULL != szSqlState)
184
313
 
185
 
                switch (status)
186
 
                {
187
 
                                /* now determine the SQLSTATE to be returned */
188
 
                        case STMT_ROW_VERSION_CHANGED:
189
 
                                pg_sqlstate_set(env, szSqlState, "01001", "01001");
190
 
                                /* data truncated */
191
 
                                break;
192
 
                        case STMT_TRUNCATED:
193
 
                                pg_sqlstate_set(env, szSqlState, "01004", "01004");
194
 
                                /* data truncated */
195
 
                                break;
196
 
                        case STMT_INFO_ONLY:
197
 
                                pg_sqlstate_set(env, szSqlState, "00000", "0000");
198
 
                                /* just information that is returned, no error */
199
 
                                break;
200
 
                        case STMT_BAD_ERROR:
201
 
                                pg_sqlstate_set(env, szSqlState, "08S01", "08S01");
202
 
                                /* communication link failure */
203
 
                                break;
204
 
                        case STMT_CREATE_TABLE_ERROR:
205
 
                                pg_sqlstate_set(env, szSqlState, "42S01", "S0001");
206
 
                                /* table already exists */
207
 
                                break;
208
 
                        case STMT_STATUS_ERROR:
209
 
                        case STMT_SEQUENCE_ERROR:
210
 
                                pg_sqlstate_set(env, szSqlState, "HY010", "S1010");
211
 
                                /* Function sequence error */
212
 
                                break;
213
 
                        case STMT_NO_MEMORY_ERROR:
214
 
                                pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
215
 
                                /* memory allocation failure */
216
 
                                break;
217
 
                        case STMT_COLNUM_ERROR:
218
 
                                pg_sqlstate_set(env, szSqlState, "07009", "S1002");
219
 
                                /* invalid column number */
220
 
                                break;
221
 
                        case STMT_NO_STMTSTRING:
222
 
                                pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
223
 
                                /* having no stmtstring is also a malloc problem */
224
 
                                break;
225
 
                        case STMT_ERROR_TAKEN_FROM_BACKEND:
226
 
                                pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
227
 
                                /* general error */
228
 
                                break;
229
 
                        case STMT_INTERNAL_ERROR:
230
 
                                pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
231
 
                                /* general error */
232
 
                                break;
233
 
                        case STMT_FETCH_OUT_OF_RANGE:
234
 
                                pg_sqlstate_set(env, szSqlState, "HY106", "S1106");
235
 
                                break;
236
 
 
237
 
                        case STMT_ROW_OUT_OF_RANGE:
238
 
                                pg_sqlstate_set(env, szSqlState, "HY107", "S1107");
239
 
                                break;
240
 
 
241
 
                        case STMT_OPERATION_CANCELLED:
242
 
                                pg_sqlstate_set(env, szSqlState, "HY008", "S1008");
243
 
                                break;
244
 
 
245
 
                        case STMT_NOT_IMPLEMENTED_ERROR:
246
 
                                pg_sqlstate_set(env, szSqlState, "HYC00", "S1C00");     /* == 'driver not
247
 
                                                                                                         * capable' */
248
 
                                break;
249
 
                        case STMT_OPTION_OUT_OF_RANGE_ERROR:
250
 
                                pg_sqlstate_set(env, szSqlState, "HY092", "S1092");
251
 
                                break;
252
 
                        case STMT_BAD_PARAMETER_NUMBER_ERROR:
253
 
                                pg_sqlstate_set(env, szSqlState, "07009", "S1093");
254
 
                                break;
255
 
                        case STMT_INVALID_COLUMN_NUMBER_ERROR:
256
 
                                pg_sqlstate_set(env, szSqlState, "07009", "S1002");
257
 
                                break;
258
 
                        case STMT_RESTRICTED_DATA_TYPE_ERROR:
259
 
                                pg_sqlstate_set(env, szSqlState, "07006", "07006");
260
 
                                break;
261
 
                        case STMT_INVALID_CURSOR_STATE_ERROR:
262
 
                                pg_sqlstate_set(env, szSqlState, "07005", "24000");
263
 
                                break;
264
 
                        case STMT_ERROR_IN_ROW:
265
 
                                pg_sqlstate_set(env, szSqlState, "01S01", "01S01");
266
 
                                break;
267
 
                        case STMT_OPTION_VALUE_CHANGED:
268
 
                                pg_sqlstate_set(env, szSqlState, "01S02", "01S02");
269
 
                                break;
270
 
                        case STMT_POS_BEFORE_RECORDSET:
271
 
                                pg_sqlstate_set(env, szSqlState, "01S06", "01S06");
272
 
                                break;
273
 
                        case STMT_INVALID_CURSOR_NAME:
274
 
                                pg_sqlstate_set(env, szSqlState, "34000", "34000");
275
 
                                break;
276
 
                        case STMT_NO_CURSOR_NAME:
277
 
                                pg_sqlstate_set(env, szSqlState, "S1015", "S1015");
278
 
                                break;
279
 
                        case STMT_INVALID_ARGUMENT_NO:
280
 
                                pg_sqlstate_set(env, szSqlState, "HY024", "S1009");
281
 
                                /* invalid argument value */
282
 
                                break;
283
 
                        case STMT_INVALID_CURSOR_POSITION:
284
 
                                pg_sqlstate_set(env, szSqlState, "HY109", "S1109");
285
 
                                break;
286
 
                        case STMT_RETURN_NULL_WITHOUT_INDICATOR:
287
 
                                pg_sqlstate_set(env, szSqlState, "22002", "22002");
288
 
                                break;
289
 
                        case STMT_VALUE_OUT_OF_RANGE:
290
 
                                pg_sqlstate_set(env, szSqlState, "HY019", "22003");
291
 
                                break;
292
 
                        case STMT_OPERATION_INVALID:
293
 
                                pg_sqlstate_set(env, szSqlState, "HY011", "S1011");
294
 
                                break;
295
 
                        case STMT_INVALID_DESCRIPTOR_IDENTIFIER:
296
 
                                pg_sqlstate_set(env, szSqlState, "HY091", "HY091");
297
 
                                break;
298
 
                        case STMT_INVALID_OPTION_IDENTIFIER:
299
 
                                pg_sqlstate_set(env, szSqlState, "HY092", "HY092");
300
 
                                break;
301
 
                        case STMT_OPTION_NOT_FOR_THE_DRIVER:
302
 
                                pg_sqlstate_set(env, szSqlState, "HYC00", "HYC00");
303
 
                                break;
304
 
                        case STMT_COUNT_FIELD_INCORRECT:
305
 
                                pg_sqlstate_set(env, szSqlState, "07002", "07002");
306
 
                                break;
307
 
                        case STMT_EXEC_ERROR:
308
 
                        default:
309
 
                                pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
310
 
                                /* also a general error */
311
 
                                break;
312
 
                }
 
314
                if ((stmt->__sqlstate != NULL) && (stmt->__sqlstate[0] != '\0'))
 
315
                                pg_sqlstate_set(env, szSqlState, stmt->__sqlstate, stmt->__sqlstate);
 
316
                else
 
317
                        switch (status)
 
318
                        {
 
319
                                        /* now determine the SQLSTATE to be returned */
 
320
                                case STMT_ROW_VERSION_CHANGED:
 
321
                                        pg_sqlstate_set(env, szSqlState, "01001", "01001");
 
322
                                        /* data truncated */
 
323
                                        break;
 
324
                                case STMT_TRUNCATED:
 
325
                                        pg_sqlstate_set(env, szSqlState, "01004", "01004");
 
326
                                        /* data truncated */
 
327
                                        break;
 
328
                                case STMT_INFO_ONLY:
 
329
                                        pg_sqlstate_set(env, szSqlState, "00000", "0000");
 
330
                                        /* just information that is returned, no error */
 
331
                                        break;
 
332
                                case STMT_BAD_ERROR:
 
333
                                        pg_sqlstate_set(env, szSqlState, "08S01", "08S01");
 
334
                                        /* communication link failure */
 
335
                                        break;
 
336
                                case STMT_CREATE_TABLE_ERROR:
 
337
                                        pg_sqlstate_set(env, szSqlState, "42S01", "S0001");
 
338
                                        /* table already exists */
 
339
                                        break;
 
340
                                case STMT_STATUS_ERROR:
 
341
                                case STMT_SEQUENCE_ERROR:
 
342
                                        pg_sqlstate_set(env, szSqlState, "HY010", "S1010");
 
343
                                        /* Function sequence error */
 
344
                                        break;
 
345
                                case STMT_NO_MEMORY_ERROR:
 
346
                                        pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
 
347
                                        /* memory allocation failure */
 
348
                                        break;
 
349
                                case STMT_COLNUM_ERROR:
 
350
                                        pg_sqlstate_set(env, szSqlState, "07009", "S1002");
 
351
                                        /* invalid column number */
 
352
                                        break;
 
353
                                case STMT_NO_STMTSTRING:
 
354
                                        pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
 
355
                                        /* having no stmtstring is also a malloc problem */
 
356
                                        break;
 
357
                                case STMT_ERROR_TAKEN_FROM_BACKEND:
 
358
                                        pg_sqlstate_set(env, szSqlState, SC_get_sqlstate(stmt), "S1000");
 
359
                                        /* Use the ODBC 3 sqlstate reported by the backend. */
 
360
                                        break;
 
361
                                case STMT_INTERNAL_ERROR:
 
362
                                        pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
 
363
                                        /* general error */
 
364
                                        break;
 
365
                                case STMT_FETCH_OUT_OF_RANGE:
 
366
                                        pg_sqlstate_set(env, szSqlState, "HY106", "S1106");
 
367
                                        break;
 
368
                                case STMT_ROW_OUT_OF_RANGE:
 
369
                                        pg_sqlstate_set(env, szSqlState, "HY107", "S1107");
 
370
                                        break;
 
371
                                case STMT_OPERATION_CANCELLED:
 
372
                                        pg_sqlstate_set(env, szSqlState, "HY008", "S1008");
 
373
                                        break;
 
374
                                case STMT_NOT_IMPLEMENTED_ERROR:
 
375
                                        pg_sqlstate_set(env, szSqlState, "HYC00", "S1C00");     /* == 'driver not
 
376
                                                                                                                 * capable' */
 
377
                                        break;
 
378
                                case STMT_OPTION_OUT_OF_RANGE_ERROR:
 
379
                                        pg_sqlstate_set(env, szSqlState, "HY092", "S1092");
 
380
                                        break;
 
381
                                case STMT_BAD_PARAMETER_NUMBER_ERROR:
 
382
                                        pg_sqlstate_set(env, szSqlState, "07009", "S1093");
 
383
                                        break;
 
384
                                case STMT_INVALID_COLUMN_NUMBER_ERROR:
 
385
                                        pg_sqlstate_set(env, szSqlState, "07009", "S1002");
 
386
                                        break;
 
387
                                case STMT_RESTRICTED_DATA_TYPE_ERROR:
 
388
                                        pg_sqlstate_set(env, szSqlState, "07006", "07006");
 
389
                                        break;
 
390
                                case STMT_INVALID_CURSOR_STATE_ERROR:
 
391
                                        pg_sqlstate_set(env, szSqlState, "07005", "24000");
 
392
                                        break;
 
393
                                case STMT_ERROR_IN_ROW:
 
394
                                        pg_sqlstate_set(env, szSqlState, "01S01", "01S01");
 
395
                                        break;
 
396
                                case STMT_OPTION_VALUE_CHANGED:
 
397
                                        pg_sqlstate_set(env, szSqlState, "01S02", "01S02");
 
398
                                        break;
 
399
                                case STMT_POS_BEFORE_RECORDSET:
 
400
                                        pg_sqlstate_set(env, szSqlState, "01S06", "01S06");
 
401
                                        break;
 
402
                                case STMT_INVALID_CURSOR_NAME:
 
403
                                        pg_sqlstate_set(env, szSqlState, "34000", "34000");
 
404
                                        break;
 
405
                                case STMT_NO_CURSOR_NAME:
 
406
                                        pg_sqlstate_set(env, szSqlState, "S1015", "S1015");
 
407
                                        break;
 
408
                                case STMT_INVALID_ARGUMENT_NO:
 
409
                                        pg_sqlstate_set(env, szSqlState, "HY024", "S1009");
 
410
                                        /* invalid argument value */
 
411
                                        break;
 
412
                                case STMT_INVALID_CURSOR_POSITION:
 
413
                                        pg_sqlstate_set(env, szSqlState, "HY109", "S1109");
 
414
                                        break;
 
415
                                case STMT_RETURN_NULL_WITHOUT_INDICATOR:
 
416
                                        pg_sqlstate_set(env, szSqlState, "22002", "22002");
 
417
                                        break;
 
418
                                case STMT_VALUE_OUT_OF_RANGE:
 
419
                                        pg_sqlstate_set(env, szSqlState, "HY019", "22003");
 
420
                                        break;
 
421
                                case STMT_OPERATION_INVALID:
 
422
                                        pg_sqlstate_set(env, szSqlState, "HY011", "S1011");
 
423
                                        break;
 
424
                                case STMT_INVALID_DESCRIPTOR_IDENTIFIER:
 
425
                                        pg_sqlstate_set(env, szSqlState, "HY091", "HY091");
 
426
                                        break;
 
427
                                case STMT_INVALID_OPTION_IDENTIFIER:
 
428
                                        pg_sqlstate_set(env, szSqlState, "HY092", "HY092");
 
429
                                        break;
 
430
                                case STMT_OPTION_NOT_FOR_THE_DRIVER:
 
431
                                        pg_sqlstate_set(env, szSqlState, "HYC00", "HYC00");
 
432
                                        break;
 
433
                                case STMT_COUNT_FIELD_INCORRECT:
 
434
                                        pg_sqlstate_set(env, szSqlState, "07002", "07002");
 
435
                                        break;
 
436
                                case STMT_EXEC_ERROR:
 
437
                                default:
 
438
                                        pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
 
439
                                        /* also a general error */
 
440
                                        break;
 
441
                        }
313
442
        mylog("      szSqlState = '%s',len=%d, szError='%s'\n", szSqlState, pcblen, szErrorMsg);
314
443
        if (clear_str)
315
444
        {
324
453
}
325
454
 
326
455
RETCODE         SQL_API
327
 
PGAPI_ConnectError(     HDBC hdbc,
328
 
                        SWORD   RecNumber,
329
 
                        UCHAR FAR * szSqlState,
330
 
                        SDWORD FAR * pfNativeError,
331
 
                        UCHAR FAR * szErrorMsg,
332
 
                        SWORD cbErrorMsgMax,
333
 
                        SWORD FAR * pcbErrorMsg,
 
456
PGAPI_ConnectError(HDBC hdbc, 
 
457
                        SWORD RecNumber,
 
458
                        SQLCHAR *szSqlState, 
 
459
                        SQLINTEGER *pfNativeError,
 
460
                        SQLCHAR *szErrorMsg, 
 
461
                        SQLSMALLINT cbErrorMsgMax,
 
462
                        SQLSMALLINT *pcbErrorMsg, 
334
463
                        UWORD flag)
335
464
{
336
465
        ConnectionClass *conn = (ConnectionClass *) hdbc;
374
503
                *pfNativeError = status;
375
504
 
376
505
        if (NULL != szSqlState)
377
 
                switch (status)
378
 
                {
379
 
                        case STMT_OPTION_VALUE_CHANGED:
380
 
                        case CONN_OPTION_VALUE_CHANGED:
381
 
                                pg_sqlstate_set(env, szSqlState, "01S02", "01S02");
382
 
                                break;
383
 
                        case STMT_TRUNCATED:
384
 
                        case CONN_TRUNCATED:
385
 
                                pg_sqlstate_set(env, szSqlState, "01004", "01004");
386
 
                                /* data truncated */
387
 
                                break;
388
 
                        case CONN_INIREAD_ERROR:
389
 
                                pg_sqlstate_set(env, szSqlState, "IM002", "IM002");
390
 
                                /* data source not found */
391
 
                                break;
392
 
                        case CONNECTION_SERVER_NOT_REACHED:
393
 
                        case CONN_OPENDB_ERROR:
394
 
                                pg_sqlstate_set(env, szSqlState, "08001", "08001");
395
 
                                /* unable to connect to data source */
396
 
                                break;
397
 
                        case CONN_INVALID_AUTHENTICATION:
398
 
                        case CONN_AUTH_TYPE_UNSUPPORTED:
399
 
                                pg_sqlstate_set(env, szSqlState, "28000", "28000");
400
 
                                break;
401
 
                        case CONN_STMT_ALLOC_ERROR:
402
 
                                pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
403
 
                                /* memory allocation failure */
404
 
                                break;
405
 
                        case CONN_IN_USE:
406
 
                                pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
407
 
                                /* general error */
408
 
                                break;
409
 
                        case CONN_UNSUPPORTED_OPTION:
410
 
                                pg_sqlstate_set(env, szSqlState, "IM001", "IM001");
411
 
                                /* driver does not support this function */
412
 
                        case CONN_INVALID_ARGUMENT_NO:
413
 
                                pg_sqlstate_set(env, szSqlState, "HY009", "S1009");
414
 
                                /* invalid argument value */
415
 
                                break;
416
 
                        case CONN_TRANSACT_IN_PROGRES:
417
 
                                pg_sqlstate_set(env, szSqlState, "HY010", "S1010");
418
 
 
419
 
                                /*
420
 
                                 * when the user tries to switch commit mode in a
421
 
                                 * transaction
422
 
                                 */
423
 
                                /* -> function sequence error */
424
 
                                break;
425
 
                        case CONN_NO_MEMORY_ERROR:
426
 
                                pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
427
 
                                break;
428
 
                        case CONN_NOT_IMPLEMENTED_ERROR:
429
 
                        case STMT_NOT_IMPLEMENTED_ERROR:
430
 
                                pg_sqlstate_set(env, szSqlState, "HYC00", "S1C00");
431
 
                                break;
432
 
                        case STMT_RETURN_NULL_WITHOUT_INDICATOR:
433
 
                                pg_sqlstate_set(env, szSqlState, "22002", "22002");
434
 
                                break;
435
 
                        case CONN_VALUE_OUT_OF_RANGE:
436
 
                        case STMT_VALUE_OUT_OF_RANGE:
437
 
                                pg_sqlstate_set(env, szSqlState, "HY019", "22003");
438
 
                                break;
439
 
                        case CONNECTION_COULD_NOT_SEND:
440
 
                        case CONNECTION_COULD_NOT_RECEIVE:
441
 
                                pg_sqlstate_set(env, szSqlState, "08S01", "08S01");
442
 
                                break;
443
 
                        default:
444
 
                                pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
445
 
                                /* general error */
446
 
                                break;
447
 
                }
 
506
                if ((conn->__sqlstate != NULL) && (conn->__sqlstate[0] != '\0'))
 
507
                        pg_sqlstate_set(env, szSqlState, conn->__sqlstate, conn->__sqlstate);
 
508
                else
 
509
                        switch (status)
 
510
                        {
 
511
                                case STMT_OPTION_VALUE_CHANGED:
 
512
                                case CONN_OPTION_VALUE_CHANGED:
 
513
                                        pg_sqlstate_set(env, szSqlState, "01S02", "01S02");
 
514
                                        break;
 
515
                                case STMT_TRUNCATED:
 
516
                                case CONN_TRUNCATED:
 
517
                                        pg_sqlstate_set(env, szSqlState, "01004", "01004");
 
518
                                        /* data truncated */
 
519
                                        break;
 
520
                                case CONN_INIREAD_ERROR:
 
521
                                        pg_sqlstate_set(env, szSqlState, "IM002", "IM002");
 
522
                                        /* data source not found */
 
523
                                        break;
 
524
                                case CONNECTION_SERVER_NOT_REACHED:
 
525
                                case CONN_OPENDB_ERROR:
 
526
                                        pg_sqlstate_set(env, szSqlState, "08001", "08001");
 
527
                                        /* unable to connect to data source */
 
528
                                        break;
 
529
                                case CONN_INVALID_AUTHENTICATION:
 
530
                                case CONN_AUTH_TYPE_UNSUPPORTED:
 
531
                                        pg_sqlstate_set(env, szSqlState, "28000", "28000");
 
532
                                        break;
 
533
                                case CONN_STMT_ALLOC_ERROR:
 
534
                                        pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
 
535
                                        /* memory allocation failure */
 
536
                                        break;
 
537
                                case CONN_IN_USE:
 
538
                                        pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
 
539
                                        /* general error */
 
540
                                        break;
 
541
                                case CONN_UNSUPPORTED_OPTION:
 
542
                                        pg_sqlstate_set(env, szSqlState, "IM001", "IM001");
 
543
                                        /* driver does not support this function */
 
544
                                case CONN_INVALID_ARGUMENT_NO:
 
545
                                        pg_sqlstate_set(env, szSqlState, "HY009", "S1009");
 
546
                                        /* invalid argument value */
 
547
                                        break;
 
548
                                case CONN_TRANSACT_IN_PROGRES:
 
549
                                        pg_sqlstate_set(env, szSqlState, "HY010", "S1010");
 
550
                                        /*
 
551
                                         * when the user tries to switch commit mode in a
 
552
                                         * transaction
 
553
                                         */
 
554
                                        /* -> function sequence error */
 
555
                                        break;
 
556
                                case CONN_NO_MEMORY_ERROR:
 
557
                                        pg_sqlstate_set(env, szSqlState, "HY001", "S1001");
 
558
                                        break;
 
559
                                case CONN_NOT_IMPLEMENTED_ERROR:
 
560
                                case STMT_NOT_IMPLEMENTED_ERROR:
 
561
                                        pg_sqlstate_set(env, szSqlState, "HYC00", "S1C00");
 
562
                                        break;
 
563
                                case STMT_RETURN_NULL_WITHOUT_INDICATOR:
 
564
                                        pg_sqlstate_set(env, szSqlState, "22002", "22002");
 
565
                                        break;
 
566
                                case CONN_VALUE_OUT_OF_RANGE:
 
567
                                case STMT_VALUE_OUT_OF_RANGE:
 
568
                                        pg_sqlstate_set(env, szSqlState, "HY019", "22003");
 
569
                                        break;
 
570
                                case CONNECTION_COULD_NOT_SEND:
 
571
                                case CONNECTION_COULD_NOT_RECEIVE:
 
572
                                        pg_sqlstate_set(env, szSqlState, "08S01", "08S01");
 
573
                                        break;
 
574
                                default:
 
575
                                        pg_sqlstate_set(env, szSqlState, "HY000", "S1000");
 
576
                                        /* general error */
 
577
                                        break;
 
578
                        }
448
579
 
449
580
        mylog("      szSqlState = '%s',len=%d, szError='%s'\n", szSqlState, msglen, szErrorMsg);
450
581
        if (once_again)
457
588
}
458
589
 
459
590
RETCODE         SQL_API
460
 
PGAPI_EnvError(         HENV henv,
461
 
                        SWORD   RecNumber,
462
 
                        UCHAR FAR * szSqlState,
463
 
                        SDWORD FAR * pfNativeError,
464
 
                        UCHAR FAR * szErrorMsg,
465
 
                        SWORD cbErrorMsgMax,
466
 
                        SWORD FAR * pcbErrorMsg,
 
591
PGAPI_EnvError(         HENV henv, 
 
592
                        SWORD RecNumber,
 
593
                        SQLCHAR *szSqlState, 
 
594
                        SQLINTEGER *pfNativeError,
 
595
                        SQLCHAR *szErrorMsg, 
 
596
                        SQLSMALLINT cbErrorMsgMax,
 
597
                        SQLSMALLINT *pcbErrorMsg, 
467
598
                        UWORD flag)
468
599
{
469
600
        EnvironmentClass *env = (EnvironmentClass *) henv;
478
609
        if (!EN_get_error(env, &status, &msg) || NULL == msg)
479
610
        {
480
611
                        mylog("EN_get_error: status = %d, msg = #%s#\n", status, msg);
481
 
                
 
612
 
482
613
                if (NULL != szSqlState)
483
614
                        pg_sqlstate_set(env, szSqlState, "00000", "00000");
484
615
                if (NULL != pcbErrorMsg)
518
649
 
519
650
/*              Returns the next SQL error information. */
520
651
RETCODE         SQL_API
521
 
PGAPI_Error(
522
 
                        HENV henv,
523
 
                        HDBC hdbc,
 
652
PGAPI_Error(            HENV henv,
 
653
                        HDBC hdbc, 
524
654
                        HSTMT hstmt,
525
 
                        UCHAR FAR * szSqlState,
526
 
                        SDWORD FAR * pfNativeError,
527
 
                        UCHAR FAR * szErrorMsg,
528
 
                        SWORD cbErrorMsgMax,
529
 
                        SWORD FAR * pcbErrorMsg)
 
655
                        SQLCHAR *szSqlState,
 
656
                        SQLINTEGER *pfNativeError,
 
657
                        SQLCHAR *szErrorMsg, 
 
658
                        SQLSMALLINT cbErrorMsgMax,
 
659
                        SQLSMALLINT *pcbErrorMsg)
530
660
{
531
661
        RETCODE ret;
532
662
        UWORD   flag = PODBC_ALLOW_PARTIAL_EXTRACT | PODBC_ERROR_CLEAR;
594
724
         */
595
725
 
596
726
        /* Free any connections belonging to this environment */
 
727
        ENTER_CONNS_CS;
597
728
        for (lf = 0; lf < MAX_CONNECTIONS; lf++)
598
729
        {
599
730
                if (conns[lf] && conns[lf]->henv == self)
 
731
                {
600
732
                        rv = rv && CC_Destructor(conns[lf]);
 
733
                        conns[lf] = NULL;
 
734
                }
601
735
        }
 
736
        LEAVE_CONNS_CS;
602
737
        DELETE_ENV_CS(self);
603
738
        free(self);
604
739