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

SQLStatisticsW

関数
テーブルの統計情報とインデックス一覧を返す(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLStatisticsW(
    void* hstmt,
    WORD* szCatalogName,   // optional
    SHORT cchCatalogName,
    WORD* szSchemaName,   // optional
    SHORT cchSchemaName,
    WORD* szTableName,   // optional
    SHORT cchTableName,
    WORD fUnique,
    WORD fAccuracy
);

パラメーター

名前方向説明
hstmtvoid*inout結果セットを生成する対象のステートメントハンドル。
szCatalogNameWORD*inoptionalカタログ名。Unicode文字列。NULL可。
cchCatalogNameSHORTinszCatalogNameの文字数。SQL_NTSでNUL終端を示す。
szSchemaNameWORD*inoptionalスキーマ名。Unicode文字列。NULL可。
cchSchemaNameSHORTinszSchemaNameの文字数。SQL_NTSでNUL終端を示す。
szTableNameWORD*inoptionalテーブル名。Unicode文字列。NULL不可。
cchTableNameSHORTinszTableNameの文字数。SQL_NTSでNUL終端を示す。
fUniqueWORDin返すインデックス種別。SQL_INDEX_UNIQUE/SQL_INDEX_ALLを指定する。
fAccuracyWORDin統計の取得精度。SQL_ENSURE/SQL_QUICKを指定する。

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLStatisticsW(
    void* hstmt,
    WORD* szCatalogName,   // optional
    SHORT cchCatalogName,
    WORD* szSchemaName,   // optional
    SHORT cchSchemaName,
    WORD* szTableName,   // optional
    SHORT cchTableName,
    WORD fUnique,
    WORD fAccuracy
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLStatisticsW(
    IntPtr hstmt,   // void* in/out
    IntPtr szCatalogName,   // WORD* optional
    short cchCatalogName,   // SHORT
    IntPtr szSchemaName,   // WORD* optional
    short cchSchemaName,   // SHORT
    IntPtr szTableName,   // WORD* optional
    short cchTableName,   // SHORT
    ushort fUnique,   // WORD
    ushort fAccuracy   // WORD
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLStatisticsW(
    hstmt As IntPtr,   ' void* in/out
    szCatalogName As IntPtr,   ' WORD* optional
    cchCatalogName As Short,   ' SHORT
    szSchemaName As IntPtr,   ' WORD* optional
    cchSchemaName As Short,   ' SHORT
    szTableName As IntPtr,   ' WORD* optional
    cchTableName As Short,   ' SHORT
    fUnique As UShort,   ' WORD
    fAccuracy As UShort   ' WORD
) As Short
End Function
' hstmt : void* in/out
' szCatalogName : WORD* optional
' cchCatalogName : SHORT
' szSchemaName : WORD* optional
' cchSchemaName : SHORT
' szTableName : WORD* optional
' cchTableName : SHORT
' fUnique : WORD
' fAccuracy : WORD
Declare PtrSafe Function SQLStatisticsW Lib "odbc32" ( _
    ByVal hstmt As LongPtr, _
    ByVal szCatalogName As LongPtr, _
    ByVal cchCatalogName As Integer, _
    ByVal szSchemaName As LongPtr, _
    ByVal cchSchemaName As Integer, _
    ByVal szTableName As LongPtr, _
    ByVal cchTableName As Integer, _
    ByVal fUnique As Integer, _
    ByVal fAccuracy As Integer) 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

SQLStatisticsW = ctypes.windll.odbc32.SQLStatisticsW
SQLStatisticsW.restype = ctypes.c_short
SQLStatisticsW.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.POINTER(ctypes.c_ushort),  # szCatalogName : WORD* optional
    ctypes.c_short,  # cchCatalogName : SHORT
    ctypes.POINTER(ctypes.c_ushort),  # szSchemaName : WORD* optional
    ctypes.c_short,  # cchSchemaName : SHORT
    ctypes.POINTER(ctypes.c_ushort),  # szTableName : WORD* optional
    ctypes.c_short,  # cchTableName : SHORT
    ctypes.c_ushort,  # fUnique : WORD
    ctypes.c_ushort,  # fAccuracy : WORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLStatisticsW = Fiddle::Function.new(
  lib['SQLStatisticsW'],
  [
    Fiddle::TYPE_VOIDP,  # hstmt : void* in/out
    Fiddle::TYPE_VOIDP,  # szCatalogName : WORD* optional
    Fiddle::TYPE_SHORT,  # cchCatalogName : SHORT
    Fiddle::TYPE_VOIDP,  # szSchemaName : WORD* optional
    Fiddle::TYPE_SHORT,  # cchSchemaName : SHORT
    Fiddle::TYPE_VOIDP,  # szTableName : WORD* optional
    Fiddle::TYPE_SHORT,  # cchTableName : SHORT
    -Fiddle::TYPE_SHORT,  # fUnique : WORD
    -Fiddle::TYPE_SHORT,  # fAccuracy : WORD
  ],
  Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "odbc32")]
extern "system" {
    fn SQLStatisticsW(
        hstmt: *mut (),  // void* in/out
        szCatalogName: *mut u16,  // WORD* optional
        cchCatalogName: i16,  // SHORT
        szSchemaName: *mut u16,  // WORD* optional
        cchSchemaName: i16,  // SHORT
        szTableName: *mut u16,  // WORD* optional
        cchTableName: i16,  // SHORT
        fUnique: u16,  // WORD
        fAccuracy: u16  // WORD
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode)]
public static extern short SQLStatisticsW(IntPtr hstmt, IntPtr szCatalogName, short cchCatalogName, IntPtr szSchemaName, short cchSchemaName, IntPtr szTableName, short cchTableName, ushort fUnique, ushort fAccuracy);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLStatisticsW' -Namespace Win32 -PassThru
# $api::SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
#uselib "ODBC32.dll"
#func global SQLStatisticsW "SQLStatisticsW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SQLStatisticsW hstmt, varptr(szCatalogName), cchCatalogName, varptr(szSchemaName), cchSchemaName, varptr(szTableName), cchTableName, fUnique, fAccuracy   ; 戻り値は stat
; hstmt : void* in/out -> "wptr"
; szCatalogName : WORD* optional -> "wptr"
; cchCatalogName : SHORT -> "wptr"
; szSchemaName : WORD* optional -> "wptr"
; cchSchemaName : SHORT -> "wptr"
; szTableName : WORD* optional -> "wptr"
; cchTableName : SHORT -> "wptr"
; fUnique : WORD -> "wptr"
; fAccuracy : WORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLStatisticsW "SQLStatisticsW" sptr, var, int, var, int, var, int, int, int
; res = SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
; hstmt : void* in/out -> "sptr"
; szCatalogName : WORD* optional -> "var"
; cchCatalogName : SHORT -> "int"
; szSchemaName : WORD* optional -> "var"
; cchSchemaName : SHORT -> "int"
; szTableName : WORD* optional -> "var"
; cchTableName : SHORT -> "int"
; fUnique : WORD -> "int"
; fAccuracy : WORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLStatisticsW(void* hstmt, WORD* szCatalogName, SHORT cchCatalogName, WORD* szSchemaName, SHORT cchSchemaName, WORD* szTableName, SHORT cchTableName, WORD fUnique, WORD fAccuracy)
#uselib "ODBC32.dll"
#cfunc global SQLStatisticsW "SQLStatisticsW" intptr, var, int, var, int, var, int, int, int
; res = SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
; hstmt : void* in/out -> "intptr"
; szCatalogName : WORD* optional -> "var"
; cchCatalogName : SHORT -> "int"
; szSchemaName : WORD* optional -> "var"
; cchSchemaName : SHORT -> "int"
; szTableName : WORD* optional -> "var"
; cchTableName : SHORT -> "int"
; fUnique : WORD -> "int"
; fAccuracy : WORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLStatisticsW = odbc32.NewProc("SQLStatisticsW")
)

