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

SQLGetDiagRecW

関数
診断レコードのSQLState・エラー情報を取得する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

SHORT SQLGetDiagRecW(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    WORD* szSqlState,   // optional
    INT* pfNativeError,
    WORD* szErrorMsg,   // optional
    SHORT cchErrorMsgMax,
    SHORT* pcchErrorMsg
);

パラメーター

名前方向
fHandleTypeSHORTin
handlevoid*inout
iRecordSHORTin
szSqlStateWORD*outoptional
pfNativeErrorINT*inout
szErrorMsgWORD*outoptional
cchErrorMsgMaxSHORTin
pcchErrorMsgSHORT*inout

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLGetDiagRecW(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    WORD* szSqlState,   // optional
    INT* pfNativeError,
    WORD* szErrorMsg,   // optional
    SHORT cchErrorMsgMax,
    SHORT* pcchErrorMsg
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLGetDiagRecW(
    short fHandleType,   // SHORT
    IntPtr handle,   // void* in/out
    short iRecord,   // SHORT
    IntPtr szSqlState,   // WORD* optional, out
    ref int pfNativeError,   // INT* in/out
    IntPtr szErrorMsg,   // WORD* optional, out
    short cchErrorMsgMax,   // SHORT
    ref short pcchErrorMsg   // SHORT* in/out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLGetDiagRecW(
    fHandleType As Short,   ' SHORT
    handle As IntPtr,   ' void* in/out
    iRecord As Short,   ' SHORT
    szSqlState As IntPtr,   ' WORD* optional, out
    ByRef pfNativeError As Integer,   ' INT* in/out
    szErrorMsg As IntPtr,   ' WORD* optional, out
    cchErrorMsgMax As Short,   ' SHORT
    ByRef pcchErrorMsg As Short   ' SHORT* in/out
) As Short
End Function
' fHandleType : SHORT
' handle : void* in/out
' iRecord : SHORT
' szSqlState : WORD* optional, out
' pfNativeError : INT* in/out
' szErrorMsg : WORD* optional, out
' cchErrorMsgMax : SHORT
' pcchErrorMsg : SHORT* in/out
Declare PtrSafe Function SQLGetDiagRecW Lib "odbc32" ( _
    ByVal fHandleType As Integer, _
    ByVal handle As LongPtr, _
    ByVal iRecord As Integer, _
    ByVal szSqlState As LongPtr, _
    ByRef pfNativeError As Long, _
    ByVal szErrorMsg As LongPtr, _
    ByVal cchErrorMsgMax As Integer, _
    ByRef pcchErrorMsg As Integer) 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

SQLGetDiagRecW = ctypes.windll.odbc32.SQLGetDiagRecW
SQLGetDiagRecW.restype = ctypes.c_short
SQLGetDiagRecW.argtypes = [
    ctypes.c_short,  # fHandleType : SHORT
    ctypes.POINTER(None),  # handle : void* in/out
    ctypes.c_short,  # iRecord : SHORT
    ctypes.POINTER(ctypes.c_ushort),  # szSqlState : WORD* optional, out
    ctypes.POINTER(ctypes.c_int),  # pfNativeError : INT* in/out
    ctypes.POINTER(ctypes.c_ushort),  # szErrorMsg : WORD* optional, out
    ctypes.c_short,  # cchErrorMsgMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcchErrorMsg : SHORT* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetDiagRecW = odbc32.NewProc("SQLGetDiagRecW")
)

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