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

SQLGetDiagField

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

シグネチャ

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLGetDiagField(
    SHORT HandleType,
    void* Handle,
    SHORT RecNumber,
    SHORT DiagIdentifier,
    void* DiagInfo,   // optional
    SHORT BufferLength,
    SHORT* StringLength   // optional
);

パラメーター

名前方向
HandleTypeSHORTin
Handlevoid*inout
RecNumberSHORTin
DiagIdentifierSHORTin
DiagInfovoid*outoptional
BufferLengthSHORTin
StringLengthSHORT*outoptional

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLGetDiagField(
    SHORT HandleType,
    void* Handle,
    SHORT RecNumber,
    SHORT DiagIdentifier,
    void* DiagInfo,   // optional
    SHORT BufferLength,
    SHORT* StringLength   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLGetDiagField(
    short HandleType,   // SHORT
    IntPtr Handle,   // void* in/out
    short RecNumber,   // SHORT
    short DiagIdentifier,   // SHORT
    IntPtr DiagInfo,   // void* optional, out
    short BufferLength,   // SHORT
    IntPtr StringLength   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLGetDiagField(
    HandleType As Short,   ' SHORT
    Handle As IntPtr,   ' void* in/out
    RecNumber As Short,   ' SHORT
    DiagIdentifier As Short,   ' SHORT
    DiagInfo As IntPtr,   ' void* optional, out
    BufferLength As Short,   ' SHORT
    StringLength As IntPtr   ' SHORT* optional, out
) As Short
End Function
' HandleType : SHORT
' Handle : void* in/out
' RecNumber : SHORT
' DiagIdentifier : SHORT
' DiagInfo : void* optional, out
' BufferLength : SHORT
' StringLength : SHORT* optional, out
Declare PtrSafe Function SQLGetDiagField Lib "odbc32" ( _
    ByVal HandleType As Integer, _
    ByVal Handle As LongPtr, _
    ByVal RecNumber As Integer, _
    ByVal DiagIdentifier As Integer, _
    ByVal DiagInfo As LongPtr, _
    ByVal BufferLength As Integer, _
    ByVal StringLength As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLGetDiagField = ctypes.windll.odbc32.SQLGetDiagField
SQLGetDiagField.restype = ctypes.c_short
SQLGetDiagField.argtypes = [
    ctypes.c_short,  # HandleType : SHORT
    ctypes.POINTER(None),  # Handle : void* in/out
    ctypes.c_short,  # RecNumber : SHORT
    ctypes.c_short,  # DiagIdentifier : SHORT
    ctypes.POINTER(None),  # DiagInfo : void* optional, out
    ctypes.c_short,  # BufferLength : SHORT
    ctypes.POINTER(ctypes.c_short),  # StringLength : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDiagField = Fiddle::Function.new(
  lib['SQLGetDiagField'],
  [
    Fiddle::TYPE_SHORT,  # HandleType : SHORT
    Fiddle::TYPE_VOIDP,  # Handle : void* in/out
    Fiddle::TYPE_SHORT,  # RecNumber : SHORT
    Fiddle::TYPE_SHORT,  # DiagIdentifier : SHORT
    Fiddle::TYPE_VOIDP,  # DiagInfo : void* optional, out
    Fiddle::TYPE_SHORT,  # BufferLength : SHORT
    Fiddle::TYPE_VOIDP,  # StringLength : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLGetDiagField(
        HandleType: i16,  // SHORT
        Handle: *mut (),  // void* in/out
        RecNumber: i16,  // SHORT
        DiagIdentifier: i16,  // SHORT
        DiagInfo: *mut (),  // void* optional, out
        BufferLength: i16,  // SHORT
        StringLength: *mut i16  // SHORT* optional, out
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLGetDiagField(short HandleType, IntPtr Handle, short RecNumber, short DiagIdentifier, IntPtr DiagInfo, short BufferLength, IntPtr StringLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDiagField' -Namespace Win32 -PassThru
# $api::SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
#uselib "ODBC32.dll"
#func global SQLGetDiagField "SQLGetDiagField" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLGetDiagField HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, varptr(StringLength)   ; 戻り値は stat
; HandleType : SHORT -> "sptr"
; Handle : void* in/out -> "sptr"
; RecNumber : SHORT -> "sptr"
; DiagIdentifier : SHORT -> "sptr"
; DiagInfo : void* optional, out -> "sptr"
; BufferLength : SHORT -> "sptr"
; StringLength : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagField "SQLGetDiagField" int, sptr, int, int, sptr, int, var
; res = SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
; HandleType : SHORT -> "int"
; Handle : void* in/out -> "sptr"
; RecNumber : SHORT -> "int"
; DiagIdentifier : SHORT -> "int"
; DiagInfo : void* optional, out -> "sptr"
; BufferLength : SHORT -> "int"
; StringLength : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLGetDiagField(SHORT HandleType, void* Handle, SHORT RecNumber, SHORT DiagIdentifier, void* DiagInfo, SHORT BufferLength, SHORT* StringLength)
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagField "SQLGetDiagField" int, intptr, int, int, intptr, int, var
; res = SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
; HandleType : SHORT -> "int"
; Handle : void* in/out -> "intptr"
; RecNumber : SHORT -> "int"
; DiagIdentifier : SHORT -> "int"
; DiagInfo : void* optional, out -> "intptr"
; BufferLength : SHORT -> "int"
; StringLength : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetDiagField = odbc32.NewProc("SQLGetDiagField")
)

// HandleType (SHORT), Handle (void* in/out), RecNumber (SHORT), DiagIdentifier (SHORT), DiagInfo (void* optional, out), BufferLength (SHORT), StringLength (SHORT* optional, out)
r1, _, err := procSQLGetDiagField.Call(
	uintptr(HandleType),
	uintptr(Handle),
	uintptr(RecNumber),
	uintptr(DiagIdentifier),
	uintptr(DiagInfo),
	uintptr(BufferLength),
	uintptr(StringLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLGetDiagField(
  HandleType: Smallint;   // SHORT
  Handle: Pointer;   // void* in/out
  RecNumber: Smallint;   // SHORT
  DiagIdentifier: Smallint;   // SHORT
  DiagInfo: Pointer;   // void* optional, out
  BufferLength: Smallint;   // SHORT
  StringLength: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDiagField';
result := DllCall("ODBC32\SQLGetDiagField"
    , "Short", HandleType   ; SHORT
    , "Ptr", Handle   ; void* in/out
    , "Short", RecNumber   ; SHORT
    , "Short", DiagIdentifier   ; SHORT
    , "Ptr", DiagInfo   ; void* optional, out
    , "Short", BufferLength   ; SHORT
    , "Ptr", StringLength   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength) = DLL("ODBC32.dll", "int SQLGetDiagField(int, void*, int, int, void*, int, void*)")
# 呼び出し: SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
# HandleType : SHORT -> "int"
# Handle : void* in/out -> "void*"
# RecNumber : SHORT -> "int"
# DiagIdentifier : SHORT -> "int"
# DiagInfo : void* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# StringLength : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。