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