aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/odbc/odbcapi25w.c
blob: 47015a23220cf7275ae927829e7bd4f325bed996 (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
/*-------
 * Module:			odbcapi25w.c
 *
 * Description:		This module contains UNICODE routines
 *
 * Classes:			n/a
 *
 * API functions:	SQLColAttributesW, SQLErrorW, SQLGetConnectOptionW,
			SQLSetConnectOptionW
 *-------
 */

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

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

RETCODE  SQL_API SQLErrorW(HENV EnvironmentHandle,
           HDBC ConnectionHandle, HSTMT StatementHandle,
           SQLWCHAR *Sqlstate, SQLINTEGER *NativeError,
           SQLWCHAR *MessageText, SQLSMALLINT BufferLength,
           SQLSMALLINT *TextLength)
{
	RETCODE	ret;
	SWORD	tlen, buflen;
	char	*qst = NULL, *mtxt = NULL;

	mylog("[SQLErrorW]");
	if (Sqlstate)
		qst = malloc(8);
	buflen = 0;
	if (MessageText && BufferLength > 0)
	{
		buflen = BufferLength * 3 + 1;
		mtxt = malloc(buflen);
	}
	ret = PGAPI_Error(EnvironmentHandle, ConnectionHandle, StatementHandle,
           	qst, NativeError, mtxt, buflen, &tlen);
	if (qst)
		utf8_to_ucs2(qst, strlen(qst), Sqlstate, 5);
	if (TextLength)
		*TextLength = utf8_to_ucs2(mtxt, tlen, MessageText, BufferLength);
	free(qst);
	if (mtxt)
		free(mtxt);
	return ret;
}

RETCODE  SQL_API SQLGetConnectOptionW(HDBC ConnectionHandle,
           SQLUSMALLINT Option, PTR Value)
{
	mylog("[SQLGetConnectOptionW]");
	((ConnectionClass *) ConnectionHandle)->unicode = 1;
	return PGAPI_GetConnectOption(ConnectionHandle, Option, Value);
} 

RETCODE  SQL_API SQLSetConnectOptionW(HDBC ConnectionHandle,
           SQLUSMALLINT Option, SQLUINTEGER Value)
{
	mylog("[SQLSetConnectionOptionW]");
if (!ConnectionHandle)	return SQL_ERROR;
	((ConnectionClass *) ConnectionHandle)->unicode = 1;
	return PGAPI_SetConnectOption(ConnectionHandle, Option, Value);
}

RETCODE SQL_API SQLColAttributesW(
    HSTMT           hstmt,
    SQLUSMALLINT       icol,
    SQLUSMALLINT       fDescType,
    PTR         rgbDesc,
    SQLSMALLINT        cbDescMax,
    SQLSMALLINT 	  *pcbDesc,
    SQLINTEGER 		  *pfDesc)
{
	mylog("[SQLColAttributesW]");
	return PGAPI_ColAttributes(hstmt, icol, fDescType, rgbDesc,
		cbDescMax, pcbDesc, pfDesc);
}