summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/ecpglib/sqlda.c
blob: 081e32666f6ac7eb45d3e3171f2adb5a52463cf3 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/*
 * SQLDA support routines
 *
 * The allocated memory area pointed by an sqlda pointer
 * contains both the metadata and the data, so freeing up
 * is a simple free(sqlda) as expected by the ESQL/C examples.
 */

#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"

#include "catalog/pg_type_d.h"
#include "decimal.h"
#include "ecpg-pthread-win32.h"
#include "ecpgerrno.h"
#include "ecpglib.h"
#include "ecpglib_extern.h"
#include "ecpgtype.h"
#include "sqlca.h"
#include "sqlda-compat.h"
#include "sqlda-native.h"

/*
 * Compute the next variable's offset with
 * the current variable's size and alignment.
 *
 *
 * Returns:
 * - the current variable's offset in *current
 * - the next variable's offset in *next
 */
static void
ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
{
	if (offset % alignment)
		offset += alignment - (offset % alignment);
	if (current)
		*current = offset;
	offset += size;
	if (next)
		*next = offset;
}

static long
sqlda_compat_empty_size(const PGresult *res)
{
	long		offset;
	int			i;
	int			sqld = PQnfields(res);

	/* Initial size to store main structure and field structures */
	offset = sizeof(struct sqlda_compat) + sqld * sizeof(struct sqlvar_compat);

	/* Add space for field names */
	for (i = 0; i < sqld; i++)
		offset += strlen(PQfname(res, i)) + 1;

	/* Add padding to the first field value */
	ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);

	return offset;
}

static long
sqlda_common_total_size(const PGresult *res, int row, enum COMPAT_MODE compat, long offset)
{
	int			sqld = PQnfields(res);
	int			i;
	long		next_offset;

	/* Add space for the field values */
	for (i = 0; i < sqld; i++)
	{
		enum ECPGttype type = sqlda_dynamic_type(PQftype(res, i), compat);

		switch (type)
		{
			case ECPGt_short:
			case ECPGt_unsigned_short:
				ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
				break;
			case ECPGt_int:
			case ECPGt_unsigned_int:
				ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
				break;
			case ECPGt_long:
			case ECPGt_unsigned_long:
				ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
				break;
			case ECPGt_long_long:
			case ECPGt_unsigned_long_long:
				ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
				break;
			case ECPGt_bool:
				ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
				break;
			case ECPGt_float:
				ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
				break;
			case ECPGt_double:
				ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
				break;
			case ECPGt_decimal:
				ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
				break;
			case ECPGt_numeric:

				/*
				 * We align the numeric struct to allow it to store a pointer,
				 * while the digits array is aligned to int (which seems like
				 * overkill, but let's keep compatibility here).
				 *
				 * Unfortunately we need to deconstruct the value twice to
				 * find out the digits array's size and then later fill it.
				 */
				ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
				if (!PQgetisnull(res, row, i))
				{
					char	   *val = PQgetvalue(res, row, i);
					numeric    *num;

					num = PGTYPESnumeric_from_asc(val, NULL);
					if (!num)
						break;
					if (num->buf)
						ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
					PGTYPESnumeric_free(num);
				}
				break;
			case ECPGt_date:
				ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
				break;
			case ECPGt_timestamp:
				ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
				break;
			case ECPGt_interval:
				ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
				break;
			case ECPGt_char:
			case ECPGt_unsigned_char:
			case ECPGt_string:
			default:
				{
					long		datalen = strlen(PQgetvalue(res, row, i)) + 1;

					ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
					break;
				}
		}
		offset = next_offset;
	}
	return offset;
}


static long
sqlda_compat_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
{
	long		offset;

	offset = sqlda_compat_empty_size(res);

	if (row < 0)
		return offset;

	offset = sqlda_common_total_size(res, row, compat, offset);
	return offset;
}

static long
sqlda_native_empty_size(const PGresult *res)
{
	long		offset;
	int			sqld = PQnfields(res);

	/* Initial size to store main structure and field structures */
	offset = sizeof(struct sqlda_struct) + (sqld - 1) * sizeof(struct sqlvar_struct);

	/* Add padding to the first field value */
	ecpg_sqlda_align_add_size(offset, sizeof(int), 0, &offset, NULL);

	return offset;
}

