aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/odbc/odbcapiw.c
blob: ac1e3f28f4e9e8099d4bbdcb724488b1d6f888a6 (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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/*-------
 * Module:			odbcapiw.c
 *
 * Description:		This module contains UNICODE routines
 *
 * Classes:			n/a
 *
 * API functions:	SQLColumnPrivilegesW, SQLColumnsW,
 			SQLConnectW, SQLDataSourcesW, SQLDescribeColW,
			SQLDriverConnectW, SQLExecDirectW,
			SQLForeignKeysW,
			SQLGetCursorNameW, SQLGetInfoW, SQLNativeSqlW,
			SQLPrepareW, SQLPrimaryKeysW, SQLProcedureColumnsW,
			SQLProceduresW, SQLSetCursorNameW,
			SQLSpecialColumnsW, SQLStatisticsW, SQLTablesW,
			SQLTablePrivilegesW, SQLGetTypeInfoW
 *-------
 */

#include "psqlodbc.h"
#include <stdio.h>
#include <string.h>

#include "pgapifunc.h"
#include "connection.h"
#include "statement.h"

RETCODE  SQL_API SQLColumnsW(HSTMT StatementHandle,
           SQLWCHAR *CatalogName, SQLSMALLINT NameLength1,
           SQLWCHAR *SchemaName, SQLSMALLINT NameLength2,
           SQLWCHAR *TableName, SQLSMALLINT NameLength3,
           SQLWCHAR *ColumnName, SQLSMALLINT NameLength4)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName, *clName;
	UInt4	nmlen1, nmlen2, nmlen3, nmlen4;

	mylog("[SQLColumnsW]");
	ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1);
	scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2);
	tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3);
	clName = ucs2_to_utf8(ColumnName, NameLength4, &nmlen4);
	ret = PGAPI_Columns(StatementHandle, ctName, (SWORD) nmlen1,
           	scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3,
           	clName, (SWORD) nmlen4, 0);
	if (ctName)
		free(ctName);
	if (scName);
		free(scName);
	if (tbName)
		free(tbName);
	if (clName);
		free(clName);
	return ret;
}


RETCODE  SQL_API SQLConnectW(HDBC ConnectionHandle,
           SQLWCHAR *ServerName, SQLSMALLINT NameLength1,
           SQLWCHAR *UserName, SQLSMALLINT NameLength2,
           SQLWCHAR *Authentication, SQLSMALLINT NameLength3)
{
	char	*svName, *usName, *auth;
	UInt4	nmlen1, nmlen2, nmlen3;
	RETCODE	ret;
	
	mylog("[SQLConnectW]");
	((ConnectionClass *) ConnectionHandle)->unicode = 1;
	svName = ucs2_to_utf8(ServerName, NameLength1, &nmlen1);
	usName = ucs2_to_utf8(UserName, NameLength2, &nmlen2);
	auth = ucs2_to_utf8(Authentication, NameLength3, &nmlen3);
	ret = PGAPI_Connect(ConnectionHandle, svName, (SWORD) nmlen1,
           	usName, (SWORD) nmlen2, auth, (SWORD) nmlen3);
	if (svName);
		free(svName);
	if (usName);
		free(usName);
	if (auth);
		free(auth);
	return ret;
}

RETCODE SQL_API SQLDriverConnectW(HDBC hdbc,
                                 HWND hwnd,
                                 SQLWCHAR *szConnStrIn,
                                 SWORD cbConnStrIn,
                                 SQLWCHAR *szConnStrOut,
                                 SWORD cbConnStrOutMax,
                                 SWORD FAR *pcbConnStrOut,
                                 UWORD fDriverCompletion)
{
	char	*szIn, *szOut;
	UInt4	inlen, obuflen;
	SWORD	olen;
	RETCODE	ret;

	mylog("[SQLDriverConnectW]");
	((ConnectionClass *) hdbc)->unicode = 1;
	szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen);
	obuflen = cbConnStrOutMax + 1;
	szOut = malloc(obuflen);
	ret = PGAPI_DriverConnect(hdbc, hwnd, szIn, (SWORD) inlen,
		szOut, cbConnStrOutMax, &olen, fDriverCompletion);
	if (ret != SQL_ERROR)
	{
		UInt4 outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
		if (pcbConnStrOut)
			*pcbConnStrOut = outlen;
	}
	free(szOut);
	if (szIn);
		free(szIn);
	return ret;
}
RETCODE SQL_API SQLBrowseConnectW(
    HDBC            hdbc,
    SQLWCHAR 		  *szConnStrIn,
    SQLSMALLINT        cbConnStrIn,
    SQLWCHAR 		  *szConnStrOut,
    SQLSMALLINT        cbConnStrOutMax,
    SQLSMALLINT       *pcbConnStrOut)
{
	char	*szIn, *szOut;
	UInt4	inlen, obuflen;
	SWORD	olen;
	RETCODE	ret;

	mylog("[SQLBrowseConnectW]");
	((ConnectionClass *) hdbc)->unicode = 1;
	szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen);
	obuflen = cbConnStrOutMax + 1;
	szOut = malloc(obuflen);
	ret = PGAPI_BrowseConnect(hdbc, szIn, (SWORD) inlen,
		szOut, cbConnStrOutMax, &olen);
	if (ret != SQL_ERROR)
	{
		UInt4	outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax);
		if (pcbConnStrOut)
			*pcbConnStrOut = outlen;
	}
	free(szOut);
	if (szIn);
		free(szIn);
	return ret;
}

