ホーム › System.Search › SQLGetDiagRec
SQLGetDiagRec
関数診断レコードのSQLState・エラー情報を取得する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLGetDiagRec(
SHORT HandleType,
void* Handle,
SHORT RecNumber,
BYTE* Sqlstate, // optional
INT* NativeError,
BYTE* MessageText, // optional
SHORT BufferLength,
SHORT* TextLength // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| HandleType | SHORT | in |
| Handle | void* | inout |
| RecNumber | SHORT | in |
| Sqlstate | BYTE* | outoptional |
| NativeError | INT* | inout |
| MessageText | BYTE* | outoptional |
| BufferLength | SHORT | in |
| TextLength | SHORT* | outoptional |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLGetDiagRec(
SHORT HandleType,
void* Handle,
SHORT RecNumber,
BYTE* Sqlstate, // optional
INT* NativeError,
BYTE* MessageText, // optional
SHORT BufferLength,
SHORT* TextLength // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLGetDiagRec(
short HandleType, // SHORT
IntPtr Handle, // void* in/out
short RecNumber, // SHORT
IntPtr Sqlstate, // BYTE* optional, out
ref int NativeError, // INT* in/out
IntPtr MessageText, // BYTE* optional, out
short BufferLength, // SHORT
IntPtr TextLength // SHORT* optional, out
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLGetDiagRec(
HandleType As Short, ' SHORT
Handle As IntPtr, ' void* in/out
RecNumber As Short, ' SHORT
Sqlstate As IntPtr, ' BYTE* optional, out
ByRef NativeError As Integer, ' INT* in/out
MessageText As IntPtr, ' BYTE* optional, out
BufferLength As Short, ' SHORT
TextLength As IntPtr ' SHORT* optional, out
) As Short
End Function' HandleType : SHORT
' Handle : void* in/out
' RecNumber : SHORT
' Sqlstate : BYTE* optional, out
' NativeError : INT* in/out
' MessageText : BYTE* optional, out
' BufferLength : SHORT
' TextLength : SHORT* optional, out
Declare PtrSafe Function SQLGetDiagRec Lib "odbc32" ( _
ByVal HandleType As Integer, _
ByVal Handle As LongPtr, _
ByVal RecNumber As Integer, _
ByVal Sqlstate As LongPtr, _
ByRef NativeError As Long, _
ByVal MessageText As LongPtr, _
ByVal BufferLength As Integer, _
ByVal TextLength As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLGetDiagRec = ctypes.windll.odbc32.SQLGetDiagRec
SQLGetDiagRec.restype = ctypes.c_short
SQLGetDiagRec.argtypes = [
ctypes.c_short, # HandleType : SHORT
ctypes.POINTER(None), # Handle : void* in/out
ctypes.c_short, # RecNumber : SHORT
ctypes.POINTER(ctypes.c_ubyte), # Sqlstate : BYTE* optional, out
ctypes.POINTER(ctypes.c_int), # NativeError : INT* in/out
ctypes.POINTER(ctypes.c_ubyte), # MessageText : BYTE* optional, out
ctypes.c_short, # BufferLength : SHORT
ctypes.POINTER(ctypes.c_short), # TextLength : SHORT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDiagRec = Fiddle::Function.new(
lib['SQLGetDiagRec'],
[
Fiddle::TYPE_SHORT, # HandleType : SHORT
Fiddle::TYPE_VOIDP, # Handle : void* in/out
Fiddle::TYPE_SHORT, # RecNumber : SHORT
Fiddle::TYPE_VOIDP, # Sqlstate : BYTE* optional, out
Fiddle::TYPE_VOIDP, # NativeError : INT* in/out
Fiddle::TYPE_VOIDP, # MessageText : BYTE* optional, out
Fiddle::TYPE_SHORT, # BufferLength : SHORT
Fiddle::TYPE_VOIDP, # TextLength : SHORT* optional, out
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLGetDiagRec(
HandleType: i16, // SHORT
Handle: *mut (), // void* in/out
RecNumber: i16, // SHORT
Sqlstate: *mut u8, // BYTE* optional, out
NativeError: *mut i32, // INT* in/out
MessageText: *mut u8, // BYTE* optional, out
BufferLength: i16, // SHORT
TextLength: *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 SQLGetDiagRec(short HandleType, IntPtr Handle, short RecNumber, IntPtr Sqlstate, ref int NativeError, IntPtr MessageText, short BufferLength, IntPtr TextLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDiagRec' -Namespace Win32 -PassThru
# $api::SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)#uselib "ODBC32.dll"
#func global SQLGetDiagRec "SQLGetDiagRec" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLGetDiagRec HandleType, Handle, RecNumber, varptr(Sqlstate), varptr(NativeError), varptr(MessageText), BufferLength, varptr(TextLength) ; 戻り値は stat
; HandleType : SHORT -> "sptr"
; Handle : void* in/out -> "sptr"
; RecNumber : SHORT -> "sptr"
; Sqlstate : BYTE* optional, out -> "sptr"
; NativeError : INT* in/out -> "sptr"
; MessageText : BYTE* optional, out -> "sptr"
; BufferLength : SHORT -> "sptr"
; TextLength : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, sptr, int, var, var, var, int, var ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "sptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "var" ; NativeError : INT* in/out -> "var" ; MessageText : BYTE* optional, out -> "var" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, sptr, int, sptr, sptr, sptr, int, sptr ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, varptr(Sqlstate), varptr(NativeError), varptr(MessageText), BufferLength, varptr(TextLength)) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "sptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "sptr" ; NativeError : INT* in/out -> "sptr" ; MessageText : BYTE* optional, out -> "sptr" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLGetDiagRec(SHORT HandleType, void* Handle, SHORT RecNumber, BYTE* Sqlstate, INT* NativeError, BYTE* MessageText, SHORT BufferLength, SHORT* TextLength) #uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, intptr, int, var, var, var, int, var ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "intptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "var" ; NativeError : INT* in/out -> "var" ; MessageText : BYTE* optional, out -> "var" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLGetDiagRec(SHORT HandleType, void* Handle, SHORT RecNumber, BYTE* Sqlstate, INT* NativeError, BYTE* MessageText, SHORT BufferLength, SHORT* TextLength) #uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, intptr, int, intptr, intptr, intptr, int, intptr ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, varptr(Sqlstate), varptr(NativeError), varptr(MessageText), BufferLength, varptr(TextLength)) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "intptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "intptr" ; NativeError : INT* in/out -> "intptr" ; MessageText : BYTE* optional, out -> "intptr" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLGetDiagRec = odbc32.NewProc("SQLGetDiagRec")
)
// HandleType (SHORT), Handle (void* in/out), RecNumber (SHORT), Sqlstate (BYTE* optional, out), NativeError (INT* in/out), MessageText (BYTE* optional, out), BufferLength (SHORT), TextLength (SHORT* optional, out)
r1, _, err := procSQLGetDiagRec.Call(
uintptr(HandleType),
uintptr(Handle),
uintptr(RecNumber),
uintptr(Sqlstate),
uintptr(NativeError),
uintptr(MessageText),
uintptr(BufferLength),
uintptr(TextLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLGetDiagRec(
HandleType: Smallint; // SHORT
Handle: Pointer; // void* in/out
RecNumber: Smallint; // SHORT
Sqlstate: Pointer; // BYTE* optional, out
NativeError: Pointer; // INT* in/out
MessageText: Pointer; // BYTE* optional, out
BufferLength: Smallint; // SHORT
TextLength: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetDiagRec';result := DllCall("ODBC32\SQLGetDiagRec"
, "Short", HandleType ; SHORT
, "Ptr", Handle ; void* in/out
, "Short", RecNumber ; SHORT
, "Ptr", Sqlstate ; BYTE* optional, out
, "Ptr", NativeError ; INT* in/out
, "Ptr", MessageText ; BYTE* optional, out
, "Short", BufferLength ; SHORT
, "Ptr", TextLength ; SHORT* optional, out
, "Short") ; return: SHORT●SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength) = DLL("ODBC32.dll", "int SQLGetDiagRec(int, void*, int, void*, void*, void*, int, void*)")
# 呼び出し: SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)
# HandleType : SHORT -> "int"
# Handle : void* in/out -> "void*"
# RecNumber : SHORT -> "int"
# Sqlstate : BYTE* optional, out -> "void*"
# NativeError : INT* in/out -> "void*"
# MessageText : BYTE* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# TextLength : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。