ホーム › 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 | 環境ハンドル。非推奨でSQLGetDiagRecに置換された。 |
| hdbc | void* | inout | 接続ハンドル。エラー対象に応じて指定する。NULL可。 |
| hstmt | void* | inout | ステートメントハンドル。エラー対象に応じて指定する。NULL可。 |
| wszSqlState | WORD* | out | 5文字のSQLSTATEコードを受け取るバッファ。Unicode文字列。 |
| pfNativeError | INT* | outoptional | データソース固有のネイティブエラーコードを受け取るポインタ。 |
| wszErrorMsg | WORD* | outoptional | エラーメッセージを受け取るバッファ。Unicode文字列。 |
| cchErrorMsgMax | SHORT | in | wszErrorMsgバッファの文字数長。 |
| pcchErrorMsg | SHORT* | outoptional | メッセージの実際の文字数を受け取るポインタ。NULL可。 |
戻り値の型: 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 版の利用を推奨。const std = @import("std");
extern "odbc32" fn SQLErrorW(
henv: ?*anyopaque, // void* in/out
hdbc: ?*anyopaque, // void* in/out
hstmt: ?*anyopaque, // void* in/out
wszSqlState: [*c]u16, // WORD* out
pfNativeError: [*c]i32, // INT* optional, out
wszErrorMsg: [*c]u16, // WORD* optional, out
cchErrorMsgMax: i16, // SHORT
pcchErrorMsg: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SQLErrorW(
henv: pointer, # void* in/out
hdbc: pointer, # void* in/out
hstmt: pointer, # void* in/out
wszSqlState: ptr uint16, # WORD* out
pfNativeError: ptr int32, # INT* optional, out
wszErrorMsg: ptr uint16, # WORD* optional, out
cchErrorMsgMax: int16, # SHORT
pcchErrorMsg: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLErrorW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "odbc32");
extern(Windows)
short SQLErrorW(
void* henv, // void* in/out
void* hdbc, // void* in/out
void* hstmt, // void* in/out
ushort* wszSqlState, // WORD* out
int* pfNativeError, // INT* optional, out
ushort* wszErrorMsg, // WORD* optional, out
short cchErrorMsgMax, // SHORT
short* pcchErrorMsg // SHORT* optional, out
);ccall((:SQLErrorW, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{UInt16}, Ptr{Int32}, Ptr{UInt16}, Int16, Ptr{Int16}),
henv, hdbc, hstmt, wszSqlState, pfNativeError, wszErrorMsg, cchErrorMsgMax, pcchErrorMsg)
# henv : void* in/out -> Ptr{Cvoid}
# hdbc : void* in/out -> Ptr{Cvoid}
# hstmt : void* in/out -> Ptr{Cvoid}
# wszSqlState : WORD* out -> Ptr{UInt16}
# pfNativeError : INT* optional, out -> Ptr{Int32}
# wszErrorMsg : WORD* optional, out -> Ptr{UInt16}
# cchErrorMsgMax : SHORT -> Int16
# pcchErrorMsg : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLErrorW(
void* henv,
void* hdbc,
void* hstmt,
uint16_t* wszSqlState,
int32_t* pfNativeError,
uint16_t* wszErrorMsg,
int16_t cchErrorMsgMax,
int16_t* pcchErrorMsg);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLErrorW(henv, hdbc, hstmt, wszSqlState, pfNativeError, wszErrorMsg, cchErrorMsgMax, pcchErrorMsg)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLErrorW = lib.func('__stdcall', 'SQLErrorW', 'int16_t', ['void *', 'void *', 'void *', 'uint16_t *', 'int32_t *', 'uint16_t *', 'int16_t', 'int16_t *']);
// 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 -> 'uint16_t *'
// pfNativeError : INT* optional, out -> 'int32_t *'
// wszErrorMsg : WORD* optional, out -> 'uint16_t *'
// cchErrorMsgMax : SHORT -> 'int16_t'
// pcchErrorMsg : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLErrorW: { parameters: ["pointer", "pointer", "pointer", "pointer", "pointer", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLErrorW(henv, hdbc, hstmt, wszSqlState, pfNativeError, wszErrorMsg, cchErrorMsgMax, pcchErrorMsg)
// henv : void* in/out -> "pointer"
// hdbc : void* in/out -> "pointer"
// hstmt : void* in/out -> "pointer"
// wszSqlState : WORD* out -> "pointer"
// pfNativeError : INT* optional, out -> "pointer"
// wszErrorMsg : WORD* optional, out -> "pointer"
// cchErrorMsgMax : SHORT -> "i16"
// pcchErrorMsg : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLErrorW(
void* henv,
void* hdbc,
void* hstmt,
uint16_t* wszSqlState,
int32_t* pfNativeError,
uint16_t* wszErrorMsg,
int16_t cchErrorMsgMax,
int16_t* pcchErrorMsg);
C, "ODBC32.dll");
// $ffi->SQLErrorW(henv, hdbc, hstmt, wszSqlState, pfNativeError, wszErrorMsg, cchErrorMsgMax, pcchErrorMsg);
// 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
// 構造体/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.UNICODE_OPTIONS);
short SQLErrorW(
Pointer henv, // void* in/out
Pointer hdbc, // void* in/out
Pointer hstmt, // void* in/out
ShortByReference wszSqlState, // WORD* out
IntByReference pfNativeError, // INT* optional, out
ShortByReference wszErrorMsg, // WORD* optional, out
short cchErrorMsgMax, // SHORT
ShortByReference pcchErrorMsg // SHORT* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("odbc32")]
lib LibODBC32
fun SQLErrorW = SQLErrorW(
henv : Void*, # void* in/out
hdbc : Void*, # void* in/out
hstmt : Void*, # void* in/out
wszSqlState : UInt16*, # WORD* out
pfNativeError : Int32*, # INT* optional, out
wszErrorMsg : UInt16*, # WORD* optional, out
cchErrorMsgMax : Int16, # SHORT
pcchErrorMsg : 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 SQLErrorWNative = Int16 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint16>, Pointer<Int32>, Pointer<Uint16>, Int16, Pointer<Int16>);
typedef SQLErrorWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint16>, Pointer<Int32>, Pointer<Uint16>, int, Pointer<Int16>);
final SQLErrorW = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLErrorWNative, SQLErrorWDart>('SQLErrorW');
// henv : void* in/out -> Pointer<Void>
// hdbc : void* in/out -> Pointer<Void>
// hstmt : void* in/out -> Pointer<Void>
// wszSqlState : WORD* out -> Pointer<Uint16>
// pfNativeError : INT* optional, out -> Pointer<Int32>
// wszErrorMsg : WORD* optional, out -> Pointer<Uint16>
// cchErrorMsgMax : SHORT -> Int16
// pcchErrorMsg : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLErrorW"
c_SQLErrorW :: Ptr () -> Ptr () -> Ptr () -> Ptr Word16 -> Ptr Int32 -> Ptr Word16 -> Int16 -> Ptr Int16 -> IO Int16
-- henv : void* in/out -> Ptr ()
-- hdbc : void* in/out -> Ptr ()
-- hstmt : void* in/out -> Ptr ()
-- wszSqlState : WORD* out -> Ptr Word16
-- pfNativeError : INT* optional, out -> Ptr Int32
-- wszErrorMsg : WORD* optional, out -> Ptr Word16
-- cchErrorMsgMax : SHORT -> Int16
-- pcchErrorMsg : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlerrorw =
foreign "SQLErrorW"
((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr int32_t) @-> (ptr uint16_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* henv : void* in/out -> (ptr void) *)
(* hdbc : void* in/out -> (ptr void) *)
(* hstmt : void* in/out -> (ptr void) *)
(* wszSqlState : WORD* out -> (ptr uint16_t) *)
(* pfNativeError : INT* optional, out -> (ptr int32_t) *)
(* wszErrorMsg : WORD* optional, out -> (ptr uint16_t) *)
(* cchErrorMsgMax : SHORT -> int16_t *)
(* pcchErrorMsg : 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 ("SQLErrorW" sqlerror-w :convention :stdcall) :int16
(henv :pointer) ; void* in/out
(hdbc :pointer) ; void* in/out
(hstmt :pointer) ; void* in/out
(wsz-sql-state :pointer) ; WORD* out
(pf-native-error :pointer) ; INT* optional, out
(wsz-error-msg :pointer) ; WORD* optional, out
(cch-error-msg-max :int16) ; SHORT
(pcch-error-msg :pointer)) ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLErrorW = Win32::API::More->new('ODBC32',
'short SQLErrorW(LPVOID henv, LPVOID hdbc, LPVOID hstmt, LPVOID wszSqlState, LPVOID pfNativeError, LPVOID wszErrorMsg, short cchErrorMsgMax, LPVOID pcchErrorMsg)');
# my $ret = $SQLErrorW->Call($henv, $hdbc, $hstmt, $wszSqlState, $pfNativeError, $wszErrorMsg, $cchErrorMsgMax, $pcchErrorMsg);
# henv : void* in/out -> LPVOID
# hdbc : void* in/out -> LPVOID
# hstmt : void* in/out -> LPVOID
# wszSqlState : WORD* out -> LPVOID
# pfNativeError : INT* optional, out -> LPVOID
# wszErrorMsg : WORD* optional, out -> LPVOID
# cchErrorMsgMax : SHORT -> short
# pcchErrorMsg : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SQLErrorA (ANSI版) — 直前のODBC関数の診断エラー情報を取得する(ANSI)。