Win32 API 日本語リファレンス
ホームSystem.Search › SQLDescribeColA

SQLDescribeColA

関数
結果セット列の名前や型などの属性を取得する(ANSI)。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLDescribeColA(
    void* hstmt,
    WORD icol,
    BYTE* szColName,   // optional
    SHORT cbColNameMax,
    SHORT* pcbColName,   // optional
    SHORT* pfSqlType,   // optional
    DWORD* pcbColDef,   // optional
    SHORT* pibScale,   // optional
    SHORT* pfNullable   // optional
);

パラメーター

名前方向説明
hstmtvoid*inoutODBCのステートメントハンドル。記述対象の結果セットを保持する。
icolWORDin対象列番号。1始まりで指定する。
szColNameBYTE*outoptional列名を受け取るバッファ。出力用。
cbColNameMaxSHORTinszColNameバッファのバイト長。
pcbColNameSHORT*outoptional実際に返された列名のバイト長を受け取るポインタ。
pfSqlTypeSHORT*outoptional列のSQLデータ型(SQL_*)を受け取るポインタ。
pcbColDefDWORD*outoptional列のサイズ(精度)を受け取るポインタ。
pibScaleSHORT*outoptional列の小数点以下桁数(スケール)を受け取るポインタ。
pfNullableSHORT*outoptional列がNULL許容か(SQL_NULLABLE等)を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLDescribeColA(
    void* hstmt,
    WORD icol,
    BYTE* szColName,   // optional
    SHORT cbColNameMax,
    SHORT* pcbColName,   // optional
    SHORT* pfSqlType,   // optional
    DWORD* pcbColDef,   // optional
    SHORT* pibScale,   // optional
    SHORT* pfNullable   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLDescribeColA(
    IntPtr hstmt,   // void* in/out
    ushort icol,   // WORD
    IntPtr szColName,   // BYTE* optional, out
    short cbColNameMax,   // SHORT
    IntPtr pcbColName,   // SHORT* optional, out
    IntPtr pfSqlType,   // SHORT* optional, out
    IntPtr pcbColDef,   // DWORD* optional, out
    IntPtr pibScale,   // SHORT* optional, out
    IntPtr pfNullable   // SHORT* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLDescribeColA(
    hstmt As IntPtr,   ' void* in/out
    icol As UShort,   ' WORD
    szColName As IntPtr,   ' BYTE* optional, out
    cbColNameMax As Short,   ' SHORT
    pcbColName As IntPtr,   ' SHORT* optional, out
    pfSqlType As IntPtr,   ' SHORT* optional, out
    pcbColDef As IntPtr,   ' DWORD* optional, out
    pibScale As IntPtr,   ' SHORT* optional, out
    pfNullable As IntPtr   ' SHORT* optional, out
) As Short
End Function
' hstmt : void* in/out
' icol : WORD
' szColName : BYTE* optional, out
' cbColNameMax : SHORT
' pcbColName : SHORT* optional, out
' pfSqlType : SHORT* optional, out
' pcbColDef : DWORD* optional, out
' pibScale : SHORT* optional, out
' pfNullable : SHORT* optional, out
Declare PtrSafe Function SQLDescribeColA Lib "odbc32" ( _
    ByVal hstmt As LongPtr, _
    ByVal icol As Integer, _
    ByVal szColName As LongPtr, _
    ByVal cbColNameMax As Integer, _
    ByVal pcbColName As LongPtr, _
    ByVal pfSqlType As LongPtr, _
    ByVal pcbColDef As LongPtr, _
    ByVal pibScale As LongPtr, _
    ByVal pfNullable As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLDescribeColA = ctypes.windll.odbc32.SQLDescribeColA
SQLDescribeColA.restype = ctypes.c_short
SQLDescribeColA.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.c_ushort,  # icol : WORD
    ctypes.POINTER(ctypes.c_ubyte),  # szColName : BYTE* optional, out
    ctypes.c_short,  # cbColNameMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbColName : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # pfSqlType : SHORT* optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcbColDef : DWORD* optional, out
    ctypes.POINTER(ctypes.c_short),  # pibScale : SHORT* optional, out
    ctypes.POINTER(ctypes.c_short),  # pfNullable : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLDescribeColA = Fiddle::Function.new(
  lib['SQLDescribeColA'],
  [
    Fiddle::TYPE_VOIDP,  # hstmt : void* in/out
    -Fiddle::TYPE_SHORT,  # icol : WORD
    Fiddle::TYPE_VOIDP,  # szColName : BYTE* optional, out
    Fiddle::TYPE_SHORT,  # cbColNameMax : SHORT
    Fiddle::TYPE_VOIDP,  # pcbColName : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # pfSqlType : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # pcbColDef : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # pibScale : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # pfNullable : SHORT* optional, out
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLDescribeColA(
        hstmt: *mut (),  // void* in/out
        icol: u16,  // WORD
        szColName: *mut u8,  // BYTE* optional, out
        cbColNameMax: i16,  // SHORT
        pcbColName: *mut i16,  // SHORT* optional, out
        pfSqlType: *mut i16,  // SHORT* optional, out
        pcbColDef: *mut u32,  // DWORD* optional, out
        pibScale: *mut i16,  // SHORT* optional, out
        pfNullable: *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 SQLDescribeColA(IntPtr hstmt, ushort icol, IntPtr szColName, short cbColNameMax, IntPtr pcbColName, IntPtr pfSqlType, IntPtr pcbColDef, IntPtr pibScale, IntPtr pfNullable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLDescribeColA' -Namespace Win32 -PassThru
# $api::SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
#uselib "ODBC32.dll"
#func global SQLDescribeColA "SQLDescribeColA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLDescribeColA hstmt, icol, varptr(szColName), cbColNameMax, varptr(pcbColName), varptr(pfSqlType), varptr(pcbColDef), varptr(pibScale), varptr(pfNullable)   ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; icol : WORD -> "sptr"
; szColName : BYTE* optional, out -> "sptr"
; cbColNameMax : SHORT -> "sptr"
; pcbColName : SHORT* optional, out -> "sptr"
; pfSqlType : SHORT* optional, out -> "sptr"
; pcbColDef : DWORD* optional, out -> "sptr"
; pibScale : SHORT* optional, out -> "sptr"
; pfNullable : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLDescribeColA "SQLDescribeColA" sptr, int, var, int, var, var, var, var, var
; res = SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
; hstmt : void* in/out -> "sptr"
; icol : WORD -> "int"
; szColName : BYTE* optional, out -> "var"
; cbColNameMax : SHORT -> "int"
; pcbColName : SHORT* optional, out -> "var"
; pfSqlType : SHORT* optional, out -> "var"
; pcbColDef : DWORD* optional, out -> "var"
; pibScale : SHORT* optional, out -> "var"
; pfNullable : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLDescribeColA(void* hstmt, WORD icol, BYTE* szColName, SHORT cbColNameMax, SHORT* pcbColName, SHORT* pfSqlType, DWORD* pcbColDef, SHORT* pibScale, SHORT* pfNullable)
#uselib "ODBC32.dll"
#cfunc global SQLDescribeColA "SQLDescribeColA" intptr, int, var, int, var, var, var, var, var
; res = SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
; hstmt : void* in/out -> "intptr"
; icol : WORD -> "int"
; szColName : BYTE* optional, out -> "var"
; cbColNameMax : SHORT -> "int"
; pcbColName : SHORT* optional, out -> "var"
; pfSqlType : SHORT* optional, out -> "var"
; pcbColDef : DWORD* optional, out -> "var"
; pibScale : SHORT* optional, out -> "var"
; pfNullable : SHORT* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLDescribeColA = odbc32.NewProc("SQLDescribeColA")
)

// hstmt (void* in/out), icol (WORD), szColName (BYTE* optional, out), cbColNameMax (SHORT), pcbColName (SHORT* optional, out), pfSqlType (SHORT* optional, out), pcbColDef (DWORD* optional, out), pibScale (SHORT* optional, out), pfNullable (SHORT* optional, out)
r1, _, err := procSQLDescribeColA.Call(
	uintptr(hstmt),
	uintptr(icol),
	uintptr(szColName),
	uintptr(cbColNameMax),
	uintptr(pcbColName),
	uintptr(pfSqlType),
	uintptr(pcbColDef),
	uintptr(pibScale),
	uintptr(pfNullable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLDescribeColA(
  hstmt: Pointer;   // void* in/out
  icol: Word;   // WORD
  szColName: Pointer;   // BYTE* optional, out
  cbColNameMax: Smallint;   // SHORT
  pcbColName: Pointer;   // SHORT* optional, out
  pfSqlType: Pointer;   // SHORT* optional, out
  pcbColDef: Pointer;   // DWORD* optional, out
  pibScale: Pointer;   // SHORT* optional, out
  pfNullable: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLDescribeColA';
result := DllCall("ODBC32\SQLDescribeColA"
    , "Ptr", hstmt   ; void* in/out
    , "UShort", icol   ; WORD
    , "Ptr", szColName   ; BYTE* optional, out
    , "Short", cbColNameMax   ; SHORT
    , "Ptr", pcbColName   ; SHORT* optional, out
    , "Ptr", pfSqlType   ; SHORT* optional, out
    , "Ptr", pcbColDef   ; DWORD* optional, out
    , "Ptr", pibScale   ; SHORT* optional, out
    , "Ptr", pfNullable   ; SHORT* optional, out
    , "Short")   ; return: SHORT
●SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable) = DLL("ODBC32.dll", "int SQLDescribeColA(void*, int, void*, int, void*, void*, void*, void*, void*)")
# 呼び出し: SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
# hstmt : void* in/out -> "void*"
# icol : WORD -> "int"
# szColName : BYTE* optional, out -> "void*"
# cbColNameMax : SHORT -> "int"
# pcbColName : SHORT* optional, out -> "void*"
# pfSqlType : SHORT* optional, out -> "void*"
# pcbColDef : DWORD* optional, out -> "void*"
# pibScale : SHORT* optional, out -> "void*"
# pfNullable : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLDescribeColA(
    hstmt: ?*anyopaque, // void* in/out
    icol: u16, // WORD
    szColName: [*c]u8, // BYTE* optional, out
    cbColNameMax: i16, // SHORT
    pcbColName: [*c]i16, // SHORT* optional, out
    pfSqlType: [*c]i16, // SHORT* optional, out
    pcbColDef: [*c]u32, // DWORD* optional, out
    pibScale: [*c]i16, // SHORT* optional, out
    pfNullable: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
proc SQLDescribeColA(
    hstmt: pointer,  # void* in/out
    icol: uint16,  # WORD
    szColName: ptr uint8,  # BYTE* optional, out
    cbColNameMax: int16,  # SHORT
    pcbColName: ptr int16,  # SHORT* optional, out
    pfSqlType: ptr int16,  # SHORT* optional, out
    pcbColDef: ptr uint32,  # DWORD* optional, out
    pibScale: ptr int16,  # SHORT* optional, out
    pfNullable: ptr int16  # SHORT* optional, out
): int16 {.importc: "SQLDescribeColA", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLDescribeColA(
    void* hstmt,   // void* in/out
    ushort icol,   // WORD
    ubyte* szColName,   // BYTE* optional, out
    short cbColNameMax,   // SHORT
    short* pcbColName,   // SHORT* optional, out
    short* pfSqlType,   // SHORT* optional, out
    uint* pcbColDef,   // DWORD* optional, out
    short* pibScale,   // SHORT* optional, out
    short* pfNullable   // SHORT* optional, out
);
ccall((:SQLDescribeColA, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, UInt16, Ptr{UInt8}, Int16, Ptr{Int16}, Ptr{Int16}, Ptr{UInt32}, Ptr{Int16}, Ptr{Int16}),
      hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
# hstmt : void* in/out -> Ptr{Cvoid}
# icol : WORD -> UInt16
# szColName : BYTE* optional, out -> Ptr{UInt8}
# cbColNameMax : SHORT -> Int16
# pcbColName : SHORT* optional, out -> Ptr{Int16}
# pfSqlType : SHORT* optional, out -> Ptr{Int16}
# pcbColDef : DWORD* optional, out -> Ptr{UInt32}
# pibScale : SHORT* optional, out -> Ptr{Int16}
# pfNullable : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLDescribeColA(
    void* hstmt,
    uint16_t icol,
    uint8_t* szColName,
    int16_t cbColNameMax,
    int16_t* pcbColName,
    int16_t* pfSqlType,
    uint32_t* pcbColDef,
    int16_t* pibScale,
    int16_t* pfNullable);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
-- hstmt : void* in/out
-- icol : WORD
-- szColName : BYTE* optional, out
-- cbColNameMax : SHORT
-- pcbColName : SHORT* optional, out
-- pfSqlType : SHORT* optional, out
-- pcbColDef : DWORD* optional, out
-- pibScale : SHORT* optional, out
-- pfNullable : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLDescribeColA = lib.func('__stdcall', 'SQLDescribeColA', 'int16_t', ['void *', 'uint16_t', 'uint8_t *', 'int16_t', 'int16_t *', 'int16_t *', 'uint32_t *', 'int16_t *', 'int16_t *']);
// SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
// hstmt : void* in/out -> 'void *'
// icol : WORD -> 'uint16_t'
// szColName : BYTE* optional, out -> 'uint8_t *'
// cbColNameMax : SHORT -> 'int16_t'
// pcbColName : SHORT* optional, out -> 'int16_t *'
// pfSqlType : SHORT* optional, out -> 'int16_t *'
// pcbColDef : DWORD* optional, out -> 'uint32_t *'
// pibScale : SHORT* optional, out -> 'int16_t *'
// pfNullable : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLDescribeColA: { parameters: ["pointer", "u16", "pointer", "i16", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i16" },
});
// lib.symbols.SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)
// hstmt : void* in/out -> "pointer"
// icol : WORD -> "u16"
// szColName : BYTE* optional, out -> "pointer"
// cbColNameMax : SHORT -> "i16"
// pcbColName : SHORT* optional, out -> "pointer"
// pfSqlType : SHORT* optional, out -> "pointer"
// pcbColDef : DWORD* optional, out -> "pointer"
// pibScale : SHORT* optional, out -> "pointer"
// pfNullable : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLDescribeColA(
    void* hstmt,
    uint16_t icol,
    uint8_t* szColName,
    int16_t cbColNameMax,
    int16_t* pcbColName,
    int16_t* pfSqlType,
    uint32_t* pcbColDef,
    int16_t* pibScale,
    int16_t* pfNullable);
C, "ODBC32.dll");
// $ffi->SQLDescribeColA(hstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable);
// hstmt : void* in/out
// icol : WORD
// szColName : BYTE* optional, out
// cbColNameMax : SHORT
// pcbColName : SHORT* optional, out
// pfSqlType : SHORT* optional, out
// pcbColDef : DWORD* optional, out
// pibScale : SHORT* optional, out
// pfNullable : 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 SQLDescribeColA(
        Pointer hstmt,   // void* in/out
        short icol,   // WORD
        byte[] szColName,   // BYTE* optional, out
        short cbColNameMax,   // SHORT
        ShortByReference pcbColName,   // SHORT* optional, out
        ShortByReference pfSqlType,   // SHORT* optional, out
        IntByReference pcbColDef,   // DWORD* optional, out
        ShortByReference pibScale,   // SHORT* optional, out
        ShortByReference pfNullable   // SHORT* optional, out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLDescribeColA = SQLDescribeColA(
    hstmt : Void*,   # void* in/out
    icol : UInt16,   # WORD
    szColName : UInt8*,   # BYTE* optional, out
    cbColNameMax : Int16,   # SHORT
    pcbColName : Int16*,   # SHORT* optional, out
    pfSqlType : Int16*,   # SHORT* optional, out
    pcbColDef : UInt32*,   # DWORD* optional, out
    pibScale : Int16*,   # SHORT* optional, out
    pfNullable : 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 SQLDescribeColANative = Int16 Function(Pointer<Void>, Uint16, Pointer<Uint8>, Int16, Pointer<Int16>, Pointer<Int16>, Pointer<Uint32>, Pointer<Int16>, Pointer<Int16>);
typedef SQLDescribeColADart = int Function(Pointer<Void>, int, Pointer<Uint8>, int, Pointer<Int16>, Pointer<Int16>, Pointer<Uint32>, Pointer<Int16>, Pointer<Int16>);
final SQLDescribeColA = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLDescribeColANative, SQLDescribeColADart>('SQLDescribeColA');
// hstmt : void* in/out -> Pointer<Void>
// icol : WORD -> Uint16
// szColName : BYTE* optional, out -> Pointer<Uint8>
// cbColNameMax : SHORT -> Int16
// pcbColName : SHORT* optional, out -> Pointer<Int16>
// pfSqlType : SHORT* optional, out -> Pointer<Int16>
// pcbColDef : DWORD* optional, out -> Pointer<Uint32>
// pibScale : SHORT* optional, out -> Pointer<Int16>
// pfNullable : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLDescribeColA(
  hstmt: Pointer;   // void* in/out
  icol: Word;   // WORD
  szColName: Pointer;   // BYTE* optional, out
  cbColNameMax: Smallint;   // SHORT
  pcbColName: Pointer;   // SHORT* optional, out
  pfSqlType: Pointer;   // SHORT* optional, out
  pcbColDef: Pointer;   // DWORD* optional, out
  pibScale: Pointer;   // SHORT* optional, out
  pfNullable: Pointer   // SHORT* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLDescribeColA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLDescribeColA"
  c_SQLDescribeColA :: Ptr () -> Word16 -> Ptr Word8 -> Int16 -> Ptr Int16 -> Ptr Int16 -> Ptr Word32 -> Ptr Int16 -> Ptr Int16 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- icol : WORD -> Word16
-- szColName : BYTE* optional, out -> Ptr Word8
-- cbColNameMax : SHORT -> Int16
-- pcbColName : SHORT* optional, out -> Ptr Int16
-- pfSqlType : SHORT* optional, out -> Ptr Int16
-- pcbColDef : DWORD* optional, out -> Ptr Word32
-- pibScale : SHORT* optional, out -> Ptr Int16
-- pfNullable : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqldescribecola =
  foreign "SQLDescribeColA"
    ((ptr void) @-> uint16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr uint32_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* icol : WORD -> uint16_t *)
(* szColName : BYTE* optional, out -> (ptr uint8_t) *)
(* cbColNameMax : SHORT -> int16_t *)
(* pcbColName : SHORT* optional, out -> (ptr int16_t) *)
(* pfSqlType : SHORT* optional, out -> (ptr int16_t) *)
(* pcbColDef : DWORD* optional, out -> (ptr uint32_t) *)
(* pibScale : SHORT* optional, out -> (ptr int16_t) *)
(* pfNullable : 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 ("SQLDescribeColA" sqldescribe-col-a :convention :stdcall) :int16
  (hstmt :pointer)   ; void* in/out
  (icol :uint16)   ; WORD
  (sz-col-name :pointer)   ; BYTE* optional, out
  (cb-col-name-max :int16)   ; SHORT
  (pcb-col-name :pointer)   ; SHORT* optional, out
  (pf-sql-type :pointer)   ; SHORT* optional, out
  (pcb-col-def :pointer)   ; DWORD* optional, out
  (pib-scale :pointer)   ; SHORT* optional, out
  (pf-nullable :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLDescribeColA = Win32::API::More->new('ODBC32',
    'short SQLDescribeColA(LPVOID hstmt, WORD icol, LPVOID szColName, short cbColNameMax, LPVOID pcbColName, LPVOID pfSqlType, LPVOID pcbColDef, LPVOID pibScale, LPVOID pfNullable)');
# my $ret = $SQLDescribeColA->Call($hstmt, $icol, $szColName, $cbColNameMax, $pcbColName, $pfSqlType, $pcbColDef, $pibScale, $pfNullable);
# hstmt : void* in/out -> LPVOID
# icol : WORD -> WORD
# szColName : BYTE* optional, out -> LPVOID
# cbColNameMax : SHORT -> short
# pcbColName : SHORT* optional, out -> LPVOID
# pfSqlType : SHORT* optional, out -> LPVOID
# pcbColDef : DWORD* optional, out -> LPVOID
# pibScale : SHORT* optional, out -> LPVOID
# pfNullable : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い