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