RETCODE  SQL_API SQLDataSourcesW(HENV EnvironmentHandle,
           SQLUSMALLINT Direction, SQLWCHAR *ServerName,
           SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1,
           SQLWCHAR *Description, SQLSMALLINT BufferLength2,
           SQLSMALLINT *NameLength2)
{
	mylog("[SQLDataSourcesW]");
	/*
	return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
		 BufferLength1, NameLength1, Description, BufferLength2,
           	NameLength2);
	*/
	return SQL_ERROR;
}

RETCODE  SQL_API SQLDescribeColW(HSTMT StatementHandle,
           SQLUSMALLINT ColumnNumber, SQLWCHAR *ColumnName,
           SQLSMALLINT BufferLength, SQLSMALLINT *NameLength,
           SQLSMALLINT *DataType, SQLUINTEGER *ColumnSize,
           SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
{
	RETCODE	ret;
	SWORD	buflen, nmlen;
	char	*clName;

	mylog("[SQLDescribeColW]");
	buflen = BufferLength * 3 + 1;
	clName = malloc(buflen);
	ret = PGAPI_DescribeCol(StatementHandle, ColumnNumber,
		clName, buflen, &nmlen, DataType, ColumnSize,
		DecimalDigits, Nullable);
	if (ret == SQL_SUCCESS)
	{
		UInt4	nmcount = utf8_to_ucs2(clName, nmlen, ColumnName, BufferLength);
		if (nmcount > (UInt4) BufferLength)
		{
			StatementClass	*stmt = (StatementClass *) StatementHandle;
			ret = SQL_SUCCESS_WITH_INFO;
			stmt->errornumber = STMT_TRUNCATED;
			stmt->errormsg = "Column name too large";
		}
		if (NameLength)
			*NameLength = nmcount;
	}
	free(clName); 
	return ret;
}

RETCODE  SQL_API SQLExecDirectW(HSTMT StatementHandle,
           SQLWCHAR *StatementText, SQLINTEGER TextLength)
{
	RETCODE	ret;
	char	*stxt;
	UInt4	slen;

	mylog("[SQLExecDirectW]");
	stxt = ucs2_to_utf8(StatementText, TextLength, &slen);
	ret = PGAPI_ExecDirect(StatementHandle, stxt, slen);
	if (stxt);
		free(stxt);
	return ret;
}

RETCODE  SQL_API SQLGetCursorNameW(HSTMT StatementHandle,
           SQLWCHAR *CursorName, SQLSMALLINT BufferLength,
           SQLSMALLINT *NameLength)
{
	RETCODE	ret;
	char	*crName;
	SWORD	clen, buflen;

	mylog("[SQLGetCursorNameW]");
	buflen = BufferLength * 3 + 1;
	crName = malloc(buflen);
	ret = PGAPI_GetCursorName(StatementHandle, crName, buflen, &clen);
	if (ret == SQL_SUCCESS)	
	{
		UInt4	nmcount = utf8_to_ucs2(crName, (Int4) clen, CursorName, BufferLength);
		if (nmcount > (UInt4) BufferLength)
		{
			StatementClass *stmt = (StatementClass *) StatementHandle;
			ret = SQL_SUCCESS_WITH_INFO;
			stmt->errornumber = STMT_TRUNCATED;
			stmt->errormsg = "Cursor name too large";
		}
		if (NameLength)
			*NameLength = utf8_to_ucs2(crName, (Int4) clen, CursorName, BufferLength);
	}
	free(crName);
	return ret;
}

RETCODE  SQL_API SQLGetInfoW(HDBC ConnectionHandle,
           SQLUSMALLINT InfoType, PTR InfoValue,
           SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
{
	ConnectionClass	*conn = (ConnectionClass *) ConnectionHandle;
	RETCODE	ret;

	conn->unicode = 1;
	CC_clear_error(conn);
#if (ODBCVER >= 0x0300)
	mylog("[SQLGetInfoW(30)]");
	if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
           	BufferLength, StringLength)) == SQL_ERROR)
	{
		if (conn->driver_version >= 0x0300)
		{
			CC_clear_error(conn);
			ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
           			BufferLength, StringLength);
		}
	}
	if (SQL_ERROR == ret)
		CC_log_error("SQLGetInfoW(30)", "", conn);
