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

SQLGetDiagFieldA

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

シグネチャ

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

SHORT SQLGetDiagFieldA(
    SHORT fHandleType,
    void* handle,
    SHORT iRecord,
    SHORT fDiagField,
    void* rgbDiagInfo,   // optional
    SHORT cbDiagInfoMax,
    SHORT* pcbDiagInfo   // optional
);

パラメーター

名前方向説明
fHandleTypeSHORTinハンドル種別。SQL_HANDLE_ENV/DBC/STMT/DESCのいずれか。
handlevoid*inout診断情報を取得する対象ハンドル。
iRecordSHORTin診断レコード番号。1始まりで指定する。
fDiagFieldSHORTin取得する診断フィールド識別子。SQL_DIAG_*定数。
rgbDiagInfovoid*outoptional診断情報を受け取るバッファ。出力用。
cbDiagInfoMaxSHORTinrgbDiagInfoバッファのバイト長。
pcbDiagInfoSHORT*outoptional実際に返された診断情報のバイト長を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLGetDiagFieldA = ctypes.windll.odbc32.SQLGetDiagFieldA
SQLGetDiagFieldA.restype = ctypes.c_short
SQLGetDiagFieldA.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,  # cbDiagInfoMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbDiagInfo : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDiagFieldA = Fiddle::Function.new(
  lib['SQLGetDiagFieldA'],
  [
    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,  # cbDiagInfoMax : SHORT
    Fiddle::TYPE_VOIDP,  # pcbDiagInfo : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLGetDiagFieldA(
        fHandleType: i16,  // SHORT
        handle: *mut (),  // void* in/out
        iRecord: i16,  // SHORT
        fDiagField: i16,  // SHORT
        rgbDiagInfo: *mut (),  // void* optional, out
        cbDiagInfoMax: i16,  // SHORT
        pcbDiagInfo: *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 SQLGetDiagFieldA(short fHandleType, IntPtr handle, short iRecord, short fDiagField, IntPtr rgbDiagInfo, short cbDiagInfoMax, IntPtr pcbDiagInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDiagFieldA' -Namespace Win32 -PassThru
# $api::SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
#uselib "ODBC32.dll"
#func global SQLGetDiagFieldA "SQLGetDiagFieldA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLGetDiagFieldA fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, varptr(pcbDiagInfo)   ; 戻り値は stat
; fHandleType : SHORT -> "sptr"
; handle : void* in/out -> "sptr"
; iRecord : SHORT -> "sptr"
; fDiagField : SHORT -> "sptr"
; rgbDiagInfo : void* optional, out -> "sptr"
; cbDiagInfoMax : SHORT -> "sptr"
; pcbDiagInfo : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagFieldA "SQLGetDiagFieldA" int, sptr, int, int, sptr, int, var
; res = SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
; fHandleType : SHORT -> "int"
; handle : void* in/out -> "sptr"
; iRecord : SHORT -> "int"
; fDiagField : SHORT -> "int"
; rgbDiagInfo : void* optional, out -> "sptr"
; cbDiagInfoMax : SHORT -> "int"
; pcbDiagInfo : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLGetDiagFieldA(SHORT fHandleType, void* handle, SHORT iRecord, SHORT fDiagField, void* rgbDiagInfo, SHORT cbDiagInfoMax, SHORT* pcbDiagInfo)
#uselib "ODBC32.dll"
#cfunc global SQLGetDiagFieldA "SQLGetDiagFieldA" int, intptr, int, int, intptr, int, var
; res = SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
; fHandleType : SHORT -> "int"
; handle : void* in/out -> "intptr"
; iRecord : SHORT -> "int"
; fDiagField : SHORT -> "int"
; rgbDiagInfo : void* optional, out -> "intptr"
; cbDiagInfoMax : SHORT -> "int"
; pcbDiagInfo : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetDiagFieldA = odbc32.NewProc("SQLGetDiagFieldA")
)

// fHandleType (SHORT), handle (void* in/out), iRecord (SHORT), fDiagField (SHORT), rgbDiagInfo (void* optional, out), cbDiagInfoMax (SHORT), pcbDiagInfo (SHORT* optional, out)
r1, _, err := procSQLGetDiagFieldA.Call(
	uintptr(fHandleType),
	uintptr(handle),
	uintptr(iRecord),
	uintptr(fDiagField),
	uintptr(rgbDiagInfo),
	uintptr(cbDiagInfoMax),
	uintptr(pcbDiagInfo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLGetDiagFieldA(
  fHandleType: Smallint;   // SHORT
  handle: Pointer;   // void* in/out
  iRecord: Smallint;   // SHORT
  fDiagField: Smallint;   // SHORT
  rgbDiagInfo: Pointer;   // void* optional, out
  cbDiagInfoMax: Smallint;   // SHORT
  pcbDiagInfo: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDiagFieldA';
result := DllCall("ODBC32\SQLGetDiagFieldA"
    , "Short", fHandleType   ; SHORT
    , "Ptr", handle   ; void* in/out
    , "Short", iRecord   ; SHORT
    , "Short", fDiagField   ; SHORT
    , "Ptr", rgbDiagInfo   ; void* optional, out
    , "Short", cbDiagInfoMax   ; SHORT
    , "Ptr", pcbDiagInfo   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo) = DLL("ODBC32.dll", "int SQLGetDiagFieldA(int, void*, int, int, void*, int, void*)")
# 呼び出し: SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
# fHandleType : SHORT -> "int"
# handle : void* in/out -> "void*"
# iRecord : SHORT -> "int"
# fDiagField : SHORT -> "int"
# rgbDiagInfo : void* optional, out -> "void*"
# cbDiagInfoMax : SHORT -> "int"
# pcbDiagInfo : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLGetDiagFieldA(
    fHandleType: i16, // SHORT
    handle: ?*anyopaque, // void* in/out
    iRecord: i16, // SHORT
    fDiagField: i16, // SHORT
    rgbDiagInfo: ?*anyopaque, // void* optional, out
    cbDiagInfoMax: i16, // SHORT
    pcbDiagInfo: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
proc SQLGetDiagFieldA(
    fHandleType: int16,  # SHORT
    handle: pointer,  # void* in/out
    iRecord: int16,  # SHORT
    fDiagField: int16,  # SHORT
    rgbDiagInfo: pointer,  # void* optional, out
    cbDiagInfoMax: int16,  # SHORT
    pcbDiagInfo: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLGetDiagFieldA", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLGetDiagFieldA(
    short fHandleType,   // SHORT
    void* handle,   // void* in/out
    short iRecord,   // SHORT
    short fDiagField,   // SHORT
    void* rgbDiagInfo,   // void* optional, out
    short cbDiagInfoMax,   // SHORT
    short* pcbDiagInfo   // SHORT* optional, out
);
ccall((:SQLGetDiagFieldA, "ODBC32.dll"), stdcall, Int16,
      (Int16, Ptr{Cvoid}, Int16, Int16, Ptr{Cvoid}, Int16, Ptr{Int16}),
      fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
# fHandleType : SHORT -> Int16
# handle : void* in/out -> Ptr{Cvoid}
# iRecord : SHORT -> Int16
# fDiagField : SHORT -> Int16
# rgbDiagInfo : void* optional, out -> Ptr{Cvoid}
# cbDiagInfoMax : SHORT -> Int16
# pcbDiagInfo : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetDiagFieldA(
    int16_t fHandleType,
    void* handle,
    int16_t iRecord,
    int16_t fDiagField,
    void* rgbDiagInfo,
    int16_t cbDiagInfoMax,
    int16_t* pcbDiagInfo);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
-- fHandleType : SHORT
-- handle : void* in/out
-- iRecord : SHORT
-- fDiagField : SHORT
-- rgbDiagInfo : void* optional, out
-- cbDiagInfoMax : SHORT
-- pcbDiagInfo : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetDiagFieldA = lib.func('__stdcall', 'SQLGetDiagFieldA', 'int16_t', ['int16_t', 'void *', 'int16_t', 'int16_t', 'void *', 'int16_t', 'int16_t *']);
// SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
// fHandleType : SHORT -> 'int16_t'
// handle : void* in/out -> 'void *'
// iRecord : SHORT -> 'int16_t'
// fDiagField : SHORT -> 'int16_t'
// rgbDiagInfo : void* optional, out -> 'void *'
// cbDiagInfoMax : SHORT -> 'int16_t'
// pcbDiagInfo : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLGetDiagFieldA: { parameters: ["i16", "pointer", "i16", "i16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo)
// fHandleType : SHORT -> "i16"
// handle : void* in/out -> "pointer"
// iRecord : SHORT -> "i16"
// fDiagField : SHORT -> "i16"
// rgbDiagInfo : void* optional, out -> "pointer"
// cbDiagInfoMax : SHORT -> "i16"
// pcbDiagInfo : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetDiagFieldA(
    int16_t fHandleType,
    void* handle,
    int16_t iRecord,
    int16_t fDiagField,
    void* rgbDiagInfo,
    int16_t cbDiagInfoMax,
    int16_t* pcbDiagInfo);
C, "ODBC32.dll");
// $ffi->SQLGetDiagFieldA(fHandleType, handle, iRecord, fDiagField, rgbDiagInfo, cbDiagInfoMax, pcbDiagInfo);
// fHandleType : SHORT
// handle : void* in/out
// iRecord : SHORT
// fDiagField : SHORT
// rgbDiagInfo : void* optional, out
// cbDiagInfoMax : SHORT
// pcbDiagInfo : 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.ASCII_OPTIONS);
    short SQLGetDiagFieldA(
        short fHandleType,   // SHORT
        Pointer handle,   // void* in/out
        short iRecord,   // SHORT
        short fDiagField,   // SHORT
        Pointer rgbDiagInfo,   // void* optional, out
        short cbDiagInfoMax,   // SHORT
        ShortByReference pcbDiagInfo   // SHORT* optional, out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLGetDiagFieldA = SQLGetDiagFieldA(
    fHandleType : Int16,   # SHORT
    handle : Void*,   # void* in/out
    iRecord : Int16,   # SHORT
    fDiagField : Int16,   # SHORT
    rgbDiagInfo : Void*,   # void* optional, out
    cbDiagInfoMax : Int16,   # SHORT
    pcbDiagInfo : 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 SQLGetDiagFieldANative = Int16 Function(Int16, Pointer<Void>, Int16, Int16, Pointer<Void>, Int16, Pointer<Int16>);
typedef SQLGetDiagFieldADart = int Function(int, Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int16>);
final SQLGetDiagFieldA = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLGetDiagFieldANative, SQLGetDiagFieldADart>('SQLGetDiagFieldA');
// fHandleType : SHORT -> Int16
// handle : void* in/out -> Pointer<Void>
// iRecord : SHORT -> Int16
// fDiagField : SHORT -> Int16
// rgbDiagInfo : void* optional, out -> Pointer<Void>
// cbDiagInfoMax : SHORT -> Int16
// pcbDiagInfo : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLGetDiagFieldA(
  fHandleType: Smallint;   // SHORT
  handle: Pointer;   // void* in/out
  iRecord: Smallint;   // SHORT
  fDiagField: Smallint;   // SHORT
  rgbDiagInfo: Pointer;   // void* optional, out
  cbDiagInfoMax: Smallint;   // SHORT
  pcbDiagInfo: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLGetDiagFieldA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLGetDiagFieldA"
  c_SQLGetDiagFieldA :: 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 ()
-- cbDiagInfoMax : SHORT -> Int16
-- pcbDiagInfo : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlgetdiagfielda =
  foreign "SQLGetDiagFieldA"
    (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) *)
(* cbDiagInfoMax : SHORT -> int16_t *)
(* pcbDiagInfo : 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 ("SQLGetDiagFieldA" sqlget-diag-field-a :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-diag-info-max :int16)   ; SHORT
  (pcb-diag-info :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLGetDiagFieldA = Win32::API::More->new('ODBC32',
    'short SQLGetDiagFieldA(short fHandleType, LPVOID handle, short iRecord, short fDiagField, LPVOID rgbDiagInfo, short cbDiagInfoMax, LPVOID pcbDiagInfo)');
# my $ret = $SQLGetDiagFieldA->Call($fHandleType, $handle, $iRecord, $fDiagField, $rgbDiagInfo, $cbDiagInfoMax, $pcbDiagInfo);
# fHandleType : SHORT -> short
# handle : void* in/out -> LPVOID
# iRecord : SHORT -> short
# fDiagField : SHORT -> short
# rgbDiagInfo : void* optional, out -> LPVOID
# cbDiagInfoMax : SHORT -> short
# pcbDiagInfo : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い