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

SQLTables

関数
データソース内のテーブル一覧を結果セットで返す。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLTables(
    void* StatementHandle,
    BYTE* CatalogName,   // optional
    SHORT NameLength1,
    BYTE* SchemaName,   // optional
    SHORT NameLength2,
    BYTE* TableName,   // optional
    SHORT NameLength3,
    BYTE* TableType,   // optional
    SHORT NameLength4
);

パラメーター

名前型方向説明
StatementHandlevoid*inout[入力] 取得した結果を受け取るステートメントハンドル。
CatalogNameBYTE*inoptional

[入力] カタログ名。CatalogName 引数は、SQL_ODBC_VERSION 環境属性が SQL_OV_ODBC3 の場合は検索パターンを受け付けますが、SQL_OV_ODBC2 が設定されている場合は受け付けません。異なる DBMS からデータを取得する場合のように、ドライバーが一部のテーブルではカタログをサポートし、他のテーブルではサポートしない場合、空文字列 ("") はカタログを持たないテーブルを示します。

SQL_ATTR_METADATA_ID ステートメント属性が SQL_TRUE に設定されている場合、CatalogName は識別子として扱われ、大文字小文字は区別されません。SQL_FALSE の場合、CatalogName はパターン値引数であり、リテラルとして扱われて大文字小文字が区別されます。詳細については、「Arguments in Catalog Functions」を参照してください。

NameLength1SHORTin[入力] *CatalogName の文字数での長さ。
SchemaNameBYTE*inoptional

[入力] スキーマ名の文字列検索パターン。異なる DBMS からデータを取得する場合のように、ドライバーが一部のテーブルではスキーマをサポートし、他のテーブルではサポートしない場合、空文字列 ("") はスキーマを持たないテーブルを示します。

SQL_ATTR_METADATA_ID ステートメント属性が SQL_TRUE に設定されている場合、SchemaName は識別子として扱われ、大文字小文字は区別されません。SQL_FALSE の場合、SchemaName はパターン値引数であり、リテラルとして扱われて大文字小文字が区別されます。

NameLength2SHORTin[入力] *SchemaName の文字数での長さ。
TableNameBYTE*inoptional

[入力] テーブル名の文字列検索パターン。

SQL_ATTR_METADATA_ID ステートメント属性が SQL_TRUE に設定されている場合、TableName は識別子として扱われ、大文字小文字は区別されません。SQL_FALSE の場合、TableName はパターン値引数であり、リテラルとして扱われて大文字小文字が区別されます。

NameLength3SHORTin[入力] *TableName の文字数での長さ。
TableTypeBYTE*inoptional

[入力] 一致させるテーブルの種類の一覧。

SQL_ATTR_METADATA_ID ステートメント属性は TableType 引数には影響しないことに注意してください。TableType は、SQL_ATTR_METADATA_ID の設定にかかわらず値リスト引数です。

NameLength4SHORTin[入力] *TableType の文字数での長さ。

戻り値の型: SHORT

公式ドキュメント

SQLTables は、特定のデータソースに格納されているテーブル名、カタログ名、またはスキーマ名の一覧と、テーブルの種類を返します。ドライバーはこの情報を結果セットとして返します。

戻り値

SQL_SUCCESS、SQL_SUCCESS_WITH_INFO、SQL_STILL_EXECUTING、SQL_ERROR、または SQL_INVALID_HANDLE。

解説(Remarks)

SQLTables は、要求された範囲内のすべてのテーブルを一覧表示します。ユーザーがこれらのテーブルに対して SELECT 特権を持っているとは限りません。アクセスできるかどうかを確認するには、アプリケーションで次の方法を使用できます。

それ以外の場合、アプリケーションは、SELECT 特権が付与されていないテーブルをユーザーが選択した状況に対処できる必要があります。

SchemaName 引数と TableName 引数は検索パターンを受け付けます。CatalogName 引数は、SQL_ODBC_VERSION 環境属性が SQL_OV_ODBC3 の場合は検索パターンを受け付けますが、SQL_OV_ODBC2 が設定されている場合は受け付けません。SQL_OV_ODBC3 が設定されている場合、ODBC 3*.x* ドライバーは、CatalogName 引数内のワイルドカード文字をリテラルとして扱うためにエスケープすることを要求します。有効な検索パターンの詳細については、「Pattern Value Arguments」を参照してください。

