ホーム › System.Search › SQLGetDiagField
SQLGetDiagField
関数診断レコードの指定フィールド値を取得する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| HandleType | SHORT | in | 診断情報を取得するハンドルの種別。SQL_HANDLE_*を指定する。 |
| Handle | void* | inout | 診断情報の対象となるハンドル。 |
| RecNumber | SHORT | in | 取得する診断レコード番号。1始まりで指定する。 |
| DiagIdentifier | SHORT | in | 取得する診断フィールドのID。SQL_DIAG_*定数を指定する。 |
| DiagInfo | void* | outoptional | 診断情報を受け取るバッファへのポインタ。 |
| BufferLength | SHORT | in | DiagInfoバッファのバイト長。文字列フィールドで意味を持つ。 |
| StringLength | SHORT* | outoptional | 実際に書き込まれたバイト数を受け取るポインタ。NULL可。 |
戻り値の型: 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 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLGetDiagField "SQLGetDiagField" int, sptr, int, int, sptr, int, sptr ; res = SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, varptr(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 -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr ; res = SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, varptr(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 -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // SHORTfunction 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)。const std = @import("std");
extern "odbc32" fn SQLGetDiagField(
HandleType: i16, // SHORT
Handle: ?*anyopaque, // void* in/out
RecNumber: i16, // SHORT
DiagIdentifier: i16, // SHORT
DiagInfo: ?*anyopaque, // void* optional, out
BufferLength: i16, // SHORT
StringLength: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;proc SQLGetDiagField(
HandleType: int16, # SHORT
Handle: pointer, # void* in/out
RecNumber: int16, # SHORT
DiagIdentifier: int16, # SHORT
DiagInfo: pointer, # void* optional, out
BufferLength: int16, # SHORT
StringLength: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLGetDiagField", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLGetDiagField(
short HandleType, // SHORT
void* Handle, // void* in/out
short RecNumber, // SHORT
short DiagIdentifier, // SHORT
void* DiagInfo, // void* optional, out
short BufferLength, // SHORT
short* StringLength // SHORT* optional, out
);ccall((:SQLGetDiagField, "ODBC32.dll"), stdcall, Int16,
(Int16, Ptr{Cvoid}, Int16, Int16, Ptr{Cvoid}, Int16, Ptr{Int16}),
HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
# HandleType : SHORT -> Int16
# Handle : void* in/out -> Ptr{Cvoid}
# RecNumber : SHORT -> Int16
# DiagIdentifier : SHORT -> Int16
# DiagInfo : void* optional, out -> Ptr{Cvoid}
# BufferLength : SHORT -> Int16
# StringLength : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetDiagField(
int16_t HandleType,
void* Handle,
int16_t RecNumber,
int16_t DiagIdentifier,
void* DiagInfo,
int16_t BufferLength,
int16_t* StringLength);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
-- HandleType : SHORT
-- Handle : void* in/out
-- RecNumber : SHORT
-- DiagIdentifier : SHORT
-- DiagInfo : void* optional, out
-- BufferLength : SHORT
-- StringLength : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetDiagField = lib.func('__stdcall', 'SQLGetDiagField', 'int16_t', ['int16_t', 'void *', 'int16_t', 'int16_t', 'void *', 'int16_t', 'int16_t *']);
// SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
// HandleType : SHORT -> 'int16_t'
// Handle : void* in/out -> 'void *'
// RecNumber : SHORT -> 'int16_t'
// DiagIdentifier : SHORT -> 'int16_t'
// DiagInfo : void* optional, out -> 'void *'
// BufferLength : SHORT -> 'int16_t'
// StringLength : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLGetDiagField: { parameters: ["i16", "pointer", "i16", "i16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength)
// HandleType : SHORT -> "i16"
// Handle : void* in/out -> "pointer"
// RecNumber : SHORT -> "i16"
// DiagIdentifier : SHORT -> "i16"
// DiagInfo : void* optional, out -> "pointer"
// BufferLength : SHORT -> "i16"
// StringLength : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetDiagField(
int16_t HandleType,
void* Handle,
int16_t RecNumber,
int16_t DiagIdentifier,
void* DiagInfo,
int16_t BufferLength,
int16_t* StringLength);
C, "ODBC32.dll");
// $ffi->SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength);
// HandleType : SHORT
// Handle : void* in/out
// RecNumber : SHORT
// DiagIdentifier : SHORT
// DiagInfo : void* optional, out
// BufferLength : SHORT
// StringLength : 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 SQLGetDiagField(
short HandleType, // SHORT
Pointer Handle, // void* in/out
short RecNumber, // SHORT
short DiagIdentifier, // SHORT
Pointer DiagInfo, // void* optional, out
short BufferLength, // SHORT
ShortByReference StringLength // SHORT* optional, out
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLGetDiagField = SQLGetDiagField(
HandleType : Int16, # SHORT
Handle : Void*, # void* in/out
RecNumber : Int16, # SHORT
DiagIdentifier : Int16, # SHORT
DiagInfo : Void*, # void* optional, out
BufferLength : Int16, # SHORT
StringLength : 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 SQLGetDiagFieldNative = Int16 Function(Int16, Pointer<Void>, Int16, Int16, Pointer<Void>, Int16, Pointer<Int16>);
typedef SQLGetDiagFieldDart = int Function(int, Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int16>);
final SQLGetDiagField = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLGetDiagFieldNative, SQLGetDiagFieldDart>('SQLGetDiagField');
// HandleType : SHORT -> Int16
// Handle : void* in/out -> Pointer<Void>
// RecNumber : SHORT -> Int16
// DiagIdentifier : SHORT -> Int16
// DiagInfo : void* optional, out -> Pointer<Void>
// BufferLength : SHORT -> Int16
// StringLength : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLGetDiagField"
c_SQLGetDiagField :: Int16 -> Ptr () -> Int16 -> Int16 -> Ptr () -> Int16 -> Ptr Int16 -> IO Int16
-- HandleType : SHORT -> Int16
-- Handle : void* in/out -> Ptr ()
-- RecNumber : SHORT -> Int16
-- DiagIdentifier : SHORT -> Int16
-- DiagInfo : void* optional, out -> Ptr ()
-- BufferLength : SHORT -> Int16
-- StringLength : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlgetdiagfield =
foreign "SQLGetDiagField"
(int16_t @-> (ptr void) @-> int16_t @-> int16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* HandleType : SHORT -> int16_t *)
(* Handle : void* in/out -> (ptr void) *)
(* RecNumber : SHORT -> int16_t *)
(* DiagIdentifier : SHORT -> int16_t *)
(* DiagInfo : void* optional, out -> (ptr void) *)
(* BufferLength : SHORT -> int16_t *)
(* StringLength : 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 ("SQLGetDiagField" sqlget-diag-field :convention :stdcall) :int16
(handle-type :int16) ; SHORT
(handle :pointer) ; void* in/out
(rec-number :int16) ; SHORT
(diag-identifier :int16) ; SHORT
(diag-info :pointer) ; void* optional, out
(buffer-length :int16) ; SHORT
(string-length :pointer)) ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLGetDiagField = Win32::API::More->new('ODBC32',
'short SQLGetDiagField(short HandleType, LPVOID Handle, short RecNumber, short DiagIdentifier, LPVOID DiagInfo, short BufferLength, LPVOID StringLength)');
# my $ret = $SQLGetDiagField->Call($HandleType, $Handle, $RecNumber, $DiagIdentifier, $DiagInfo, $BufferLength, $StringLength);
# HandleType : SHORT -> short
# Handle : void* in/out -> LPVOID
# RecNumber : SHORT -> short
# DiagIdentifier : SHORT -> short
# DiagInfo : void* optional, out -> LPVOID
# BufferLength : SHORT -> short
# StringLength : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLGetDiagFieldA (ANSI版) — 診断レコードの指定フィールド値を取得する(ANSI)。
- f SQLGetDiagFieldW (Unicode版) — 診断レコードの指定フィールド値を取得する(Unicode)。