Win32 API 日本語リファレンス
ホームSystem.Search › SQLGetDiagFieldW

SQLGetDiagFieldW

関数
診断レコードの指定フィールド値を取得する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLGetDiagFieldW(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    SHORT fDiagField,
    void* rgbDiagInfo,   // optional
    SHORT cbBufferLength,
    SHORT* pcbStringLength   // optional
);

パラメーター

名前方向説明
fHandleTypeSHORTin診断情報を取得するハンドルの種別。SQL_HANDLE_*を指定する。
handlevoid*inout診断情報の対象となるハンドル。
iRecordSHORTin取得する診断レコード番号。1始まりで指定する。
fDiagFieldSHORTin取得する診断フィールドのID。SQL_DIAG_*定数を指定する。
rgbDiagInfovoid*outoptional診断情報を受け取るバッファ。文字列はUnicode。
cbBufferLengthSHORTinrgbDiagInfoバッファのバイト長。文字列フィールドで意味を持つ。
pcbStringLengthSHORT*outoptional実際に書き込まれたバイト数を受け取るポインタ。NULL可。

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLGetDiagFieldW(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    SHORT fDiagField,
    void* rgbDiagInfo,   // optional
    SHORT cbBufferLength,
    SHORT* pcbStringLength   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLGetDiagFieldW(
    short fHandleType,   // SHORT
    IntPtr handle,   // void* in/out
    short iRecord,   // SHORT
    short fDiagField,   // SHORT
    IntPtr rgbDiagInfo,   // void* optional, out
    short cbBufferLength,   // SHORT
    IntPtr pcbStringLength   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLGetDiagFieldW(
    fHandleType As Short,   ' SHORT
    handle As IntPtr,   ' void* in/out
    iRecord As Short,   ' SHORT
    fDiagField As Short,   ' SHORT
    rgbDiagInfo As IntPtr,   ' void* optional, out
    cbBufferLength As Short,   ' SHORT
    pcbStringLength As IntPtr   ' SHORT* optional, out
) As Short
End Function
' fHandleType : SHORT
' handle : void* in/out
' iRecord : SHORT
' fDiagField : SHORT
' rgbDiagInfo : void* optional, out
' cbBufferLength : SHORT
' pcbStringLength : SHORT* optional, out
Declare PtrSafe Function SQLGetDiagFieldW Lib "odbc32" ( _
    ByVal fHandleType As Integer, _
    ByVal handle As LongPtr, _
    ByVal iRecord As Integer, _
    ByVal fDiagField As Integer, _
    ByVal rgbDiagInfo As LongPtr, _
    ByVal cbBufferLength As Integer, _
    ByVal pcbStringLength As LongPtr) As Integer
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLGetDiagFieldW = ctypes.windll.odbc32.SQLGetDiagFieldW
SQLGetDiagFieldW.restype = ctypes.c_short
SQLGetDiagFieldW.argtypes = [
    ctypes.c_short,  # fHandleType : SHORT
    ctypes.POINTER(None),  # handle : void* in/out
    ctypes.c_short,  # iRecord : SHORT
    ctypes.c_short,  # fDiagField : SHORT
    ctypes.POINTER(None),  # rgbDiagInfo : void* optional, out
    ctypes.c_short,  # cbBufferLength : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbStringLength : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDiagFieldW = Fiddle::Function.new(
  lib['SQLGetDiagFieldW'],
  [
    Fiddle::TYPE_SHORT,  # fHandleType : SHORT
    Fiddle::TYPE_VOIDP,  # handle : void* in/out
    Fiddle::TYPE_SHORT,  # iRecord : SHORT
    Fiddle::TYPE_SHORT,  # fDiagField : SHORT
    Fiddle::TYPE_VOIDP,  # rgbDiagInfo : void* optional, out
    Fiddle::TYPE_SHORT,  # cbBufferLength : SHORT
    Fiddle::TYPE_VOIDP,  # pcbStringLength : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "odbc32")]
extern "system" {
    fn SQLGetDiagFieldW(
        fHandleType: i16,  // SHORT
        handle: *mut (),  // void* in/out
        iRecord: i16,  // SHORT
        fDiagField: i16,  // SHORT
        rgbDiagInfo: *mut (),  // void* optional, out
        cbBufferLength: i16,  // SHORT
        pcbStringLength: *mut i16  // SHORT* optional, out
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode)]
public static extern short SQLGetDiagFieldW(short fHandleType, IntPtr handle, short iRecord, short fDiagField, IntPtr rgbDiagInfo, short cbBufferLength, IntPtr pcbStringLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDiagFieldW' -Namespace Win32 -PassThru
# $api::SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
#uselib "ODBC32.dll"
#func global SQLGetDiagFieldW "SQLGetDiagFieldW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SQLGetDiagFieldW fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, varptr(pcbStringLength)   ; 戻り値は stat
; fHandleType : SHORT -> "wptr"
; handle : void* in/out -> "wptr"
; iRecord : SHORT -> "wptr"
; fDiagField : SHORT -> "wptr"
; rgbDiagInfo : void* optional, out -> "wptr"
; cbBufferLength : SHORT -> "wptr"
; pcbStringLength : SHORT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagFieldW "SQLGetDiagFieldW" int, sptr, int, int, sptr, int, var
; res = SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
; fHandleType : SHORT -> "int"
; handle : void* in/out -> "sptr"
; iRecord : SHORT -> "int"
; fDiagField : SHORT -> "int"
; rgbDiagInfo : void* optional, out -> "sptr"
; cbBufferLength : SHORT -> "int"
; pcbStringLength : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLGetDiagFieldW(SHORT fHandleType, void* handle, SHORT iRecord, SHORT fDiagField, void* rgbDiagInfo, SHORT cbBufferLength, SHORT* pcbStringLength)
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagFieldW "SQLGetDiagFieldW" int, intptr, int, int, intptr, int, var
; res = SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
; fHandleType : SHORT -> "int"
; handle : void* in/out -> "intptr"
; iRecord : SHORT -> "int"
; fDiagField : SHORT -> "int"
; rgbDiagInfo : void* optional, out -> "intptr"
; cbBufferLength : SHORT -> "int"
; pcbStringLength : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetDiagFieldW = odbc32.NewProc("SQLGetDiagFieldW")
)

// fHandleType (SHORT), handle (void* in/out), iRecord (SHORT), fDiagField (SHORT), rgbDiagInfo (void* optional, out), cbBufferLength (SHORT), pcbStringLength (SHORT* optional, out)
r1, _, err := procSQLGetDiagFieldW.Call(
	uintptr(fHandleType),
	uintptr(handle),
	uintptr(iRecord),
	uintptr(fDiagField),
	uintptr(rgbDiagInfo),
	uintptr(cbBufferLength),
	uintptr(pcbStringLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLGetDiagFieldW(
  fHandleType: Smallint;   // SHORT
  handle: Pointer;   // void* in/out
  iRecord: Smallint;   // SHORT
  fDiagField: Smallint;   // SHORT
  rgbDiagInfo: Pointer;   // void* optional, out
  cbBufferLength: Smallint;   // SHORT
  pcbStringLength: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDiagFieldW';
result := DllCall("ODBC32\SQLGetDiagFieldW"
    , "Short", fHandleType   ; SHORT
    , "Ptr", handle   ; void* in/out
    , "Short", iRecord   ; SHORT
    , "Short", fDiagField   ; SHORT
    , "Ptr", rgbDiagInfo   ; void* optional, out
    , "Short", cbBufferLength   ; SHORT
    , "Ptr", pcbStringLength   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength) = DLL("ODBC32.dll", "int SQLGetDiagFieldW(int, void*, int, int, void*, int, void*)")
# 呼び出し: SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
# fHandleType : SHORT -> "int"
# handle : void* in/out -> "void*"
# iRecord : SHORT -> "int"
# fDiagField : SHORT -> "int"
# rgbDiagInfo : void* optional, out -> "void*"
# cbBufferLength : SHORT -> "int"
# pcbStringLength : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "odbc32" fn SQLGetDiagFieldW(
    fHandleType: i16, // SHORT
    handle: ?*anyopaque, // void* in/out
    iRecord: i16, // SHORT
    fDiagField: i16, // SHORT
    rgbDiagInfo: ?*anyopaque, // void* optional, out
    cbBufferLength: i16, // SHORT
    pcbStringLength: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SQLGetDiagFieldW(
    fHandleType: int16,  # SHORT
    handle: pointer,  # void* in/out
    iRecord: int16,  # SHORT
    fDiagField: int16,  # SHORT
    rgbDiagInfo: pointer,  # void* optional, out
    cbBufferLength: int16,  # SHORT
    pcbStringLength: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLGetDiagFieldW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "odbc32");
extern(Windows)
short SQLGetDiagFieldW(
    short fHandleType,   // SHORT
    void* handle,   // void* in/out
    short iRecord,   // SHORT
    short fDiagField,   // SHORT
    void* rgbDiagInfo,   // void* optional, out
    short cbBufferLength,   // SHORT
    short* pcbStringLength   // SHORT* optional, out
);
ccall((:SQLGetDiagFieldW, "ODBC32.dll"), stdcall, Int16,
      (Int16, Ptr{Cvoid}, Int16, Int16, Ptr{Cvoid}, Int16, Ptr{Int16}),
      fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
# fHandleType : SHORT -> Int16
# handle : void* in/out -> Ptr{Cvoid}
# iRecord : SHORT -> Int16
# fDiagField : SHORT -> Int16
# rgbDiagInfo : void* optional, out -> Ptr{Cvoid}
# cbBufferLength : SHORT -> Int16
# pcbStringLength : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetDiagFieldW(
    int16_t fHandleType,
    void* handle,
    int16_t iRecord,
    int16_t fDiagField,
    void* rgbDiagInfo,
    int16_t cbBufferLength,
    int16_t* pcbStringLength);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
-- fHandleType : SHORT
-- handle : void* in/out
-- iRecord : SHORT
-- fDiagField : SHORT
-- rgbDiagInfo : void* optional, out
-- cbBufferLength : SHORT
-- pcbStringLength : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetDiagFieldW = lib.func('__stdcall', 'SQLGetDiagFieldW', 'int16_t', ['int16_t', 'void *', 'int16_t', 'int16_t', 'void *', 'int16_t', 'int16_t *']);
// SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
// fHandleType : SHORT -> 'int16_t'
// handle : void* in/out -> 'void *'
// iRecord : SHORT -> 'int16_t'
// fDiagField : SHORT -> 'int16_t'
// rgbDiagInfo : void* optional, out -> 'void *'
// cbBufferLength : SHORT -> 'int16_t'
// pcbStringLength : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLGetDiagFieldW: { parameters: ["i16", "pointer", "i16", "i16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength)
// fHandleType : SHORT -> "i16"
// handle : void* in/out -> "pointer"
// iRecord : SHORT -> "i16"
// fDiagField : SHORT -> "i16"
// rgbDiagInfo : void* optional, out -> "pointer"
// cbBufferLength : SHORT -> "i16"
// pcbStringLength : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetDiagFieldW(
    int16_t fHandleType,
    void* handle,
    int16_t iRecord,
    int16_t fDiagField,
    void* rgbDiagInfo,
    int16_t cbBufferLength,
    int16_t* pcbStringLength);
C, "ODBC32.dll");
// $ffi->SQLGetDiagFieldW(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbBufferLength, pcbStringLength);
// fHandleType : SHORT
// handle : void* in/out
// iRecord : SHORT
// fDiagField : SHORT
// rgbDiagInfo : void* optional, out
// cbBufferLength : SHORT
// pcbStringLength : SHORT* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Odbc32 extends StdCallLibrary {
    Odbc32 INSTANCE = Native.load("odbc32", Odbc32.class, W32APIOptions.UNICODE_OPTIONS);
    short SQLGetDiagFieldW(
        short fHandleType,   // SHORT
        Pointer handle,   // void* in/out
        short iRecord,   // SHORT
        short fDiagField,   // SHORT
        Pointer rgbDiagInfo,   // void* optional, out
        short cbBufferLength,   // SHORT
        ShortByReference pcbStringLength   // SHORT* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("odbc32")]
lib LibODBC32
  fun SQLGetDiagFieldW = SQLGetDiagFieldW(
    fHandleType : Int16,   # SHORT
    handle : Void*,   # void* in/out
    iRecord : Int16,   # SHORT
    fDiagField : Int16,   # SHORT
    rgbDiagInfo : Void*,   # void* optional, out
    cbBufferLength : Int16,   # SHORT
    pcbStringLength : Int16*   # SHORT* optional, out
  ) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SQLGetDiagFieldWNative = Int16 Function(Int16, Pointer<Void>, Int16, Int16, Pointer<Void>, Int16, Pointer<Int16>);
typedef SQLGetDiagFieldWDart = int Function(int, Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int16>);
final SQLGetDiagFieldW = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLGetDiagFieldWNative, SQLGetDiagFieldWDart>('SQLGetDiagFieldW');
// fHandleType : SHORT -> Int16
// handle : void* in/out -> Pointer<Void>
// iRecord : SHORT -> Int16
// fDiagField : SHORT -> Int16
// rgbDiagInfo : void* optional, out -> Pointer<Void>
// cbBufferLength : SHORT -> Int16
// pcbStringLength : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLGetDiagFieldW(
  fHandleType: Smallint;   // SHORT
  handle: Pointer;   // void* in/out
  iRecord: Smallint;   // SHORT
  fDiagField: Smallint;   // SHORT
  rgbDiagInfo: Pointer;   // void* optional, out
  cbBufferLength: Smallint;   // SHORT
  pcbStringLength: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDiagFieldW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLGetDiagFieldW"
  c_SQLGetDiagFieldW :: Int16 -> Ptr () -> Int16 -> Int16 -> Ptr () -> Int16 -> Ptr Int16 -> IO Int16
-- fHandleType : SHORT -> Int16
-- handle : void* in/out -> Ptr ()
-- iRecord : SHORT -> Int16
-- fDiagField : SHORT -> Int16
-- rgbDiagInfo : void* optional, out -> Ptr ()
-- cbBufferLength : SHORT -> Int16
-- pcbStringLength : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlgetdiagfieldw =
  foreign "SQLGetDiagFieldW"
    (int16_t @-> (ptr void) @-> int16_t @-> int16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* fHandleType : SHORT -> int16_t *)
(* handle : void* in/out -> (ptr void) *)
(* iRecord : SHORT -> int16_t *)
(* fDiagField : SHORT -> int16_t *)
(* rgbDiagInfo : void* optional, out -> (ptr void) *)
(* cbBufferLength : SHORT -> int16_t *)
(* pcbStringLength : SHORT* optional, out -> (ptr int16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLGetDiagFieldW" sqlget-diag-field-w :convention :stdcall) :int16
  (f-handle-type :int16)   ; SHORT
  (handle :pointer)   ; void* in/out
  (i-record :int16)   ; SHORT
  (f-diag-field :int16)   ; SHORT
  (rgb-diag-info :pointer)   ; void* optional, out
  (cb-buffer-length :int16)   ; SHORT
  (pcb-string-length :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLGetDiagFieldW = Win32::API::More->new('ODBC32',
    'short SQLGetDiagFieldW(short fHandleType, LPVOID handle, short iRecord, short fDiagField, LPVOID rgbDiagInfo, short cbBufferLength, LPVOID pcbStringLength)');
# my $ret = $SQLGetDiagFieldW->Call($fHandleType, $handle, $iRecord, $fDiagField, $rgbDiagInfo, $cbBufferLength, $pcbStringLength);
# fHandleType : SHORT -> short
# handle : void* in/out -> LPVOID
# iRecord : SHORT -> short
# fDiagField : SHORT -> short
# rgbDiagInfo : void* optional, out -> LPVOID
# cbBufferLength : SHORT -> short
# pcbStringLength : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い