メモ

ODBC カタログ関数の一般的な用途、引数、および返されるデータの詳細については、「Catalog Functions」を参照してください。

カタログ、スキーマ、およびテーブルの種類の列挙をサポートするために、SQLTables の CatalogName、SchemaName、TableName、TableType の各引数には次の特別なセマンティクスが定義されています。

TableType が空文字列でない場合は、対象とする種類をコンマ区切りで列挙した一覧を指定する必要があります。各値は単一引用符 (') で囲むことも、囲まないこともできます (例: 'TABLE', 'VIEW' または TABLE, VIEW)。アプリケーションでは常にテーブルの種類を大文字で指定してください。ドライバーは、データソースが必要とする大文字小文字にテーブルの種類を変換します。データソースが指定されたテーブルの種類をサポートしていない場合、SQLTables はその種類に対して結果を返しません。

SQLTables は、TABLE_TYPE、TABLE_CAT、TABLE_SCHEM、TABLE_NAME の順に並べ替えた標準の結果セットとして結果を返します。この情報の利用方法については、「Uses of Catalog Data」を参照してください。

TABLE_CAT、TABLE_SCHEM、TABLE_NAME の各列の実際の長さを調べるには、アプリケーションで SQL_MAX_CATALOG_NAME_LEN、SQL_MAX_SCHEMA_NAME_LEN、SQL_MAX_TABLE_NAME_LEN の各情報型を指定して SQLGetInfo を呼び出します。

次の列は ODBC 3*.x* で名前が変更されました。アプリケーションは列番号でバインドするため、列名の変更が下位互換性に影響することはありません。

ODBC 2.0 の列 ODBC 3*.x* の列
TABLE_QUALIFIER TABLE_CAT
TABLE_OWNER TABLE_SCHEM

次の表に、結果セットの列を示します。5 列目 (REMARKS) より後の列は、ドライバーが追加で定義できます。アプリケーションでは、明示的な序数位置を指定するのではなく、結果セットの末尾から逆に数えることでドライバー固有の列にアクセスしてください。詳細については、「Data Returned by Catalog Functions」を参照してください。

列名 列番号 データ型 コメント
TABLE_CAT (ODBC 1.0) 1 Varchar カタログ名。データソースに該当しない場合は NULL。異なる DBMS からデータを取得する場合のように、ドライバーが一部のテーブルではカタログをサポートし、他のテーブルではサポートしない場合、カタログを持たないテーブルについては空文字列 ("") を返します。
TABLE_SCHEM (ODBC 1.0) 2 Varchar スキーマ名。データソースに該当しない場合は NULL。異なる DBMS からデータを取得する場合のように、ドライバーが一部のテーブルではスキーマをサポートし、他のテーブルではサポートしない場合、スキーマを持たないテーブルについては空文字列 ("") を返します。
TABLE_NAME (ODBC 1.0) 3 Varchar テーブル名。
TABLE_TYPE (ODBC 1.0) 4 Varchar テーブルの種類の名前。次のいずれかです: "TABLE"、"VIEW"、"SYSTEM TABLE"、"GLOBAL TEMPORARY"、"LOCAL TEMPORARY"、"ALIAS"、"SYNONYM"、またはデータソース固有の種類名。

"ALIAS" と "SYNONYM" の意味はドライバー固有です。
REMARKS (ODBC 1.0) 5 Varchar テーブルの説明。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp)

各言語での呼び出し定義

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