static long
sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
{
	long		offset;

	offset = sqlda_native_empty_size(res);

	if (row < 0)
		return offset;

	offset = sqlda_common_total_size(res, row, compat, offset);
	return offset;
}

/*
 * Build "struct sqlda_compat" (metadata only) from PGresult
 * leaving enough space for the field values in
 * the given row number
 */
struct sqlda_compat *
ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
{
	struct sqlda_compat *sqlda;
	struct sqlvar_compat *sqlvar;
	char	   *fname;
	long		size;
	int			sqld;
	int			i;

	size = sqlda_compat_total_size(res, row, compat);
	sqlda = (struct sqlda_compat *) ecpg_alloc(size, line);
	if (!sqlda)
		return NULL;

	memset(sqlda, 0, size);
	sqlvar = (struct sqlvar_compat *) (sqlda + 1);
	sqld = PQnfields(res);
	fname = (char *) (sqlvar + sqld);

	sqlda->sqld = sqld;
	ecpg_log("ecpg_build_compat_sqlda on line %d sqld = %d\n", line, sqld);
	sqlda->desc_occ = size;		/* cheat here, keep the full allocated size */
	sqlda->sqlvar = sqlvar;

	for (i = 0; i < sqlda->sqld; i++)
	{
		sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
		strcpy(fname, PQfname(res, i));
		sqlda->sqlvar[i].sqlname = fname;
		fname += strlen(sqlda->sqlvar[i].sqlname) + 1;

		/*
		 * this is reserved for future use, so we leave it empty for the time
		 * being
		 */
		/* sqlda->sqlvar[i].sqlformat = (char *) (long) PQfformat(res, i); */
		sqlda->sqlvar[i].sqlxid = PQftype(res, i);
		sqlda->sqlvar[i].sqltypelen = PQfsize(res, i);
	}

	return sqlda;
}

/*
 * Sets values from PGresult.
 */
static int16 value_is_null = -1;
static int16 value_is_not_null = 0;

void
ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
{
	struct sqlda_compat *sqlda = (*_sqlda);
	int			i;
	long		offset,
				next_offset;

	if (row < 0)
		return;

	/* Offset for the first field value */
	offset = sqlda_compat_empty_size(res);

	/*
	 * Set sqlvar[i]->sqldata pointers and convert values to correct format
	 */
	for (i = 0; i < sqlda->sqld; i++)
	{
		int			isnull;
		int			datalen;
		bool		set_data = true;

		switch (sqlda->sqlvar[i].sqltype)
		{
			case ECPGt_short:
			case ECPGt_unsigned_short:
				ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(short);
				break;
			case ECPGt_int:
			case ECPGt_unsigned_int:
				ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(int);
				break;
			case ECPGt_long:
			case ECPGt_unsigned_long:
				ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(long);
				break;
			case ECPGt_long_long:
			case ECPGt_unsigned_long_long:
				ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(long long);
				break;
			case ECPGt_bool:
				ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(bool);
				break;
			case ECPGt_float:
				ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(float);
				break;
			case ECPGt_double:
				ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(double);
				break;
			case ECPGt_decimal:
				ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(decimal);
				break;
			case ECPGt_numeric:
				{
					numeric    *num;
					char	   *val;

					set_data = false;

					ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
					sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
					sqlda->sqlvar[i].sqllen = sizeof(numeric);

					if (PQgetisnull(res, row, i))
					{
						ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
						break;
					}

					val = PQgetvalue(res, row, i);
					num = PGTYPESnumeric_from_asc(val, NULL);
					if (!num)
					{
						ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
						break;
					}

					memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));

					if (num->buf)
					{
						ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
						memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);

						((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
						((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
					}

					PGTYPESnumeric_free(num);

					break;
				}
			case ECPGt_date:
				ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(date);
				break;
			case ECPGt_timestamp:
				ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(timestamp);
				break;
			case ECPGt_interval:
				ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(interval);
				break;
			case ECPGt_char:
			case ECPGt_unsigned_char:
			case ECPGt_string:
			default:
				datalen = strlen(PQgetvalue(res, row, i)) + 1;
				ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = datalen;
				if (datalen > 32768)
					sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
				break;
		}

		isnull = PQgetisnull(res, row, i);
		ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
		sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
		sqlda->sqlvar[i].sqlitype = ECPGt_short;
		sqlda->sqlvar[i].sqlilen = sizeof(short);
		if (!isnull)
		{
			if (set_data)
				ecpg_get_data(res, row, i, lineno,
							  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
							  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
							  ECPG_ARRAY_NONE, compat, false);
		}
		else
			ECPGset_noind_null(sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqldata);

		offset = next_offset;
	}
}

struct sqlda_struct *
ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
{
	struct sqlda_struct *sqlda;
	long		size;
	int			i;

	size = sqlda_native_total_size(res, row, compat);
	sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
	if (!sqlda)
		return NULL;

	memset(sqlda, 0, size);

	sprintf(sqlda->sqldaid, "SQLDA  ");
	sqlda->sqld = sqlda->sqln = PQnfields(res);
	ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
	sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);

	for (i = 0; i < sqlda->sqld; i++)
	{
		char	   *fname;

		sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
		fname = PQfname(res, i);
		sqlda->sqlvar[i].sqlname.length = strlen(fname);
		strcpy(sqlda->sqlvar[i].sqlname.data, fname);
	}

	return sqlda;
}