#else
	mylog("[SQLGetInfoW]");
	ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
           	BufferLength, StringLength);
	if (SQL_ERROR == ret)
		CC_log_error("SQLGetInfoW", "", conn);
#endif
	return ret;
}

RETCODE  SQL_API SQLPrepareW(HSTMT StatementHandle,
           SQLWCHAR *StatementText, SQLINTEGER TextLength)
{
	RETCODE	ret;
	char	*stxt;
	UInt4	slen;

	mylog("[SQLPrepareW]");
	stxt = ucs2_to_utf8(StatementText, TextLength, &slen);
	ret = PGAPI_Prepare(StatementHandle, stxt, slen);
	if (stxt);
		free(stxt);
	return ret;
}

RETCODE  SQL_API SQLSetCursorNameW(HSTMT StatementHandle,
           SQLWCHAR *CursorName, SQLSMALLINT NameLength)
{
	RETCODE	ret;
	char	*crName;
	UInt4	nlen;

	mylog("[SQLSetCursorNameW]");
	crName = ucs2_to_utf8(CursorName, NameLength, &nlen);
	ret = PGAPI_SetCursorName(StatementHandle, crName, (SWORD) nlen);
	if (crName);
		free(crName);
	return ret;
}

RETCODE  SQL_API SQLSpecialColumnsW(HSTMT StatementHandle,
           SQLUSMALLINT IdentifierType, SQLWCHAR *CatalogName,
           SQLSMALLINT NameLength1, SQLWCHAR *SchemaName,
           SQLSMALLINT NameLength2, SQLWCHAR *TableName,
           SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
           SQLUSMALLINT Nullable)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName;
	UInt4	nmlen1, nmlen2, nmlen3;
	
	mylog("[SQLSpecialColumnsW]");
	ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1);
	scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2);
	tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3);
	ret = PGAPI_SpecialColumns(StatementHandle, IdentifierType, ctName,
           (SWORD) nmlen1, scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3,
		Scope, Nullable);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	return ret;
}

RETCODE  SQL_API SQLStatisticsW(HSTMT StatementHandle,
           SQLWCHAR *CatalogName, SQLSMALLINT NameLength1,
           SQLWCHAR *SchemaName, SQLSMALLINT NameLength2,
           SQLWCHAR *TableName, SQLSMALLINT NameLength3,
           SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName;
	UInt4	nmlen1, nmlen2, nmlen3;

	mylog("[SQLStatisticsW]");
	ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1);
	scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2);
	tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3);
	return PGAPI_Statistics(StatementHandle, ctName, (SWORD) nmlen1,
           scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3, Unique,
		Reserved);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	return ret;
}

RETCODE  SQL_API SQLTablesW(HSTMT StatementHandle,
           SQLWCHAR *CatalogName, SQLSMALLINT NameLength1,
           SQLWCHAR *SchemaName, SQLSMALLINT NameLength2,
           SQLWCHAR *TableName, SQLSMALLINT NameLength3,
           SQLWCHAR *TableType, SQLSMALLINT NameLength4)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName, *tbType;
	UInt4	nmlen1, nmlen2, nmlen3, nmlen4;

	mylog("[SQLTablesW]");
	ctName = ucs2_to_utf8(CatalogName, NameLength1, &nmlen1);
	scName = ucs2_to_utf8(SchemaName, NameLength2, &nmlen2);
	tbName = ucs2_to_utf8(TableName, NameLength3, &nmlen3);
	tbType = ucs2_to_utf8(TableType, NameLength4, &nmlen4);
	return PGAPI_Tables(StatementHandle, ctName, (SWORD) nmlen1,
           scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3,
           tbType, (SWORD) nmlen4);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	if (tbType);
		free(tbType);
	return ret;
}