// hstmt (void* in/out), szCatalogName (WORD* optional), cchCatalogName (SHORT), szSchemaName (WORD* optional), cchSchemaName (SHORT), szTableName (WORD* optional), cchTableName (SHORT), fUnique (WORD), fAccuracy (WORD)
r1, _, err := procSQLStatisticsW.Call(
	uintptr(hstmt),
	uintptr(szCatalogName),
	uintptr(cchCatalogName),
	uintptr(szSchemaName),
	uintptr(cchSchemaName),
	uintptr(szTableName),
	uintptr(cchTableName),
	uintptr(fUnique),
	uintptr(fAccuracy),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLStatisticsW(
  hstmt: Pointer;   // void* in/out
  szCatalogName: Pointer;   // WORD* optional
  cchCatalogName: Smallint;   // SHORT
  szSchemaName: Pointer;   // WORD* optional
  cchSchemaName: Smallint;   // SHORT
  szTableName: Pointer;   // WORD* optional
  cchTableName: Smallint;   // SHORT
  fUnique: Word;   // WORD
  fAccuracy: Word   // WORD
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLStatisticsW';
result := DllCall("ODBC32\SQLStatisticsW"
    , "Ptr", hstmt   ; void* in/out
    , "Ptr", szCatalogName   ; WORD* optional
    , "Short", cchCatalogName   ; SHORT
    , "Ptr", szSchemaName   ; WORD* optional
    , "Short", cchSchemaName   ; SHORT
    , "Ptr", szTableName   ; WORD* optional
    , "Short", cchTableName   ; SHORT
    , "UShort", fUnique   ; WORD
    , "UShort", fAccuracy   ; WORD
    , "Short")   ; return: SHORT
●SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy) = DLL("ODBC32.dll", "int SQLStatisticsW(void*, void*, int, void*, int, void*, int, int, int)")
# 呼び出し: SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
# hstmt : void* in/out -> "void*"
# szCatalogName : WORD* optional -> "void*"
# cchCatalogName : SHORT -> "int"
# szSchemaName : WORD* optional -> "void*"
# cchSchemaName : SHORT -> "int"
# szTableName : WORD* optional -> "void*"
# cchTableName : SHORT -> "int"
# fUnique : WORD -> "int"
# fAccuracy : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "odbc32" fn SQLStatisticsW(
    hstmt: ?*anyopaque, // void* in/out
    szCatalogName: [*c]u16, // WORD* optional
    cchCatalogName: i16, // SHORT
    szSchemaName: [*c]u16, // WORD* optional
    cchSchemaName: i16, // SHORT
    szTableName: [*c]u16, // WORD* optional
    cchTableName: i16, // SHORT
    fUnique: u16, // WORD
    fAccuracy: u16 // WORD
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SQLStatisticsW(
    hstmt: pointer,  # void* in/out
    szCatalogName: ptr uint16,  # WORD* optional
    cchCatalogName: int16,  # SHORT
    szSchemaName: ptr uint16,  # WORD* optional
    cchSchemaName: int16,  # SHORT
    szTableName: ptr uint16,  # WORD* optional
    cchTableName: int16,  # SHORT
    fUnique: uint16,  # WORD
    fAccuracy: uint16  # WORD
): int16 {.importc: "SQLStatisticsW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "odbc32");
extern(Windows)
short SQLStatisticsW(
    void* hstmt,   // void* in/out
    ushort* szCatalogName,   // WORD* optional
    short cchCatalogName,   // SHORT
    ushort* szSchemaName,   // WORD* optional
    short cchSchemaName,   // SHORT
    ushort* szTableName,   // WORD* optional
    short cchTableName,   // SHORT
    ushort fUnique,   // WORD
    ushort fAccuracy   // WORD
);
ccall((:SQLStatisticsW, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Ptr{UInt16}, Int16, Ptr{UInt16}, Int16, Ptr{UInt16}, Int16, UInt16, UInt16),
      hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
# hstmt : void* in/out -> Ptr{Cvoid}
# szCatalogName : WORD* optional -> Ptr{UInt16}
# cchCatalogName : SHORT -> Int16
# szSchemaName : WORD* optional -> Ptr{UInt16}
# cchSchemaName : SHORT -> Int16
# szTableName : WORD* optional -> Ptr{UInt16}
# cchTableName : SHORT -> Int16
# fUnique : WORD -> UInt16
# fAccuracy : WORD -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLStatisticsW(
    void* hstmt,
    uint16_t* szCatalogName,
    int16_t cchCatalogName,
    uint16_t* szSchemaName,
    int16_t cchSchemaName,
    uint16_t* szTableName,
    int16_t cchTableName,
    uint16_t fUnique,
    uint16_t fAccuracy);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
-- hstmt : void* in/out
-- szCatalogName : WORD* optional
-- cchCatalogName : SHORT
-- szSchemaName : WORD* optional
-- cchSchemaName : SHORT
-- szTableName : WORD* optional
-- cchTableName : SHORT
-- fUnique : WORD
-- fAccuracy : WORD
-- 構造体/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 SQLStatisticsW = lib.func('__stdcall', 'SQLStatisticsW', 'int16_t', ['void *', 'uint16_t *', 'int16_t', 'uint16_t *', 'int16_t', 'uint16_t *', 'int16_t', 'uint16_t', 'uint16_t']);
// SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
// hstmt : void* in/out -> 'void *'
// szCatalogName : WORD* optional -> 'uint16_t *'
// cchCatalogName : SHORT -> 'int16_t'
// szSchemaName : WORD* optional -> 'uint16_t *'
// cchSchemaName : SHORT -> 'int16_t'
// szTableName : WORD* optional -> 'uint16_t *'
// cchTableName : SHORT -> 'int16_t'
// fUnique : WORD -> 'uint16_t'
// fAccuracy : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLStatisticsW: { parameters: ["pointer", "pointer", "i16", "pointer", "i16", "pointer", "i16", "u16", "u16"], result: "i16" },
});
// lib.symbols.SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy)
// hstmt : void* in/out -> "pointer"
// szCatalogName : WORD* optional -> "pointer"
// cchCatalogName : SHORT -> "i16"
// szSchemaName : WORD* optional -> "pointer"
// cchSchemaName : SHORT -> "i16"
// szTableName : WORD* optional -> "pointer"
// cchTableName : SHORT -> "i16"
// fUnique : WORD -> "u16"
// fAccuracy : WORD -> "u16"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLStatisticsW(
    void* hstmt,
    uint16_t* szCatalogName,
    int16_t cchCatalogName,
    uint16_t* szSchemaName,
    int16_t cchSchemaName,
    uint16_t* szTableName,
    int16_t cchTableName,
    uint16_t fUnique,
    uint16_t fAccuracy);