void
ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
{
	struct sqlda_struct *sqlda = (*_sqlda);
	int			i;
	long		offset,
				next_offset;

	if (row < 0)
		return;

	/* Offset for the first field value */
	offset = sqlda_native_empty_size(res);

	/*
	 * Set sqlvar[i]->sqldata pointers and convert values to correct format
	 */
	for (i = 0; i < sqlda->sqld; i++)
	{
		int			isnull;
		int			datalen;
		bool		set_data = true;

		switch (sqlda->sqlvar[i].sqltype)
		{
			case ECPGt_short:
			case ECPGt_unsigned_short:
				ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(short);
				break;
			case ECPGt_int:
			case ECPGt_unsigned_int:
				ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(int);
				break;
			case ECPGt_long:
			case ECPGt_unsigned_long:
				ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(long);
				break;
			case ECPGt_long_long:
			case ECPGt_unsigned_long_long:
				ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(long long);
				break;
			case ECPGt_bool:
				ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(bool);
				break;
			case ECPGt_float:
				ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(float);
				break;
			case ECPGt_double:
				ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(double);
				break;
			case ECPGt_decimal:
				ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(decimal);
				break;
			case ECPGt_numeric:
				{
					numeric    *num;
					char	   *val;

					set_data = false;

					ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
					sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
					sqlda->sqlvar[i].sqllen = sizeof(numeric);

					if (PQgetisnull(res, row, i))
					{
						ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
						break;
					}

					val = PQgetvalue(res, row, i);
					num = PGTYPESnumeric_from_asc(val, NULL);
					if (!num)
					{
						ECPGset_noind_null(ECPGt_numeric, sqlda->sqlvar[i].sqldata);
						break;
					}

					memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));

					if (num->buf)
					{
						ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
						memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);

						((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
						((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
					}

					PGTYPESnumeric_free(num);

					break;
				}
			case ECPGt_date:
				ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(date);
				break;
			case ECPGt_timestamp:
				ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(timestamp);
				break;
			case ECPGt_interval:
				ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = sizeof(interval);
				break;
			case ECPGt_char:
			case ECPGt_unsigned_char:
			case ECPGt_string:
			default:
				datalen = strlen(PQgetvalue(res, row, i)) + 1;
				ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
				sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
				sqlda->sqlvar[i].sqllen = datalen;
				break;
		}

		isnull = PQgetisnull(res, row, i);
		ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
		sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
		if (!isnull)
		{
			if (set_data)
				ecpg_get_data(res, row, i, lineno,
							  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
							  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
							  ECPG_ARRAY_NONE, compat, false);
		}

		offset = next_offset;
	}
}