ホーム › 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 | ハンドル種別。SQL_HANDLE_ENV/DBC/STMT/DESCのいずれか。 |
| handle | void* | inout | 診断情報を取得する対象ハンドル。 |
| iRecord | SHORT | in | 診断レコード番号。1始まりで指定する。 |
| szSqlState | BYTE* | outoptional | 5文字のSQLSTATEを受け取るバッファ。出力用。 |
| pfNativeError | INT* | inout | ドライバ固有のネイティブエラーコードを受け取るポインタ。 |
| szErrorMsg | BYTE* | outoptional | エラーメッセージ本文を受け取るバッファ。出力用。 |
| cbErrorMsgMax | SHORT | in | szErrorMsgバッファのバイト長。 |
| 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)。const std = @import("std");
extern "odbc32" fn SQLGetDiagRecA(
fHandleType: i16, // SHORT
handle: ?*anyopaque, // void* in/out
iRecord: i16, // SHORT
szSqlState: [*c]u8, // BYTE* optional, out
pfNativeError: [*c]i32, // INT* in/out
szErrorMsg: [*c]u8, // BYTE* optional, out
cbErrorMsgMax: i16, // SHORT
pcbErrorMsg: [*c]i16 // SHORT* in/out
) callconv(std.os.windows.WINAPI) i16;proc SQLGetDiagRecA(
fHandleType: int16, # SHORT
handle: pointer, # void* in/out
iRecord: int16, # SHORT
szSqlState: ptr uint8, # BYTE* optional, out
pfNativeError: ptr int32, # INT* in/out
szErrorMsg: ptr uint8, # BYTE* optional, out
cbErrorMsgMax: int16, # SHORT
pcbErrorMsg: ptr int16 # SHORT* in/out
): int16 {.importc: "SQLGetDiagRecA", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLGetDiagRecA(
short fHandleType, // SHORT
void* handle, // void* in/out
short iRecord, // SHORT
ubyte* szSqlState, // BYTE* optional, out
int* pfNativeError, // INT* in/out
ubyte* szErrorMsg, // BYTE* optional, out
short cbErrorMsgMax, // SHORT
short* pcbErrorMsg // SHORT* in/out
);ccall((:SQLGetDiagRecA, "ODBC32.dll"), stdcall, Int16,
(Int16, Ptr{Cvoid}, Int16, Ptr{UInt8}, Ptr{Int32}, Ptr{UInt8}, Int16, Ptr{Int16}),
fHandleType, handle, iRecord, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)
# fHandleType : SHORT -> Int16
# handle : void* in/out -> Ptr{Cvoid}
# iRecord : SHORT -> Int16
# szSqlState : BYTE* optional, out -> Ptr{UInt8}
# pfNativeError : INT* in/out -> Ptr{Int32}
# szErrorMsg : BYTE* optional, out -> Ptr{UInt8}
# cbErrorMsgMax : SHORT -> Int16
# pcbErrorMsg : SHORT* in/out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetDiagRecA(
int16_t fHandleType,
void* handle,
int16_t iRecord,
uint8_t* szSqlState,
int32_t* pfNativeError,
uint8_t* szErrorMsg,
int16_t cbErrorMsgMax,
int16_t* pcbErrorMsg);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetDiagRecA(fHandleType, handle, iRecord, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetDiagRecA = lib.func('__stdcall', 'SQLGetDiagRecA', 'int16_t', ['int16_t', 'void *', 'int16_t', 'uint8_t *', 'int32_t *', 'uint8_t *', 'int16_t', 'int16_t *']);
// SQLGetDiagRecA(fHandleType, handle, iRecord, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)
// fHandleType : SHORT -> 'int16_t'
// handle : void* in/out -> 'void *'
// iRecord : SHORT -> 'int16_t'
// szSqlState : BYTE* optional, out -> 'uint8_t *'
// pfNativeError : INT* in/out -> 'int32_t *'
// szErrorMsg : BYTE* optional, out -> 'uint8_t *'
// cbErrorMsgMax : SHORT -> 'int16_t'
// pcbErrorMsg : SHORT* in/out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLGetDiagRecA: { parameters: ["i16", "pointer", "i16", "pointer", "pointer", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetDiagRecA(fHandleType, handle, iRecord, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)
// fHandleType : SHORT -> "i16"
// handle : void* in/out -> "pointer"
// iRecord : SHORT -> "i16"
// szSqlState : BYTE* optional, out -> "pointer"
// pfNativeError : INT* in/out -> "pointer"
// szErrorMsg : BYTE* optional, out -> "pointer"
// cbErrorMsgMax : SHORT -> "i16"
// pcbErrorMsg : SHORT* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetDiagRecA(
int16_t fHandleType,
void* handle,
int16_t iRecord,
uint8_t* szSqlState,
int32_t* pfNativeError,
uint8_t* szErrorMsg,
int16_t cbErrorMsgMax,
int16_t* pcbErrorMsg);
C, "ODBC32.dll");
// $ffi->SQLGetDiagRecA(fHandleType, handle, iRecord, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg);
// 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
// 構造体/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.ASCII_OPTIONS);
short SQLGetDiagRecA(
short fHandleType, // SHORT
Pointer handle, // void* in/out
short iRecord, // SHORT
byte[] szSqlState, // BYTE* optional, out
IntByReference pfNativeError, // INT* in/out
byte[] szErrorMsg, // BYTE* optional, out
short cbErrorMsgMax, // SHORT
ShortByReference pcbErrorMsg // SHORT* in/out
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLGetDiagRecA = SQLGetDiagRecA(
fHandleType : Int16, # SHORT
handle : Void*, # void* in/out
iRecord : Int16, # SHORT
szSqlState : UInt8*, # BYTE* optional, out
pfNativeError : Int32*, # INT* in/out
szErrorMsg : UInt8*, # BYTE* optional, out
cbErrorMsgMax : Int16, # SHORT
pcbErrorMsg : Int16* # SHORT* in/out
) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SQLGetDiagRecANative = Int16 Function(Int16, Pointer<Void>, Int16, Pointer<Uint8>, Pointer<Int32>, Pointer<Uint8>, Int16, Pointer<Int16>);
typedef SQLGetDiagRecADart = int Function(int, Pointer<Void>, int, Pointer<Uint8>, Pointer<Int32>, Pointer<Uint8>, int, Pointer<Int16>);
final SQLGetDiagRecA = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLGetDiagRecANative, SQLGetDiagRecADart>('SQLGetDiagRecA');
// fHandleType : SHORT -> Int16
// handle : void* in/out -> Pointer<Void>
// iRecord : SHORT -> Int16
// szSqlState : BYTE* optional, out -> Pointer<Uint8>
// pfNativeError : INT* in/out -> Pointer<Int32>
// szErrorMsg : BYTE* optional, out -> Pointer<Uint8>
// cbErrorMsgMax : SHORT -> Int16
// pcbErrorMsg : SHORT* in/out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLGetDiagRecA"
c_SQLGetDiagRecA :: Int16 -> Ptr () -> Int16 -> Ptr Word8 -> Ptr Int32 -> Ptr Word8 -> Int16 -> Ptr Int16 -> IO Int16
-- fHandleType : SHORT -> Int16
-- handle : void* in/out -> Ptr ()
-- iRecord : SHORT -> Int16
-- szSqlState : BYTE* optional, out -> Ptr Word8
-- pfNativeError : INT* in/out -> Ptr Int32
-- szErrorMsg : BYTE* optional, out -> Ptr Word8
-- cbErrorMsgMax : SHORT -> Int16
-- pcbErrorMsg : SHORT* in/out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlgetdiagreca =
foreign "SQLGetDiagRecA"
(int16_t @-> (ptr void) @-> int16_t @-> (ptr uint8_t) @-> (ptr int32_t) @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* fHandleType : SHORT -> int16_t *)
(* handle : void* in/out -> (ptr void) *)
(* iRecord : SHORT -> int16_t *)
(* szSqlState : BYTE* optional, out -> (ptr uint8_t) *)
(* pfNativeError : INT* in/out -> (ptr int32_t) *)
(* szErrorMsg : BYTE* optional, out -> (ptr uint8_t) *)
(* cbErrorMsgMax : SHORT -> int16_t *)
(* pcbErrorMsg : SHORT* in/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 ("SQLGetDiagRecA" sqlget-diag-rec-a :convention :stdcall) :int16
(f-handle-type :int16) ; SHORT
(handle :pointer) ; void* in/out
(i-record :int16) ; SHORT
(sz-sql-state :pointer) ; BYTE* optional, out
(pf-native-error :pointer) ; INT* in/out
(sz-error-msg :pointer) ; BYTE* optional, out
(cb-error-msg-max :int16) ; SHORT
(pcb-error-msg :pointer)) ; SHORT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLGetDiagRecA = Win32::API::More->new('ODBC32',
'short SQLGetDiagRecA(short fHandleType, LPVOID handle, short iRecord, LPVOID szSqlState, LPVOID pfNativeError, LPVOID szErrorMsg, short cbErrorMsgMax, LPVOID pcbErrorMsg)');
# my $ret = $SQLGetDiagRecA->Call($fHandleType, $handle, $iRecord, $szSqlState, $pfNativeError, $szErrorMsg, $cbErrorMsgMax, $pcbErrorMsg);
# fHandleType : SHORT -> short
# handle : void* in/out -> LPVOID
# iRecord : SHORT -> short
# szSqlState : BYTE* optional, out -> LPVOID
# pfNativeError : INT* in/out -> LPVOID
# szErrorMsg : BYTE* optional, out -> LPVOID
# cbErrorMsgMax : SHORT -> short
# pcbErrorMsg : SHORT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLGetDiagRecW (Unicode版) — 診断レコードのSQLState・エラー情報を取得する(Unicode)。