C, "ODBC32.dll");
// $ffi->SQLStatisticsW(hstmt, szCatalogName, cchCatalogName, szSchemaName, cchSchemaName, szTableName, cchTableName, fUnique, fAccuracy);
// hstmt : void* in/out
// szCatalogName : WORD* optional
// cchCatalogName : SHORT
// szSchemaName : WORD* optional
// cchSchemaName : SHORT
// szTableName : WORD* optional
// cchTableName : SHORT
// fUnique : WORD
// fAccuracy : WORD
// 構造体/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 SQLStatisticsW(
        Pointer hstmt,   // void* in/out
        ShortByReference szCatalogName,   // WORD* optional
        short cchCatalogName,   // SHORT
        ShortByReference szSchemaName,   // WORD* optional
        short cchSchemaName,   // SHORT
        ShortByReference szTableName,   // WORD* optional
        short cchTableName,   // SHORT
        short fUnique,   // WORD
        short fAccuracy   // WORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("odbc32")]
lib LibODBC32
  fun SQLStatisticsW = SQLStatisticsW(
    hstmt : Void*,   # void* in/out
    szCatalogName : UInt16*,   # WORD* optional
    cchCatalogName : Int16,   # SHORT
    szSchemaName : UInt16*,   # WORD* optional
    cchSchemaName : Int16,   # SHORT
    szTableName : UInt16*,   # WORD* optional
    cchTableName : Int16,   # SHORT
    fUnique : UInt16,   # WORD
    fAccuracy : UInt16   # WORD
  ) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SQLStatisticsWNative = Int16 Function(Pointer<Void>, Pointer<Uint16>, Int16, Pointer<Uint16>, Int16, Pointer<Uint16>, Int16, Uint16, Uint16);