RETCODE SQL_API SQLColumnPrivilegesW(
    HSTMT           hstmt,
    SQLWCHAR 		  *szCatalogName,
    SQLSMALLINT        cbCatalogName,
    SQLWCHAR 		  *szSchemaName,
    SQLSMALLINT        cbSchemaName,
    SQLWCHAR 		  *szTableName,
    SQLSMALLINT        cbTableName,
    SQLWCHAR 		  *szColumnName,
    SQLSMALLINT        cbColumnName)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName, *clName;
	UInt4	nmlen1, nmlen2, nmlen3, nmlen4;

	mylog("[SQLColumnPrivilegesW]");
	ctName = ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1);
	scName = ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2);
	tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3);
	clName = ucs2_to_utf8(szColumnName, cbColumnName, &nmlen4);
	ret = PGAPI_ColumnPrivileges(hstmt, ctName, (SWORD) nmlen1,
		scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3,
		clName, (SWORD) nmlen4);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	if (clName);
		free(clName);
	return ret;
}

RETCODE SQL_API SQLForeignKeysW(
    HSTMT           hstmt,
    SQLWCHAR 		  *szPkCatalogName,
    SQLSMALLINT        cbPkCatalogName,
    SQLWCHAR 		  *szPkSchemaName,
    SQLSMALLINT        cbPkSchemaName,
    SQLWCHAR 		  *szPkTableName,
    SQLSMALLINT        cbPkTableName,
    SQLWCHAR 		  *szFkCatalogName,
    SQLSMALLINT        cbFkCatalogName,
    SQLWCHAR 		  *szFkSchemaName,
    SQLSMALLINT        cbFkSchemaName,
    SQLWCHAR 		  *szFkTableName,
    SQLSMALLINT        cbFkTableName)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName, *fkctName, *fkscName, *fktbName;
	UInt4	nmlen1, nmlen2, nmlen3, nmlen4, nmlen5, nmlen6;

	mylog("[SQLForeignKeysW]");
	ctName = ucs2_to_utf8(szPkCatalogName, cbPkCatalogName, &nmlen1);
	scName = ucs2_to_utf8(szPkSchemaName, cbPkSchemaName, &nmlen2);
	tbName = ucs2_to_utf8(szPkTableName, cbPkTableName, &nmlen3);
	fkctName = ucs2_to_utf8(szFkCatalogName, cbFkCatalogName, &nmlen4);
	fkscName = ucs2_to_utf8(szFkSchemaName, cbFkSchemaName, &nmlen5);
	fktbName = ucs2_to_utf8(szFkTableName, cbFkTableName, &nmlen6);
	ret = PGAPI_ForeignKeys(hstmt, ctName, (SWORD) nmlen1,
		scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3,
		fkctName, (SWORD) nmlen4, fkscName, (SWORD) nmlen5,
		fktbName, (SWORD) nmlen6);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	if (fkctName);
		free(fkctName);
	if (fkscName);
		free(fkscName);
	if (fktbName);
		free(fktbName);
	return ret;
}

RETCODE SQL_API SQLNativeSqlW(
    HDBC            hdbc,
    SQLWCHAR 		  *szSqlStrIn,
    SQLINTEGER         cbSqlStrIn,
    SQLWCHAR 		  *szSqlStr,
    SQLINTEGER         cbSqlStrMax,
    SQLINTEGER 		  *pcbSqlStr)
{
	RETCODE		ret;
	char		*szIn, *szOut;
	UInt4		slen;
	SQLINTEGER	buflen, olen;

	mylog("[SQLNativeSqlW]");
	((ConnectionClass *) hdbc)->unicode = 1;
	szIn = ucs2_to_utf8(szSqlStrIn, cbSqlStrIn, &slen);
	buflen = 3 * cbSqlStrMax + 1;
	szOut = malloc(buflen);
	ret = PGAPI_NativeSql(hdbc, szIn, (SQLINTEGER) slen,
		szOut, buflen, &olen);
	if (szIn);
		free(szIn);
	if (ret == SQL_SUCCESS)
	{
		UInt4	szcount = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax);
		if (szcount > (UInt4) cbSqlStrMax)
		{
			ConnectionClass	*conn = (ConnectionClass *) hdbc;

			ret = SQL_SUCCESS_WITH_INFO;
			conn->errornumber = CONN_TRUNCATED;
			conn->errormsg = "Sql string too large";
		}
		if (pcbSqlStr)
			*pcbSqlStr = szcount;
	}
	free(szOut);
	return ret;
}

