コード例 #1
0
ファイル: SQLGetDiagRec.c プロジェクト: cswxu/monetdb-mcs
SQLRETURN SQL_API
SQLGetDiagRecW(SQLSMALLINT HandleType,
	       SQLHANDLE Handle,
	       SQLSMALLINT RecNumber,
	       SQLWCHAR *SQLState,
	       SQLINTEGER *NativeErrorPtr,
	       SQLWCHAR *MessageText,
	       SQLSMALLINT BufferLength,
	       SQLSMALLINT *TextLengthPtr)
{
	SQLRETURN rc;
	SQLCHAR state[6];
	SQLCHAR msg[512];
	SQLSMALLINT n;

#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagRecW %s " PTRFMT " %d %d\n",
		HandleType == SQL_HANDLE_ENV ? "Env" : HandleType == SQL_HANDLE_DBC ? "Dbc" : HandleType == SQL_HANDLE_STMT ? "Stmt" : "Desc",
		PTRFMTCAST Handle, (int) RecNumber, (int) BufferLength);
#endif


	rc = MNDBGetDiagRec(HandleType, Handle, RecNumber, state,
			    NativeErrorPtr, msg, (SQLSMALLINT) sizeof(msg), &n);
#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagRecW: %s\n", SQL_SUCCEEDED(rc) ? (char *) msg : rc == SQL_NO_DATA ? "no error" : "failed");
#endif

	if (SQL_SUCCEEDED(rc)) {
		char *e = ODBCutf82wchar(state, 5, SQLState, 6, NULL);

		if (e)
			rc = SQL_ERROR;
	}

	if (SQL_SUCCEEDED(rc)) {
		char *e = ODBCutf82wchar(msg, n, MessageText,
					 BufferLength, &n);

		if (e)
			rc = SQL_ERROR;
		if (TextLengthPtr)
			*TextLengthPtr = n;
	}

	return rc;
}
コード例 #2
0
ファイル: SQLGetDiagField.c プロジェクト: MonetDB/MonetDB
SQLRETURN SQL_API
SQLGetDiagFieldW(SQLSMALLINT HandleType,
		 SQLHANDLE Handle,
		 SQLSMALLINT RecNumber,
		 SQLSMALLINT DiagIdentifier,
		 SQLPOINTER DiagInfoPtr,
		 SQLSMALLINT BufferLength,
		 SQLSMALLINT *StringLengthPtr)
{
	SQLRETURN rc;
	SQLPOINTER ptr = NULL;
	SQLSMALLINT n;

#ifdef ODBCDEBUG
	ODBCLOG("SQLGetDiagFieldW %s %p %d %s %p %d %p\n",
		HandleType == SQL_HANDLE_ENV ? "Env" : HandleType == SQL_HANDLE_DBC ? "Dbc" : HandleType == SQL_HANDLE_STMT ? "Stmt" : "Desc",
		Handle, (int) RecNumber,
		translateDiagIdentifier(DiagIdentifier),
		DiagInfoPtr,
		(int) BufferLength, StringLengthPtr);
#endif

	switch (DiagIdentifier) {
		/* all string attributes */
	case SQL_DIAG_DYNAMIC_FUNCTION:
	case SQL_DIAG_CLASS_ORIGIN:
	case SQL_DIAG_CONNECTION_NAME:
	case SQL_DIAG_MESSAGE_TEXT:
	case SQL_DIAG_SERVER_NAME:
	case SQL_DIAG_SQLSTATE:
	case SQL_DIAG_SUBCLASS_ORIGIN:
		rc = MNDBGetDiagField(HandleType, Handle, RecNumber,
				      DiagIdentifier, NULL, 0, &n);
		if (!SQL_SUCCEEDED(rc))
			return rc;
		n++;		/* account for NUL byte */
		ptr = (SQLPOINTER) malloc(n);
		break;
	default:
		n = BufferLength;
		ptr = DiagInfoPtr;
		break;
	}

	rc = MNDBGetDiagField(HandleType, Handle, RecNumber,
			      DiagIdentifier, ptr, n, &n);
#ifdef ODBCDEBUG
	if (ptr != DiagInfoPtr)
		ODBCLOG("SQLGetDiagFieldW: %s\n", (char *) ptr);
#endif

	if (ptr != DiagInfoPtr) {
		if (SQL_SUCCEEDED(rc)) {
			const char *e = ODBCutf82wchar(ptr, n, DiagInfoPtr,
						       BufferLength / 2, &n,
						       NULL);

			if (e)
				rc = SQL_ERROR;
			if (StringLengthPtr)
				*StringLengthPtr = n * 2;
		}
		free(ptr);
	}

	return rc;
}