typedef SQLStatisticsWDart = int Function(Pointer<Void>, Pointer<Uint16>, int, Pointer<Uint16>, int, Pointer<Uint16>, int, int, int);
final SQLStatisticsW = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLStatisticsWNative, SQLStatisticsWDart>('SQLStatisticsW');
// hstmt : void* in/out -> Pointer<Void>
// szCatalogName : WORD* optional -> Pointer<Uint16>
// cchCatalogName : SHORT -> Int16
// szSchemaName : WORD* optional -> Pointer<Uint16>
// cchSchemaName : SHORT -> Int16
// szTableName : WORD* optional -> Pointer<Uint16>
// cchTableName : SHORT -> Int16
// fUnique : WORD -> Uint16
// fAccuracy : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLStatisticsW(
  hstmt: Pointer;   // void* in/out
  szCatalogName: Pointer;   // WORD* optional
  cchCatalogName: Smallint;   // SHORT
  szSchemaName: Pointer;   // WORD* optional
  cchSchemaName: Smallint;   // SHORT
  szTableName: Pointer;   // WORD* optional
  cchTableName: Smallint;   // SHORT
  fUnique: Word;   // WORD
  fAccuracy: Word   // WORD
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLStatisticsW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLStatisticsW"
  c_SQLStatisticsW :: Ptr () -> Ptr Word16 -> Int16 -> Ptr Word16 -> Int16 -> Ptr Word16 -> Int16 -> Word16 -> Word16 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- szCatalogName : WORD* optional -> Ptr Word16
