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