SHORT SQLTables(
    void* StatementHandle,
    BYTE* CatalogName,   // optional
    SHORT NameLength1,
    BYTE* SchemaName,   // optional
    SHORT NameLength2,
    BYTE* TableName,   // optional
    SHORT NameLength3,
    BYTE* TableType,   // optional
    SHORT NameLength4
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLTables(
    IntPtr StatementHandle,   // void* in/out
    IntPtr CatalogName,   // BYTE* optional
    short NameLength1,   // SHORT
    IntPtr SchemaName,   // BYTE* optional
    short NameLength2,   // SHORT
    IntPtr TableName,   // BYTE* optional
    short NameLength3,   // SHORT
    IntPtr TableType,   // BYTE* optional
    short NameLength4   // SHORT
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLTables(
    StatementHandle As IntPtr,   ' void* in/out
    CatalogName As IntPtr,   ' BYTE* optional
    NameLength1 As Short,   ' SHORT
    SchemaName As IntPtr,   ' BYTE* optional
    NameLength2 As Short,   ' SHORT
    TableName As IntPtr,   ' BYTE* optional
    NameLength3 As Short,   ' SHORT
    TableType As IntPtr,   ' BYTE* optional
    NameLength4 As Short   ' SHORT
) As Short
End Function
' StatementHandle : void* in/out
' CatalogName : BYTE* optional
' NameLength1 : SHORT
' SchemaName : BYTE* optional
' NameLength2 : SHORT
' TableName : BYTE* optional
' NameLength3 : SHORT
' TableType : BYTE* optional
' NameLength4 : SHORT
Declare PtrSafe Function SQLTables Lib "odbc32" ( _
    ByVal StatementHandle As LongPtr, _
    ByVal CatalogName As LongPtr, _
    ByVal NameLength1 As Integer, _
    ByVal SchemaName As LongPtr, _
    ByVal NameLength2 As Integer, _
    ByVal TableName As LongPtr, _
    ByVal NameLength3 As Integer, _
    ByVal TableType As LongPtr, _
    ByVal NameLength4 As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLTables = ctypes.windll.odbc32.SQLTables
SQLTables.restype = ctypes.c_short
SQLTables.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # CatalogName : BYTE* optional
    ctypes.c_short,  # NameLength1 : SHORT
    ctypes.POINTER(ctypes.c_ubyte),  # SchemaName : BYTE* optional
    ctypes.c_short,  # NameLength2 : SHORT
    ctypes.POINTER(ctypes.c_ubyte),  # TableName : BYTE* optional
    ctypes.c_short,  # NameLength3 : SHORT
    ctypes.POINTER(ctypes.c_ubyte),  # TableType : BYTE* optional
    ctypes.c_short,  # NameLength4 : SHORT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLTables = Fiddle::Function.new(
  lib['SQLTables'],
  [
    Fiddle::TYPE_VOIDP,  # StatementHandle : void* in/out
    Fiddle::TYPE_VOIDP,  # CatalogName : BYTE* optional
    Fiddle::TYPE_SHORT,  # NameLength1 : SHORT
    Fiddle::TYPE_VOIDP,  # SchemaName : BYTE* optional
    Fiddle::TYPE_SHORT,  # NameLength2 : SHORT
    Fiddle::TYPE_VOIDP,  # TableName : BYTE* optional
    Fiddle::TYPE_SHORT,  # NameLength3 : SHORT
    Fiddle::TYPE_VOIDP,  # TableType : BYTE* optional
    Fiddle::TYPE_SHORT,  # NameLength4 : SHORT
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLTables(
        StatementHandle: *mut (),  // void* in/out
        CatalogName: *mut u8,  // BYTE* optional
        NameLength1: i16,  // SHORT
        SchemaName: *mut u8,  // BYTE* optional
        NameLength2: i16,  // SHORT
        TableName: *mut u8,  // BYTE* optional
        NameLength3: i16,  // SHORT
        TableType: *mut u8,  // BYTE* optional
        NameLength4: i16  // SHORT
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLTables(IntPtr StatementHandle, IntPtr CatalogName, short NameLength1, IntPtr SchemaName, short NameLength2, IntPtr TableName, short NameLength3, IntPtr TableType, short NameLength4);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLTables' -Namespace Win32 -PassThru
# $api::SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
#uselib "ODBC32.dll"
#func global SQLTables "SQLTables" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLTables StatementHandle, varptr(CatalogName), NameLength1, varptr(SchemaName), NameLength2, varptr(TableName), NameLength3, varptr(TableType), NameLength4   ; 戻り値は stat
; StatementHandle : void* in/out -> "sptr"
; CatalogName : BYTE* optional -> "sptr"
; NameLength1 : SHORT -> "sptr"
; SchemaName : BYTE* optional -> "sptr"
; NameLength2 : SHORT -> "sptr"
; TableName : BYTE* optional -> "sptr"
; NameLength3 : SHORT -> "sptr"
; TableType : BYTE* optional -> "sptr"
; NameLength4 : SHORT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLTables "SQLTables" sptr, var, int, var, int, var, int, var, int
; res = SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
; StatementHandle : void* in/out -> "sptr"
; CatalogName : BYTE* optional -> "var"
; NameLength1 : SHORT -> "int"
; SchemaName : BYTE* optional -> "var"
; NameLength2 : SHORT -> "int"
; TableName : BYTE* optional -> "var"
; NameLength3 : SHORT -> "int"
; TableType : BYTE* optional -> "var"
; NameLength4 : SHORT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLTables(void* StatementHandle, BYTE* CatalogName, SHORT NameLength1, BYTE* SchemaName, SHORT NameLength2, BYTE* TableName, SHORT NameLength3, BYTE* TableType, SHORT NameLength4)
#uselib "ODBC32.dll"
#cfunc global SQLTables "SQLTables" intptr, var, int, var, int, var, int, var, int
; res = SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
; StatementHandle : void* in/out -> "intptr"
; CatalogName : BYTE* optional -> "var"
; NameLength1 : SHORT -> "int"
; SchemaName : BYTE* optional -> "var"
; NameLength2 : SHORT -> "int"
; TableName : BYTE* optional -> "var"
; NameLength3 : SHORT -> "int"
; TableType : BYTE* optional -> "var"
; NameLength4 : SHORT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLTables = odbc32.NewProc("SQLTables")
)

// StatementHandle (void* in/out), CatalogName (BYTE* optional), NameLength1 (SHORT), SchemaName (BYTE* optional), NameLength2 (SHORT), TableName (BYTE* optional), NameLength3 (SHORT), TableType (BYTE* optional), NameLength4 (SHORT)
r1, _, err := procSQLTables.Call(
	uintptr(StatementHandle),
	uintptr(CatalogName),
	uintptr(NameLength1),
	uintptr(SchemaName),
	uintptr(NameLength2),
	uintptr(TableName),
	uintptr(NameLength3),
	uintptr(TableType),
	uintptr(NameLength4),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLTables(
  StatementHandle: Pointer;   // void* in/out
  CatalogName: Pointer;   // BYTE* optional
  NameLength1: Smallint;   // SHORT
  SchemaName: Pointer;   // BYTE* optional
  NameLength2: Smallint;   // SHORT
  TableName: Pointer;   // BYTE* optional
  NameLength3: Smallint;   // SHORT
  TableType: Pointer;   // BYTE* optional
  NameLength4: Smallint   // SHORT
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLTables';
result := DllCall("ODBC32\SQLTables"
    , "Ptr", StatementHandle   ; void* in/out
    , "Ptr", CatalogName   ; BYTE* optional
    , "Short", NameLength1   ; SHORT
    , "Ptr", SchemaName   ; BYTE* optional
    , "Short", NameLength2   ; SHORT
    , "Ptr", TableName   ; BYTE* optional
    , "Short", NameLength3   ; SHORT
    , "Ptr", TableType   ; BYTE* optional
    , "Short", NameLength4   ; SHORT
    , "Short")   ; return: SHORT
●SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4) = DLL("ODBC32.dll", "int SQLTables(void*, void*, int, void*, int, void*, int, void*, int)")
# 呼び出し: SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
# StatementHandle : void* in/out -> "void*"
# CatalogName : BYTE* optional -> "void*"
# NameLength1 : SHORT -> "int"
# SchemaName : BYTE* optional -> "void*"
# NameLength2 : SHORT -> "int"
# TableName : BYTE* optional -> "void*"
# NameLength3 : SHORT -> "int"
# TableType : BYTE* optional -> "void*"
# NameLength4 : SHORT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLTables(
    StatementHandle: ?*anyopaque, // void* in/out
    CatalogName: [*c]u8, // BYTE* optional
    NameLength1: i16, // SHORT
    SchemaName: [*c]u8, // BYTE* optional
    NameLength2: i16, // SHORT
    TableName: [*c]u8, // BYTE* optional
    NameLength3: i16, // SHORT
    TableType: [*c]u8, // BYTE* optional
    NameLength4: i16 // SHORT
) callconv(std.os.windows.WINAPI) i16;
proc SQLTables(
    StatementHandle: pointer,  # void* in/out
    CatalogName: ptr uint8,  # BYTE* optional
    NameLength1: int16,  # SHORT
    SchemaName: ptr uint8,  # BYTE* optional
    NameLength2: int16,  # SHORT
    TableName: ptr uint8,  # BYTE* optional
    NameLength3: int16,  # SHORT
    TableType: ptr uint8,  # BYTE* optional
    NameLength4: int16  # SHORT
): int16 {.importc: "SQLTables", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLTables(
    void* StatementHandle,   // void* in/out
    ubyte* CatalogName,   // BYTE* optional
    short NameLength1,   // SHORT
    ubyte* SchemaName,   // BYTE* optional
    short NameLength2,   // SHORT
    ubyte* TableName,   // BYTE* optional
    short NameLength3,   // SHORT
    ubyte* TableType,   // BYTE* optional
    short NameLength4   // SHORT
);
ccall((:SQLTables, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16),
      StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
# StatementHandle : void* in/out -> Ptr{Cvoid}
# CatalogName : BYTE* optional -> Ptr{UInt8}
# NameLength1 : SHORT -> Int16
# SchemaName : BYTE* optional -> Ptr{UInt8}
# NameLength2 : SHORT -> Int16
# TableName : BYTE* optional -> Ptr{UInt8}
# NameLength3 : SHORT -> Int16
# TableType : BYTE* optional -> Ptr{UInt8}
# NameLength4 : SHORT -> Int16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLTables(
    void* StatementHandle,
    uint8_t* CatalogName,
    int16_t NameLength1,
    uint8_t* SchemaName,
    int16_t NameLength2,
    uint8_t* TableName,
    int16_t NameLength3,
    uint8_t* TableType,
    int16_t NameLength4);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
-- StatementHandle : void* in/out
-- CatalogName : BYTE* optional
-- NameLength1 : SHORT
-- SchemaName : BYTE* optional
-- NameLength2 : SHORT
-- TableName : BYTE* optional
-- NameLength3 : SHORT
-- TableType : BYTE* optional
-- NameLength4 : SHORT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLTables = lib.func('__stdcall', 'SQLTables', 'int16_t', ['void *', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t']);
// SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
// StatementHandle : void* in/out -> 'void *'
// CatalogName : BYTE* optional -> 'uint8_t *'
// NameLength1 : SHORT -> 'int16_t'
// SchemaName : BYTE* optional -> 'uint8_t *'
// NameLength2 : SHORT -> 'int16_t'
// TableName : BYTE* optional -> 'uint8_t *'
// NameLength3 : SHORT -> 'int16_t'
// TableType : BYTE* optional -> 'uint8_t *'
// NameLength4 : SHORT -> 'int16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLTables: { parameters: ["pointer", "pointer", "i16", "pointer", "i16", "pointer", "i16", "pointer", "i16"], result: "i16" },
});
// lib.symbols.SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4)
// StatementHandle : void* in/out -> "pointer"
// CatalogName : BYTE* optional -> "pointer"
// NameLength1 : SHORT -> "i16"
// SchemaName : BYTE* optional -> "pointer"
// NameLength2 : SHORT -> "i16"
// TableName : BYTE* optional -> "pointer"
// NameLength3 : SHORT -> "i16"
// TableType : BYTE* optional -> "pointer"
// NameLength4 : SHORT -> "i16"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLTables(
    void* StatementHandle,
    uint8_t* CatalogName,
    int16_t NameLength1,
    uint8_t* SchemaName,
    int16_t NameLength2,
    uint8_t* TableName,
    int16_t NameLength3,
    uint8_t* TableType,
    int16_t NameLength4);
C, "ODBC32.dll");
// $ffi->SQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, TableType, NameLength4);
// StatementHandle : void* in/out
// CatalogName : BYTE* optional
// NameLength1 : SHORT
// SchemaName : BYTE* optional
// NameLength2 : SHORT
// TableName : BYTE* optional
// NameLength3 : SHORT
// TableType : BYTE* optional
// NameLength4 : SHORT
// 構造体/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 SQLTables(
        Pointer StatementHandle,   // void* in/out
        byte[] CatalogName,   // BYTE* optional
        short NameLength1,   // SHORT
        byte[] SchemaName,   // BYTE* optional
        short NameLength2,   // SHORT
        byte[] TableName,   // BYTE* optional
        short NameLength3,   // SHORT
        byte[] TableType,   // BYTE* optional
        short NameLength4   // SHORT
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLTables = SQLTables(
    StatementHandle : Void*,   # void* in/out
    CatalogName : UInt8*,   # BYTE* optional
    NameLength1 : Int16,   # SHORT
    SchemaName : UInt8*,   # BYTE* optional
    NameLength2 : Int16,   # SHORT
    TableName : UInt8*,   # BYTE* optional
    NameLength3 : Int16,   # SHORT
    TableType : UInt8*,   # BYTE* optional
    NameLength4 : Int16   # SHORT
  ) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SQLTablesNative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16);
typedef SQLTablesDart = int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int);
final SQLTables = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLTablesNative, SQLTablesDart>('SQLTables');
// StatementHandle : void* in/out -> Pointer<Void>
// CatalogName : BYTE* optional -> Pointer<Uint8>
// NameLength1 : SHORT -> Int16
// SchemaName : BYTE* optional -> Pointer<Uint8>
// NameLength2 : SHORT -> Int16
// TableName : BYTE* optional -> Pointer<Uint8>
// NameLength3 : SHORT -> Int16
// TableType : BYTE* optional -> Pointer<Uint8>
// NameLength4 : SHORT -> Int16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLTables(
  StatementHandle: Pointer;   // void* in/out
  CatalogName: Pointer;   // BYTE* optional
  NameLength1: Smallint;   // SHORT
  SchemaName: Pointer;   // BYTE* optional
  NameLength2: Smallint;   // SHORT
  TableName: Pointer;   // BYTE* optional
  NameLength3: Smallint;   // SHORT
  TableType: Pointer;   // BYTE* optional
  NameLength4: Smallint   // SHORT
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLTables';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLTables"
  c_SQLTables :: Ptr () -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- CatalogName : BYTE* optional -> Ptr Word8
-- NameLength1 : SHORT -> Int16
-- SchemaName : BYTE* optional -> Ptr Word8
-- NameLength2 : SHORT -> Int16
-- TableName : BYTE* optional -> Ptr Word8
-- NameLength3 : SHORT -> Int16
-- TableType : BYTE* optional -> Ptr Word8
-- NameLength4 : SHORT -> Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqltables =
  foreign "SQLTables"
    ((ptr void) @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* CatalogName : BYTE* optional -> (ptr uint8_t) *)
(* NameLength1 : SHORT -> int16_t *)
(* SchemaName : BYTE* optional -> (ptr uint8_t) *)
(* NameLength2 : SHORT -> int16_t *)
(* TableName : BYTE* optional -> (ptr uint8_t) *)
(* NameLength3 : SHORT -> int16_t *)
(* TableType : BYTE* optional -> (ptr uint8_t) *)
(* NameLength4 : SHORT -> int16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLTables" sqltables :convention :stdcall) :int16
  (statement-handle :pointer)   ; void* in/out
  (catalog-name :pointer)   ; BYTE* optional
  (name-length1 :int16)   ; SHORT
  (schema-name :pointer)   ; BYTE* optional
  (name-length2 :int16)   ; SHORT
  (table-name :pointer)   ; BYTE* optional
  (name-length3 :int16)   ; SHORT
  (table-type :pointer)   ; BYTE* optional
  (name-length4 :int16))   ; SHORT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLTables = Win32::API::More->new('ODBC32',
    'short SQLTables(LPVOID StatementHandle, LPVOID CatalogName, short NameLength1, LPVOID SchemaName, short NameLength2, LPVOID TableName, short NameLength3, LPVOID TableType, short NameLength4)');
# my $ret = $SQLTables->Call($StatementHandle, $CatalogName, $NameLength1, $SchemaName, $NameLength2, $TableName, $NameLength3, $TableType, $NameLength4);
# StatementHandle : void* in/out -> LPVOID
# CatalogName : BYTE* optional -> LPVOID
# NameLength1 : SHORT -> short
# SchemaName : BYTE* optional -> LPVOID
# NameLength2 : SHORT -> short
# TableName : BYTE* optional -> LPVOID
# NameLength3 : SHORT -> short
# TableType : BYTE* optional -> LPVOID
# NameLength4 : SHORT -> short
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い