RETCODE SQL_API SQLPrimaryKeysW(
    HSTMT           hstmt,
    SQLWCHAR 		  *szCatalogName,
    SQLSMALLINT        cbCatalogName,
    SQLWCHAR 		  *szSchemaName,
    SQLSMALLINT        cbSchemaName,
    SQLWCHAR 		  *szTableName,
    SQLSMALLINT        cbTableName)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName;
	UInt4	nmlen1, nmlen2, nmlen3;

	mylog("[SQLPrimaryKeysW]");
	ctName = ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1);
	scName = ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2);
	tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3);
	return PGAPI_PrimaryKeys(hstmt, ctName, (SWORD) nmlen1,
		scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	return ret;
}

RETCODE SQL_API SQLProcedureColumnsW(
    HSTMT           hstmt,
    SQLWCHAR 		  *szCatalogName,
    SQLSMALLINT        cbCatalogName,
    SQLWCHAR 		  *szSchemaName,
    SQLSMALLINT        cbSchemaName,
    SQLWCHAR 		  *szProcName,
    SQLSMALLINT        cbProcName,
    SQLWCHAR 		  *szColumnName,
    SQLSMALLINT        cbColumnName)
{
	RETCODE	ret;
	char	*ctName, *scName, *prName, *clName;
	UInt4	nmlen1, nmlen2, nmlen3, nmlen4;

	mylog("[SQLProcedureColumnsW]");
	ctName = ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1);
	scName = ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2);
	prName = ucs2_to_utf8(szProcName, cbProcName, &nmlen3);
	clName = ucs2_to_utf8(szColumnName, cbColumnName, &nmlen4);
	ret = PGAPI_ProcedureColumns(hstmt, ctName, (SWORD) nmlen1,
		scName, (SWORD) nmlen2, prName, (SWORD) nmlen3,
		clName, (SWORD) nmlen4);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (prName);
		free(prName);
	if (clName);
		free(clName);
	return ret;
}

RETCODE SQL_API SQLProceduresW(
    HSTMT           hstmt,
    SQLWCHAR 		  *szCatalogName,
    SQLSMALLINT        cbCatalogName,
    SQLWCHAR 		  *szSchemaName,
    SQLSMALLINT        cbSchemaName,
    SQLWCHAR 		  *szProcName,
    SQLSMALLINT        cbProcName)
{
	RETCODE	ret;
	char	*ctName, *scName, *prName;
	UInt4	nmlen1, nmlen2, nmlen3;

	mylog("[SQLProceduresW]");
	ctName = ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1);
	scName = ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2);
	prName = ucs2_to_utf8(szProcName, cbProcName, &nmlen3);
	ret = PGAPI_Procedures(hstmt, ctName, (SWORD) nmlen1,
		scName, (SWORD) nmlen2, prName, (SWORD) nmlen3);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (prName);
		free(prName);
	return ret;
}

RETCODE SQL_API SQLTablePrivilegesW(
    HSTMT           hstmt,
    SQLWCHAR 		  *szCatalogName,
    SQLSMALLINT        cbCatalogName,
    SQLWCHAR 		  *szSchemaName,
    SQLSMALLINT        cbSchemaName,
    SQLWCHAR 		  *szTableName,
    SQLSMALLINT        cbTableName)
{
	RETCODE	ret;
	char	*ctName, *scName, *tbName;
	UInt4	nmlen1, nmlen2, nmlen3;

	mylog("[SQLTablePrivilegesW]");
	ctName = ucs2_to_utf8(szCatalogName, cbCatalogName, &nmlen1);
	scName = ucs2_to_utf8(szSchemaName, cbSchemaName, &nmlen2);
	tbName = ucs2_to_utf8(szTableName, cbTableName, &nmlen3);
	ret = PGAPI_TablePrivileges(hstmt, ctName, (SWORD) nmlen1,
		scName, (SWORD) nmlen2, tbName, (SWORD) nmlen3, 0);
	if (ctName);
		free(ctName);
	if (scName);
		free(scName);
	if (tbName);
		free(tbName);
	return ret;
}

RETCODE SQL_API	SQLGetTypeInfoW(
		SQLHSTMT	StatementHandle,
		SQLSMALLINT	DataType)
{
	return PGAPI_GetTypeInfo(StatementHandle, DataType);
}