ホーム › System.Search › SQLGetDiagRec
SQLGetDiagRec
関数診断レコードのSQLState・エラー情報を取得する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLGetDiagRec(
SHORT HandleType,
void* Handle,
SHORT RecNumber,
BYTE* Sqlstate, // optional
INT* NativeError,
BYTE* MessageText, // optional
SHORT BufferLength,
SHORT* TextLength // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| HandleType | SHORT | in | 診断情報を取得するハンドルの種別。SQL_HANDLE_*を指定する。 |
| Handle | void* | inout | 診断情報の対象となるハンドル。 |
| RecNumber | SHORT | in | 取得する診断レコード番号。1始まりで指定する。 |
| Sqlstate | BYTE* | outoptional | 5文字のSQLSTATEコードを受け取るバッファ。ANSI文字列。 |
| NativeError | INT* | inout | データソース固有のネイティブエラーコードを受け取るポインタ。 |
| MessageText | BYTE* | outoptional | エラーメッセージ文字列を受け取るバッファ。ANSI文字列。 |
| BufferLength | SHORT | in | MessageTextバッファの文字数長。 |
| TextLength | SHORT* | outoptional | 実際のメッセージの文字数を受け取るポインタ。NULL可。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLGetDiagRec(
SHORT HandleType,
void* Handle,
SHORT RecNumber,
BYTE* Sqlstate, // optional
INT* NativeError,
BYTE* MessageText, // optional
SHORT BufferLength,
SHORT* TextLength // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLGetDiagRec(
short HandleType, // SHORT
IntPtr Handle, // void* in/out
short RecNumber, // SHORT
IntPtr Sqlstate, // BYTE* optional, out
ref int NativeError, // INT* in/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 SQLGetDiagRec(
HandleType As Short, ' SHORT
Handle As IntPtr, ' void* in/out
RecNumber As Short, ' SHORT
Sqlstate As IntPtr, ' BYTE* optional, out
ByRef NativeError As Integer, ' INT* in/out
MessageText As IntPtr, ' BYTE* optional, out
BufferLength As Short, ' SHORT
TextLength As IntPtr ' SHORT* optional, out
) As Short
End Function' HandleType : SHORT
' Handle : void* in/out
' RecNumber : SHORT
' Sqlstate : BYTE* optional, out
' NativeError : INT* in/out
' MessageText : BYTE* optional, out
' BufferLength : SHORT
' TextLength : SHORT* optional, out
Declare PtrSafe Function SQLGetDiagRec Lib "odbc32" ( _
ByVal HandleType As Integer, _
ByVal Handle As LongPtr, _
ByVal RecNumber As Integer, _
ByVal Sqlstate As LongPtr, _
ByRef NativeError As Long, _
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
SQLGetDiagRec = ctypes.windll.odbc32.SQLGetDiagRec
SQLGetDiagRec.restype = ctypes.c_short
SQLGetDiagRec.argtypes = [
ctypes.c_short, # HandleType : SHORT
ctypes.POINTER(None), # Handle : void* in/out
ctypes.c_short, # RecNumber : SHORT
ctypes.POINTER(ctypes.c_ubyte), # Sqlstate : BYTE* optional, out
ctypes.POINTER(ctypes.c_int), # NativeError : INT* in/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')
SQLGetDiagRec = Fiddle::Function.new(
lib['SQLGetDiagRec'],
[
Fiddle::TYPE_SHORT, # HandleType : SHORT
Fiddle::TYPE_VOIDP, # Handle : void* in/out
Fiddle::TYPE_SHORT, # RecNumber : SHORT
Fiddle::TYPE_VOIDP, # Sqlstate : BYTE* optional, out
Fiddle::TYPE_VOIDP, # NativeError : INT* in/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 SQLGetDiagRec(
HandleType: i16, // SHORT
Handle: *mut (), // void* in/out
RecNumber: i16, // SHORT
Sqlstate: *mut u8, // BYTE* optional, out
NativeError: *mut i32, // INT* in/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 SQLGetDiagRec(short HandleType, IntPtr Handle, short RecNumber, IntPtr Sqlstate, ref int NativeError, IntPtr MessageText, short BufferLength, IntPtr TextLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDiagRec' -Namespace Win32 -PassThru
# $api::SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)#uselib "ODBC32.dll"
#func global SQLGetDiagRec "SQLGetDiagRec" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLGetDiagRec HandleType, Handle, RecNumber, varptr(Sqlstate), varptr(NativeError), varptr(MessageText), BufferLength, varptr(TextLength) ; 戻り値は stat
; HandleType : SHORT -> "sptr"
; Handle : void* in/out -> "sptr"
; RecNumber : SHORT -> "sptr"
; Sqlstate : BYTE* optional, out -> "sptr"
; NativeError : INT* in/out -> "sptr"
; MessageText : BYTE* optional, out -> "sptr"
; BufferLength : SHORT -> "sptr"
; TextLength : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, sptr, int, var, var, var, int, var ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "sptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "var" ; NativeError : INT* in/out -> "var" ; MessageText : BYTE* optional, out -> "var" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, sptr, int, sptr, sptr, sptr, int, sptr ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, varptr(Sqlstate), varptr(NativeError), varptr(MessageText), BufferLength, varptr(TextLength)) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "sptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "sptr" ; NativeError : INT* in/out -> "sptr" ; MessageText : BYTE* optional, out -> "sptr" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLGetDiagRec(SHORT HandleType, void* Handle, SHORT RecNumber, BYTE* Sqlstate, INT* NativeError, BYTE* MessageText, SHORT BufferLength, SHORT* TextLength) #uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, intptr, int, var, var, var, int, var ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "intptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "var" ; NativeError : INT* in/out -> "var" ; MessageText : BYTE* optional, out -> "var" ; BufferLength : SHORT -> "int" ; TextLength : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLGetDiagRec(SHORT HandleType, void* Handle, SHORT RecNumber, BYTE* Sqlstate, INT* NativeError, BYTE* MessageText, SHORT BufferLength, SHORT* TextLength) #uselib "ODBC32.dll" #cfunc global SQLGetDiagRec "SQLGetDiagRec" int, intptr, int, intptr, intptr, intptr, int, intptr ; res = SQLGetDiagRec(HandleType, Handle, RecNumber, varptr(Sqlstate), varptr(NativeError), varptr(MessageText), BufferLength, varptr(TextLength)) ; HandleType : SHORT -> "int" ; Handle : void* in/out -> "intptr" ; RecNumber : SHORT -> "int" ; Sqlstate : BYTE* optional, out -> "intptr" ; NativeError : INT* in/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")
procSQLGetDiagRec = odbc32.NewProc("SQLGetDiagRec")
)
// HandleType (SHORT), Handle (void* in/out), RecNumber (SHORT), Sqlstate (BYTE* optional, out), NativeError (INT* in/out), MessageText (BYTE* optional, out), BufferLength (SHORT), TextLength (SHORT* optional, out)
r1, _, err := procSQLGetDiagRec.Call(
uintptr(HandleType),
uintptr(Handle),
uintptr(RecNumber),
uintptr(Sqlstate),
uintptr(NativeError),
uintptr(MessageText),
uintptr(BufferLength),
uintptr(TextLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLGetDiagRec(
HandleType: Smallint; // SHORT
Handle: Pointer; // void* in/out
RecNumber: Smallint; // SHORT
Sqlstate: Pointer; // BYTE* optional, out
NativeError: Pointer; // INT* in/out
MessageText: Pointer; // BYTE* optional, out
BufferLength: Smallint; // SHORT
TextLength: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetDiagRec';result := DllCall("ODBC32\SQLGetDiagRec"
, "Short", HandleType ; SHORT
, "Ptr", Handle ; void* in/out
, "Short", RecNumber ; SHORT
, "Ptr", Sqlstate ; BYTE* optional, out
, "Ptr", NativeError ; INT* in/out
, "Ptr", MessageText ; BYTE* optional, out
, "Short", BufferLength ; SHORT
, "Ptr", TextLength ; SHORT* optional, out
, "Short") ; return: SHORT●SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength) = DLL("ODBC32.dll", "int SQLGetDiagRec(int, void*, int, void*, void*, void*, int, void*)")
# 呼び出し: SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)
# HandleType : SHORT -> "int"
# Handle : void* in/out -> "void*"
# RecNumber : SHORT -> "int"
# Sqlstate : BYTE* optional, out -> "void*"
# NativeError : INT* in/out -> "void*"
# MessageText : BYTE* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# TextLength : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLGetDiagRec(
HandleType: i16, // SHORT
Handle: ?*anyopaque, // void* in/out
RecNumber: i16, // SHORT
Sqlstate: [*c]u8, // BYTE* optional, out
NativeError: [*c]i32, // INT* in/out
MessageText: [*c]u8, // BYTE* optional, out
BufferLength: i16, // SHORT
TextLength: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;proc SQLGetDiagRec(
HandleType: int16, # SHORT
Handle: pointer, # void* in/out
RecNumber: int16, # SHORT
Sqlstate: ptr uint8, # BYTE* optional, out
NativeError: ptr int32, # INT* in/out
MessageText: ptr uint8, # BYTE* optional, out
BufferLength: int16, # SHORT
TextLength: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLGetDiagRec", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLGetDiagRec(
short HandleType, // SHORT
void* Handle, // void* in/out
short RecNumber, // SHORT
ubyte* Sqlstate, // BYTE* optional, out
int* NativeError, // INT* in/out
ubyte* MessageText, // BYTE* optional, out
short BufferLength, // SHORT
short* TextLength // SHORT* optional, out
);ccall((:SQLGetDiagRec, "ODBC32.dll"), stdcall, Int16,
(Int16, Ptr{Cvoid}, Int16, Ptr{UInt8}, Ptr{Int32}, Ptr{UInt8}, Int16, Ptr{Int16}),
HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)
# HandleType : SHORT -> Int16
# Handle : void* in/out -> Ptr{Cvoid}
# RecNumber : SHORT -> Int16
# Sqlstate : BYTE* optional, out -> Ptr{UInt8}
# NativeError : INT* in/out -> Ptr{Int32}
# MessageText : BYTE* optional, out -> Ptr{UInt8}
# BufferLength : SHORT -> Int16
# TextLength : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetDiagRec(
int16_t HandleType,
void* Handle,
int16_t RecNumber,
uint8_t* Sqlstate,
int32_t* NativeError,
uint8_t* MessageText,
int16_t BufferLength,
int16_t* TextLength);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)
-- HandleType : SHORT
-- Handle : void* in/out
-- RecNumber : SHORT
-- Sqlstate : BYTE* optional, out
-- NativeError : INT* in/out
-- MessageText : BYTE* optional, out
-- BufferLength : SHORT
-- TextLength : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetDiagRec = lib.func('__stdcall', 'SQLGetDiagRec', 'int16_t', ['int16_t', 'void *', 'int16_t', 'uint8_t *', 'int32_t *', 'uint8_t *', 'int16_t', 'int16_t *']);
// SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)
// HandleType : SHORT -> 'int16_t'
// Handle : void* in/out -> 'void *'
// RecNumber : SHORT -> 'int16_t'
// Sqlstate : BYTE* optional, out -> 'uint8_t *'
// NativeError : INT* in/out -> 'int32_t *'
// MessageText : BYTE* optional, out -> 'uint8_t *'
// BufferLength : SHORT -> 'int16_t'
// TextLength : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLGetDiagRec: { parameters: ["i16", "pointer", "i16", "pointer", "pointer", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength)
// HandleType : SHORT -> "i16"
// Handle : void* in/out -> "pointer"
// RecNumber : SHORT -> "i16"
// Sqlstate : BYTE* optional, out -> "pointer"
// NativeError : INT* in/out -> "pointer"
// MessageText : BYTE* optional, out -> "pointer"
// BufferLength : SHORT -> "i16"
// TextLength : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetDiagRec(
int16_t HandleType,
void* Handle,
int16_t RecNumber,
uint8_t* Sqlstate,
int32_t* NativeError,
uint8_t* MessageText,
int16_t BufferLength,
int16_t* TextLength);
C, "ODBC32.dll");
// $ffi->SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
// HandleType : SHORT
// Handle : void* in/out
// RecNumber : SHORT
// Sqlstate : BYTE* optional, out
// NativeError : INT* in/out
// MessageText : BYTE* optional, out
// BufferLength : SHORT
// TextLength : 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.ASCII_OPTIONS);
short SQLGetDiagRec(
short HandleType, // SHORT
Pointer Handle, // void* in/out
short RecNumber, // SHORT
byte[] Sqlstate, // BYTE* optional, out
IntByReference NativeError, // INT* in/out
byte[] MessageText, // BYTE* optional, out
short BufferLength, // SHORT
ShortByReference TextLength // SHORT* optional, out
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLGetDiagRec = SQLGetDiagRec(
HandleType : Int16, # SHORT
Handle : Void*, # void* in/out
RecNumber : Int16, # SHORT
Sqlstate : UInt8*, # BYTE* optional, out
NativeError : Int32*, # INT* in/out
MessageText : UInt8*, # BYTE* optional, out
BufferLength : Int16, # SHORT
TextLength : 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 SQLGetDiagRecNative = Int16 Function(Int16, Pointer<Void>, Int16, Pointer<Uint8>, Pointer<Int32>, Pointer<Uint8>, Int16, Pointer<Int16>);
typedef SQLGetDiagRecDart = int Function(int, Pointer<Void>, int, Pointer<Uint8>, Pointer<Int32>, Pointer<Uint8>, int, Pointer<Int16>);
final SQLGetDiagRec = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLGetDiagRecNative, SQLGetDiagRecDart>('SQLGetDiagRec');
// HandleType : SHORT -> Int16
// Handle : void* in/out -> Pointer<Void>
// RecNumber : SHORT -> Int16
// Sqlstate : BYTE* optional, out -> Pointer<Uint8>
// NativeError : INT* in/out -> Pointer<Int32>
// MessageText : BYTE* optional, out -> Pointer<Uint8>
// BufferLength : SHORT -> Int16
// TextLength : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLGetDiagRec(
HandleType: Smallint; // SHORT
Handle: Pointer; // void* in/out
RecNumber: Smallint; // SHORT
Sqlstate: Pointer; // BYTE* optional, out
NativeError: Pointer; // INT* in/out
MessageText: Pointer; // BYTE* optional, out
BufferLength: Smallint; // SHORT
TextLength: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetDiagRec';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLGetDiagRec"
c_SQLGetDiagRec :: Int16 -> Ptr () -> Int16 -> Ptr Word8 -> Ptr Int32 -> Ptr Word8 -> Int16 -> Ptr Int16 -> IO Int16
-- HandleType : SHORT -> Int16
-- Handle : void* in/out -> Ptr ()
-- RecNumber : SHORT -> Int16
-- Sqlstate : BYTE* optional, out -> Ptr Word8
-- NativeError : INT* in/out -> Ptr Int32
-- MessageText : BYTE* optional, out -> Ptr Word8
-- BufferLength : SHORT -> Int16
-- TextLength : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlgetdiagrec =
foreign "SQLGetDiagRec"
(int16_t @-> (ptr void) @-> int16_t @-> (ptr uint8_t) @-> (ptr int32_t) @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* HandleType : SHORT -> int16_t *)
(* Handle : void* in/out -> (ptr void) *)
(* RecNumber : SHORT -> int16_t *)
(* Sqlstate : BYTE* optional, out -> (ptr uint8_t) *)
(* NativeError : INT* in/out -> (ptr int32_t) *)
(* MessageText : BYTE* optional, out -> (ptr uint8_t) *)
(* BufferLength : SHORT -> int16_t *)
(* TextLength : 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 ("SQLGetDiagRec" sqlget-diag-rec :convention :stdcall) :int16
(handle-type :int16) ; SHORT
(handle :pointer) ; void* in/out
(rec-number :int16) ; SHORT
(sqlstate :pointer) ; BYTE* optional, out
(native-error :pointer) ; INT* in/out
(message-text :pointer) ; BYTE* optional, out
(buffer-length :int16) ; SHORT
(text-length :pointer)) ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLGetDiagRec = Win32::API::More->new('ODBC32',
'short SQLGetDiagRec(short HandleType, LPVOID Handle, short RecNumber, LPVOID Sqlstate, LPVOID NativeError, LPVOID MessageText, short BufferLength, LPVOID TextLength)');
# my $ret = $SQLGetDiagRec->Call($HandleType, $Handle, $RecNumber, $Sqlstate, $NativeError, $MessageText, $BufferLength, $TextLength);
# HandleType : SHORT -> short
# Handle : void* in/out -> LPVOID
# RecNumber : SHORT -> short
# Sqlstate : BYTE* optional, out -> LPVOID
# NativeError : INT* in/out -> LPVOID
# MessageText : BYTE* optional, out -> LPVOID
# BufferLength : SHORT -> short
# TextLength : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLGetDiagRecA (ANSI版) — 診断レコードのSQLState・エラー情報を取得する(ANSI)。
- f SQLGetDiagRecW (Unicode版) — 診断レコードのSQLState・エラー情報を取得する(Unicode)。