-- cchCatalogName : SHORT -> Int16
-- szSchemaName : WORD* optional -> Ptr Word16
-- cchSchemaName : SHORT -> Int16
-- szTableName : WORD* optional -> Ptr Word16
-- cchTableName : SHORT -> Int16
-- fUnique : WORD -> Word16
-- fAccuracy : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlstatisticsw =
  foreign "SQLStatisticsW"
    ((ptr void) @-> (ptr uint16_t) @-> int16_t @-> (ptr uint16_t) @-> int16_t @-> (ptr uint16_t) @-> int16_t @-> uint16_t @-> uint16_t @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* szCatalogName : WORD* optional -> (ptr uint16_t) *)
(* cchCatalogName : SHORT -> int16_t *)
(* szSchemaName : WORD* optional -> (ptr uint16_t) *)
(* cchSchemaName : SHORT -> int16_t *)
(* szTableName : WORD* optional -> (ptr uint16_t) *)
(* cchTableName : SHORT -> int16_t *)
(* fUnique : WORD -> uint16_t *)
(* fAccuracy : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLStatisticsW" sqlstatistics-w :convention :stdcall) :int16
  (hstmt :pointer)   ; void* in/out
  (sz-catalog-name :pointer)   ; WORD* optional
  (cch-catalog-name :int16)   ; SHORT
  (sz-schema-name :pointer)   ; WORD* optional
  (cch-schema-name :int16)   ; SHORT
  (sz-table-name :pointer)   ; WORD* optional
  (cch-table-name :int16)   ; SHORT
  (f-unique :uint16)   ; WORD
  (f-accuracy :uint16))   ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLStatisticsW = Win32::API::More->new('ODBC32',
    'short SQLStatisticsW(LPVOID hstmt, LPVOID szCatalogName, short cchCatalogName, LPVOID szSchemaName, short cchSchemaName, LPVOID szTableName, short cchTableName, WORD fUnique, WORD fAccuracy)');
# my $ret = $SQLStatisticsW->Call($hstmt, $szCatalogName, $cchCatalogName, $szSchemaName, $cchSchemaName, $szTableName, $cchTableName, $fUnique, $fAccuracy);
# hstmt : void* in/out -> LPVOID
# szCatalogName : WORD* optional -> LPVOID
# cchCatalogName : SHORT -> short
# szSchemaName : WORD* optional -> LPVOID
# cchSchemaName : SHORT -> short
# szTableName : WORD* optional -> LPVOID
# cchTableName : SHORT -> short
# fUnique : WORD -> WORD
# fAccuracy : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い