ホーム › System.Search › SQLForeignKeys
SQLForeignKeys
関数テーブル間の外部キー関係の一覧を返す。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLForeignKeys(
void* hstmt,
BYTE* szPkCatalogName, // optional
SHORT cchPkCatalogName,
BYTE* szPkSchemaName, // optional
SHORT cchPkSchemaName,
BYTE* szPkTableName, // optional
SHORT cchPkTableName,
BYTE* szFkCatalogName, // optional
SHORT cchFkCatalogName,
BYTE* szFkSchemaName, // optional
SHORT cchFkSchemaName,
BYTE* szFkTableName, // optional
SHORT cchFkTableName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hstmt | void* | inout | 結果セットを生成する対象のステートメントハンドル。 |
| szPkCatalogName | BYTE* | inoptional | 主キー側テーブルのカタログ名。ANSI文字列。NULL可。 |
| cchPkCatalogName | SHORT | in | szPkCatalogNameの文字数。SQL_NTSでNUL終端を示す。 |
| szPkSchemaName | BYTE* | inoptional | 主キー側テーブルのスキーマ名。ANSI文字列。NULL可。 |
| cchPkSchemaName | SHORT | in | szPkSchemaNameの文字数。SQL_NTSでNUL終端を示す。 |
| szPkTableName | BYTE* | inoptional | 主キー側テーブル名。ANSI文字列。NULL可。 |
| cchPkTableName | SHORT | in | szPkTableNameの文字数。SQL_NTSでNUL終端を示す。 |
| szFkCatalogName | BYTE* | inoptional | 外部キー側テーブルのカタログ名。ANSI文字列。NULL可。 |
| cchFkCatalogName | SHORT | in | szFkCatalogNameの文字数。SQL_NTSでNUL終端を示す。 |
| szFkSchemaName | BYTE* | inoptional | 外部キー側テーブルのスキーマ名。ANSI文字列。NULL可。 |
| cchFkSchemaName | SHORT | in | szFkSchemaNameの文字数。SQL_NTSでNUL終端を示す。 |
| szFkTableName | BYTE* | inoptional | 外部キー側テーブル名。ANSI文字列。NULL可。 |
| cchFkTableName | SHORT | in | szFkTableNameの文字数。SQL_NTSでNUL終端を示す。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLForeignKeys(
void* hstmt,
BYTE* szPkCatalogName, // optional
SHORT cchPkCatalogName,
BYTE* szPkSchemaName, // optional
SHORT cchPkSchemaName,
BYTE* szPkTableName, // optional
SHORT cchPkTableName,
BYTE* szFkCatalogName, // optional
SHORT cchFkCatalogName,
BYTE* szFkSchemaName, // optional
SHORT cchFkSchemaName,
BYTE* szFkTableName, // optional
SHORT cchFkTableName
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLForeignKeys(
IntPtr hstmt, // void* in/out
IntPtr szPkCatalogName, // BYTE* optional
short cchPkCatalogName, // SHORT
IntPtr szPkSchemaName, // BYTE* optional
short cchPkSchemaName, // SHORT
IntPtr szPkTableName, // BYTE* optional
short cchPkTableName, // SHORT
IntPtr szFkCatalogName, // BYTE* optional
short cchFkCatalogName, // SHORT
IntPtr szFkSchemaName, // BYTE* optional
short cchFkSchemaName, // SHORT
IntPtr szFkTableName, // BYTE* optional
short cchFkTableName // SHORT
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLForeignKeys(
hstmt As IntPtr, ' void* in/out
szPkCatalogName As IntPtr, ' BYTE* optional
cchPkCatalogName As Short, ' SHORT
szPkSchemaName As IntPtr, ' BYTE* optional
cchPkSchemaName As Short, ' SHORT
szPkTableName As IntPtr, ' BYTE* optional
cchPkTableName As Short, ' SHORT
szFkCatalogName As IntPtr, ' BYTE* optional
cchFkCatalogName As Short, ' SHORT
szFkSchemaName As IntPtr, ' BYTE* optional
cchFkSchemaName As Short, ' SHORT
szFkTableName As IntPtr, ' BYTE* optional
cchFkTableName As Short ' SHORT
) As Short
End Function' hstmt : void* in/out
' szPkCatalogName : BYTE* optional
' cchPkCatalogName : SHORT
' szPkSchemaName : BYTE* optional
' cchPkSchemaName : SHORT
' szPkTableName : BYTE* optional
' cchPkTableName : SHORT
' szFkCatalogName : BYTE* optional
' cchFkCatalogName : SHORT
' szFkSchemaName : BYTE* optional
' cchFkSchemaName : SHORT
' szFkTableName : BYTE* optional
' cchFkTableName : SHORT
Declare PtrSafe Function SQLForeignKeys Lib "odbc32" ( _
ByVal hstmt As LongPtr, _
ByVal szPkCatalogName As LongPtr, _
ByVal cchPkCatalogName As Integer, _
ByVal szPkSchemaName As LongPtr, _
ByVal cchPkSchemaName As Integer, _
ByVal szPkTableName As LongPtr, _
ByVal cchPkTableName As Integer, _
ByVal szFkCatalogName As LongPtr, _
ByVal cchFkCatalogName As Integer, _
ByVal szFkSchemaName As LongPtr, _
ByVal cchFkSchemaName As Integer, _
ByVal szFkTableName As LongPtr, _
ByVal cchFkTableName As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLForeignKeys = ctypes.windll.odbc32.SQLForeignKeys
SQLForeignKeys.restype = ctypes.c_short
SQLForeignKeys.argtypes = [
ctypes.POINTER(None), # hstmt : void* in/out
ctypes.POINTER(ctypes.c_ubyte), # szPkCatalogName : BYTE* optional
ctypes.c_short, # cchPkCatalogName : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szPkSchemaName : BYTE* optional
ctypes.c_short, # cchPkSchemaName : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szPkTableName : BYTE* optional
ctypes.c_short, # cchPkTableName : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szFkCatalogName : BYTE* optional
ctypes.c_short, # cchFkCatalogName : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szFkSchemaName : BYTE* optional
ctypes.c_short, # cchFkSchemaName : SHORT
ctypes.POINTER(ctypes.c_ubyte), # szFkTableName : BYTE* optional
ctypes.c_short, # cchFkTableName : SHORT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLForeignKeys = Fiddle::Function.new(
lib['SQLForeignKeys'],
[
Fiddle::TYPE_VOIDP, # hstmt : void* in/out
Fiddle::TYPE_VOIDP, # szPkCatalogName : BYTE* optional
Fiddle::TYPE_SHORT, # cchPkCatalogName : SHORT
Fiddle::TYPE_VOIDP, # szPkSchemaName : BYTE* optional
Fiddle::TYPE_SHORT, # cchPkSchemaName : SHORT
Fiddle::TYPE_VOIDP, # szPkTableName : BYTE* optional
Fiddle::TYPE_SHORT, # cchPkTableName : SHORT
Fiddle::TYPE_VOIDP, # szFkCatalogName : BYTE* optional
Fiddle::TYPE_SHORT, # cchFkCatalogName : SHORT
Fiddle::TYPE_VOIDP, # szFkSchemaName : BYTE* optional
Fiddle::TYPE_SHORT, # cchFkSchemaName : SHORT
Fiddle::TYPE_VOIDP, # szFkTableName : BYTE* optional
Fiddle::TYPE_SHORT, # cchFkTableName : SHORT
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLForeignKeys(
hstmt: *mut (), // void* in/out
szPkCatalogName: *mut u8, // BYTE* optional
cchPkCatalogName: i16, // SHORT
szPkSchemaName: *mut u8, // BYTE* optional
cchPkSchemaName: i16, // SHORT
szPkTableName: *mut u8, // BYTE* optional
cchPkTableName: i16, // SHORT
szFkCatalogName: *mut u8, // BYTE* optional
cchFkCatalogName: i16, // SHORT
szFkSchemaName: *mut u8, // BYTE* optional
cchFkSchemaName: i16, // SHORT
szFkTableName: *mut u8, // BYTE* optional
cchFkTableName: i16 // SHORT
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLForeignKeys(IntPtr hstmt, IntPtr szPkCatalogName, short cchPkCatalogName, IntPtr szPkSchemaName, short cchPkSchemaName, IntPtr szPkTableName, short cchPkTableName, IntPtr szFkCatalogName, short cchFkCatalogName, IntPtr szFkSchemaName, short cchFkSchemaName, IntPtr szFkTableName, short cchFkTableName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLForeignKeys' -Namespace Win32 -PassThru
# $api::SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName)#uselib "ODBC32.dll"
#func global SQLForeignKeys "SQLForeignKeys" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLForeignKeys hstmt, varptr(szPkCatalogName), cchPkCatalogName, varptr(szPkSchemaName), cchPkSchemaName, varptr(szPkTableName), cchPkTableName, varptr(szFkCatalogName), cchFkCatalogName, varptr(szFkSchemaName), cchFkSchemaName, varptr(szFkTableName), cchFkTableName ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; szPkCatalogName : BYTE* optional -> "sptr"
; cchPkCatalogName : SHORT -> "sptr"
; szPkSchemaName : BYTE* optional -> "sptr"
; cchPkSchemaName : SHORT -> "sptr"
; szPkTableName : BYTE* optional -> "sptr"
; cchPkTableName : SHORT -> "sptr"
; szFkCatalogName : BYTE* optional -> "sptr"
; cchFkCatalogName : SHORT -> "sptr"
; szFkSchemaName : BYTE* optional -> "sptr"
; cchFkSchemaName : SHORT -> "sptr"
; szFkTableName : BYTE* optional -> "sptr"
; cchFkTableName : SHORT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLForeignKeys "SQLForeignKeys" sptr, var, int, var, int, var, int, var, int, var, int, var, int ; res = SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName) ; hstmt : void* in/out -> "sptr" ; szPkCatalogName : BYTE* optional -> "var" ; cchPkCatalogName : SHORT -> "int" ; szPkSchemaName : BYTE* optional -> "var" ; cchPkSchemaName : SHORT -> "int" ; szPkTableName : BYTE* optional -> "var" ; cchPkTableName : SHORT -> "int" ; szFkCatalogName : BYTE* optional -> "var" ; cchFkCatalogName : SHORT -> "int" ; szFkSchemaName : BYTE* optional -> "var" ; cchFkSchemaName : SHORT -> "int" ; szFkTableName : BYTE* optional -> "var" ; cchFkTableName : SHORT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLForeignKeys "SQLForeignKeys" sptr, sptr, int, sptr, int, sptr, int, sptr, int, sptr, int, sptr, int ; res = SQLForeignKeys(hstmt, varptr(szPkCatalogName), cchPkCatalogName, varptr(szPkSchemaName), cchPkSchemaName, varptr(szPkTableName), cchPkTableName, varptr(szFkCatalogName), cchFkCatalogName, varptr(szFkSchemaName), cchFkSchemaName, varptr(szFkTableName), cchFkTableName) ; hstmt : void* in/out -> "sptr" ; szPkCatalogName : BYTE* optional -> "sptr" ; cchPkCatalogName : SHORT -> "int" ; szPkSchemaName : BYTE* optional -> "sptr" ; cchPkSchemaName : SHORT -> "int" ; szPkTableName : BYTE* optional -> "sptr" ; cchPkTableName : SHORT -> "int" ; szFkCatalogName : BYTE* optional -> "sptr" ; cchFkCatalogName : SHORT -> "int" ; szFkSchemaName : BYTE* optional -> "sptr" ; cchFkSchemaName : SHORT -> "int" ; szFkTableName : BYTE* optional -> "sptr" ; cchFkTableName : SHORT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLForeignKeys(void* hstmt, BYTE* szPkCatalogName, SHORT cchPkCatalogName, BYTE* szPkSchemaName, SHORT cchPkSchemaName, BYTE* szPkTableName, SHORT cchPkTableName, BYTE* szFkCatalogName, SHORT cchFkCatalogName, BYTE* szFkSchemaName, SHORT cchFkSchemaName, BYTE* szFkTableName, SHORT cchFkTableName) #uselib "ODBC32.dll" #cfunc global SQLForeignKeys "SQLForeignKeys" intptr, var, int, var, int, var, int, var, int, var, int, var, int ; res = SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName) ; hstmt : void* in/out -> "intptr" ; szPkCatalogName : BYTE* optional -> "var" ; cchPkCatalogName : SHORT -> "int" ; szPkSchemaName : BYTE* optional -> "var" ; cchPkSchemaName : SHORT -> "int" ; szPkTableName : BYTE* optional -> "var" ; cchPkTableName : SHORT -> "int" ; szFkCatalogName : BYTE* optional -> "var" ; cchFkCatalogName : SHORT -> "int" ; szFkSchemaName : BYTE* optional -> "var" ; cchFkSchemaName : SHORT -> "int" ; szFkTableName : BYTE* optional -> "var" ; cchFkTableName : SHORT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLForeignKeys(void* hstmt, BYTE* szPkCatalogName, SHORT cchPkCatalogName, BYTE* szPkSchemaName, SHORT cchPkSchemaName, BYTE* szPkTableName, SHORT cchPkTableName, BYTE* szFkCatalogName, SHORT cchFkCatalogName, BYTE* szFkSchemaName, SHORT cchFkSchemaName, BYTE* szFkTableName, SHORT cchFkTableName) #uselib "ODBC32.dll" #cfunc global SQLForeignKeys "SQLForeignKeys" intptr, intptr, int, intptr, int, intptr, int, intptr, int, intptr, int, intptr, int ; res = SQLForeignKeys(hstmt, varptr(szPkCatalogName), cchPkCatalogName, varptr(szPkSchemaName), cchPkSchemaName, varptr(szPkTableName), cchPkTableName, varptr(szFkCatalogName), cchFkCatalogName, varptr(szFkSchemaName), cchFkSchemaName, varptr(szFkTableName), cchFkTableName) ; hstmt : void* in/out -> "intptr" ; szPkCatalogName : BYTE* optional -> "intptr" ; cchPkCatalogName : SHORT -> "int" ; szPkSchemaName : BYTE* optional -> "intptr" ; cchPkSchemaName : SHORT -> "int" ; szPkTableName : BYTE* optional -> "intptr" ; cchPkTableName : SHORT -> "int" ; szFkCatalogName : BYTE* optional -> "intptr" ; cchFkCatalogName : SHORT -> "int" ; szFkSchemaName : BYTE* optional -> "intptr" ; cchFkSchemaName : SHORT -> "int" ; szFkTableName : BYTE* optional -> "intptr" ; cchFkTableName : SHORT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLForeignKeys = odbc32.NewProc("SQLForeignKeys")
)
// hstmt (void* in/out), szPkCatalogName (BYTE* optional), cchPkCatalogName (SHORT), szPkSchemaName (BYTE* optional), cchPkSchemaName (SHORT), szPkTableName (BYTE* optional), cchPkTableName (SHORT), szFkCatalogName (BYTE* optional), cchFkCatalogName (SHORT), szFkSchemaName (BYTE* optional), cchFkSchemaName (SHORT), szFkTableName (BYTE* optional), cchFkTableName (SHORT)
r1, _, err := procSQLForeignKeys.Call(
uintptr(hstmt),
uintptr(szPkCatalogName),
uintptr(cchPkCatalogName),
uintptr(szPkSchemaName),
uintptr(cchPkSchemaName),
uintptr(szPkTableName),
uintptr(cchPkTableName),
uintptr(szFkCatalogName),
uintptr(cchFkCatalogName),
uintptr(szFkSchemaName),
uintptr(cchFkSchemaName),
uintptr(szFkTableName),
uintptr(cchFkTableName),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLForeignKeys(
hstmt: Pointer; // void* in/out
szPkCatalogName: Pointer; // BYTE* optional
cchPkCatalogName: Smallint; // SHORT
szPkSchemaName: Pointer; // BYTE* optional
cchPkSchemaName: Smallint; // SHORT
szPkTableName: Pointer; // BYTE* optional
cchPkTableName: Smallint; // SHORT
szFkCatalogName: Pointer; // BYTE* optional
cchFkCatalogName: Smallint; // SHORT
szFkSchemaName: Pointer; // BYTE* optional
cchFkSchemaName: Smallint; // SHORT
szFkTableName: Pointer; // BYTE* optional
cchFkTableName: Smallint // SHORT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLForeignKeys';result := DllCall("ODBC32\SQLForeignKeys"
, "Ptr", hstmt ; void* in/out
, "Ptr", szPkCatalogName ; BYTE* optional
, "Short", cchPkCatalogName ; SHORT
, "Ptr", szPkSchemaName ; BYTE* optional
, "Short", cchPkSchemaName ; SHORT
, "Ptr", szPkTableName ; BYTE* optional
, "Short", cchPkTableName ; SHORT
, "Ptr", szFkCatalogName ; BYTE* optional
, "Short", cchFkCatalogName ; SHORT
, "Ptr", szFkSchemaName ; BYTE* optional
, "Short", cchFkSchemaName ; SHORT
, "Ptr", szFkTableName ; BYTE* optional
, "Short", cchFkTableName ; SHORT
, "Short") ; return: SHORT●SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName) = DLL("ODBC32.dll", "int SQLForeignKeys(void*, void*, int, void*, int, void*, int, void*, int, void*, int, void*, int)")
# 呼び出し: SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName)
# hstmt : void* in/out -> "void*"
# szPkCatalogName : BYTE* optional -> "void*"
# cchPkCatalogName : SHORT -> "int"
# szPkSchemaName : BYTE* optional -> "void*"
# cchPkSchemaName : SHORT -> "int"
# szPkTableName : BYTE* optional -> "void*"
# cchPkTableName : SHORT -> "int"
# szFkCatalogName : BYTE* optional -> "void*"
# cchFkCatalogName : SHORT -> "int"
# szFkSchemaName : BYTE* optional -> "void*"
# cchFkSchemaName : SHORT -> "int"
# szFkTableName : BYTE* optional -> "void*"
# cchFkTableName : SHORT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLForeignKeys(
hstmt: ?*anyopaque, // void* in/out
szPkCatalogName: [*c]u8, // BYTE* optional
cchPkCatalogName: i16, // SHORT
szPkSchemaName: [*c]u8, // BYTE* optional
cchPkSchemaName: i16, // SHORT
szPkTableName: [*c]u8, // BYTE* optional
cchPkTableName: i16, // SHORT
szFkCatalogName: [*c]u8, // BYTE* optional
cchFkCatalogName: i16, // SHORT
szFkSchemaName: [*c]u8, // BYTE* optional
cchFkSchemaName: i16, // SHORT
szFkTableName: [*c]u8, // BYTE* optional
cchFkTableName: i16 // SHORT
) callconv(std.os.windows.WINAPI) i16;proc SQLForeignKeys(
hstmt: pointer, # void* in/out
szPkCatalogName: ptr uint8, # BYTE* optional
cchPkCatalogName: int16, # SHORT
szPkSchemaName: ptr uint8, # BYTE* optional
cchPkSchemaName: int16, # SHORT
szPkTableName: ptr uint8, # BYTE* optional
cchPkTableName: int16, # SHORT
szFkCatalogName: ptr uint8, # BYTE* optional
cchFkCatalogName: int16, # SHORT
szFkSchemaName: ptr uint8, # BYTE* optional
cchFkSchemaName: int16, # SHORT
szFkTableName: ptr uint8, # BYTE* optional
cchFkTableName: int16 # SHORT
): int16 {.importc: "SQLForeignKeys", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLForeignKeys(
void* hstmt, // void* in/out
ubyte* szPkCatalogName, // BYTE* optional
short cchPkCatalogName, // SHORT
ubyte* szPkSchemaName, // BYTE* optional
short cchPkSchemaName, // SHORT
ubyte* szPkTableName, // BYTE* optional
short cchPkTableName, // SHORT
ubyte* szFkCatalogName, // BYTE* optional
short cchFkCatalogName, // SHORT
ubyte* szFkSchemaName, // BYTE* optional
short cchFkSchemaName, // SHORT
ubyte* szFkTableName, // BYTE* optional
short cchFkTableName // SHORT
);ccall((:SQLForeignKeys, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16, Ptr{UInt8}, Int16),
hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName)
# hstmt : void* in/out -> Ptr{Cvoid}
# szPkCatalogName : BYTE* optional -> Ptr{UInt8}
# cchPkCatalogName : SHORT -> Int16
# szPkSchemaName : BYTE* optional -> Ptr{UInt8}
# cchPkSchemaName : SHORT -> Int16
# szPkTableName : BYTE* optional -> Ptr{UInt8}
# cchPkTableName : SHORT -> Int16
# szFkCatalogName : BYTE* optional -> Ptr{UInt8}
# cchFkCatalogName : SHORT -> Int16
# szFkSchemaName : BYTE* optional -> Ptr{UInt8}
# cchFkSchemaName : SHORT -> Int16
# szFkTableName : BYTE* optional -> Ptr{UInt8}
# cchFkTableName : SHORT -> Int16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLForeignKeys(
void* hstmt,
uint8_t* szPkCatalogName,
int16_t cchPkCatalogName,
uint8_t* szPkSchemaName,
int16_t cchPkSchemaName,
uint8_t* szPkTableName,
int16_t cchPkTableName,
uint8_t* szFkCatalogName,
int16_t cchFkCatalogName,
uint8_t* szFkSchemaName,
int16_t cchFkSchemaName,
uint8_t* szFkTableName,
int16_t cchFkTableName);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName)
-- hstmt : void* in/out
-- szPkCatalogName : BYTE* optional
-- cchPkCatalogName : SHORT
-- szPkSchemaName : BYTE* optional
-- cchPkSchemaName : SHORT
-- szPkTableName : BYTE* optional
-- cchPkTableName : SHORT
-- szFkCatalogName : BYTE* optional
-- cchFkCatalogName : SHORT
-- szFkSchemaName : BYTE* optional
-- cchFkSchemaName : SHORT
-- szFkTableName : BYTE* optional
-- cchFkTableName : SHORT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLForeignKeys = lib.func('__stdcall', 'SQLForeignKeys', 'int16_t', ['void *', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t', 'uint8_t *', 'int16_t']);
// SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName)
// hstmt : void* in/out -> 'void *'
// szPkCatalogName : BYTE* optional -> 'uint8_t *'
// cchPkCatalogName : SHORT -> 'int16_t'
// szPkSchemaName : BYTE* optional -> 'uint8_t *'
// cchPkSchemaName : SHORT -> 'int16_t'
// szPkTableName : BYTE* optional -> 'uint8_t *'
// cchPkTableName : SHORT -> 'int16_t'
// szFkCatalogName : BYTE* optional -> 'uint8_t *'
// cchFkCatalogName : SHORT -> 'int16_t'
// szFkSchemaName : BYTE* optional -> 'uint8_t *'
// cchFkSchemaName : SHORT -> 'int16_t'
// szFkTableName : BYTE* optional -> 'uint8_t *'
// cchFkTableName : SHORT -> 'int16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLForeignKeys: { parameters: ["pointer", "pointer", "i16", "pointer", "i16", "pointer", "i16", "pointer", "i16", "pointer", "i16", "pointer", "i16"], result: "i16" },
});
// lib.symbols.SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName)
// hstmt : void* in/out -> "pointer"
// szPkCatalogName : BYTE* optional -> "pointer"
// cchPkCatalogName : SHORT -> "i16"
// szPkSchemaName : BYTE* optional -> "pointer"
// cchPkSchemaName : SHORT -> "i16"
// szPkTableName : BYTE* optional -> "pointer"
// cchPkTableName : SHORT -> "i16"
// szFkCatalogName : BYTE* optional -> "pointer"
// cchFkCatalogName : SHORT -> "i16"
// szFkSchemaName : BYTE* optional -> "pointer"
// cchFkSchemaName : SHORT -> "i16"
// szFkTableName : BYTE* optional -> "pointer"
// cchFkTableName : SHORT -> "i16"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLForeignKeys(
void* hstmt,
uint8_t* szPkCatalogName,
int16_t cchPkCatalogName,
uint8_t* szPkSchemaName,
int16_t cchPkSchemaName,
uint8_t* szPkTableName,
int16_t cchPkTableName,
uint8_t* szFkCatalogName,
int16_t cchFkCatalogName,
uint8_t* szFkSchemaName,
int16_t cchFkSchemaName,
uint8_t* szFkTableName,
int16_t cchFkTableName);
C, "ODBC32.dll");
// $ffi->SQLForeignKeys(hstmt, szPkCatalogName, cchPkCatalogName, szPkSchemaName, cchPkSchemaName, szPkTableName, cchPkTableName, szFkCatalogName, cchFkCatalogName, szFkSchemaName, cchFkSchemaName, szFkTableName, cchFkTableName);
// hstmt : void* in/out
// szPkCatalogName : BYTE* optional
// cchPkCatalogName : SHORT
// szPkSchemaName : BYTE* optional
// cchPkSchemaName : SHORT
// szPkTableName : BYTE* optional
// cchPkTableName : SHORT
// szFkCatalogName : BYTE* optional
// cchFkCatalogName : SHORT
// szFkSchemaName : BYTE* optional
// cchFkSchemaName : SHORT
// szFkTableName : BYTE* optional
// cchFkTableName : 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 SQLForeignKeys(
Pointer hstmt, // void* in/out
byte[] szPkCatalogName, // BYTE* optional
short cchPkCatalogName, // SHORT
byte[] szPkSchemaName, // BYTE* optional
short cchPkSchemaName, // SHORT
byte[] szPkTableName, // BYTE* optional
short cchPkTableName, // SHORT
byte[] szFkCatalogName, // BYTE* optional
short cchFkCatalogName, // SHORT
byte[] szFkSchemaName, // BYTE* optional
short cchFkSchemaName, // SHORT
byte[] szFkTableName, // BYTE* optional
short cchFkTableName // SHORT
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLForeignKeys = SQLForeignKeys(
hstmt : Void*, # void* in/out
szPkCatalogName : UInt8*, # BYTE* optional
cchPkCatalogName : Int16, # SHORT
szPkSchemaName : UInt8*, # BYTE* optional
cchPkSchemaName : Int16, # SHORT
szPkTableName : UInt8*, # BYTE* optional
cchPkTableName : Int16, # SHORT
szFkCatalogName : UInt8*, # BYTE* optional
cchFkCatalogName : Int16, # SHORT
szFkSchemaName : UInt8*, # BYTE* optional
cchFkSchemaName : Int16, # SHORT
szFkTableName : UInt8*, # BYTE* optional
cchFkTableName : 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 SQLForeignKeysNative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16, Pointer<Uint8>, Int16);
typedef SQLForeignKeysDart = int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint8>, int);
final SQLForeignKeys = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLForeignKeysNative, SQLForeignKeysDart>('SQLForeignKeys');
// hstmt : void* in/out -> Pointer<Void>
// szPkCatalogName : BYTE* optional -> Pointer<Uint8>
// cchPkCatalogName : SHORT -> Int16
// szPkSchemaName : BYTE* optional -> Pointer<Uint8>
// cchPkSchemaName : SHORT -> Int16
// szPkTableName : BYTE* optional -> Pointer<Uint8>
// cchPkTableName : SHORT -> Int16
// szFkCatalogName : BYTE* optional -> Pointer<Uint8>
// cchFkCatalogName : SHORT -> Int16
// szFkSchemaName : BYTE* optional -> Pointer<Uint8>
// cchFkSchemaName : SHORT -> Int16
// szFkTableName : BYTE* optional -> Pointer<Uint8>
// cchFkTableName : SHORT -> Int16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLForeignKeys(
hstmt: Pointer; // void* in/out
szPkCatalogName: Pointer; // BYTE* optional
cchPkCatalogName: Smallint; // SHORT
szPkSchemaName: Pointer; // BYTE* optional
cchPkSchemaName: Smallint; // SHORT
szPkTableName: Pointer; // BYTE* optional
cchPkTableName: Smallint; // SHORT
szFkCatalogName: Pointer; // BYTE* optional
cchFkCatalogName: Smallint; // SHORT
szFkSchemaName: Pointer; // BYTE* optional
cchFkSchemaName: Smallint; // SHORT
szFkTableName: Pointer; // BYTE* optional
cchFkTableName: Smallint // SHORT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLForeignKeys';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLForeignKeys"
c_SQLForeignKeys :: Ptr () -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> Ptr Word8 -> Int16 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- szPkCatalogName : BYTE* optional -> Ptr Word8
-- cchPkCatalogName : SHORT -> Int16
-- szPkSchemaName : BYTE* optional -> Ptr Word8
-- cchPkSchemaName : SHORT -> Int16
-- szPkTableName : BYTE* optional -> Ptr Word8
-- cchPkTableName : SHORT -> Int16
-- szFkCatalogName : BYTE* optional -> Ptr Word8
-- cchFkCatalogName : SHORT -> Int16
-- szFkSchemaName : BYTE* optional -> Ptr Word8
-- cchFkSchemaName : SHORT -> Int16
-- szFkTableName : BYTE* optional -> Ptr Word8
-- cchFkTableName : SHORT -> Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlforeignkeys =
foreign "SQLForeignKeys"
((ptr void) @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> (ptr uint8_t) @-> int16_t @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* szPkCatalogName : BYTE* optional -> (ptr uint8_t) *)
(* cchPkCatalogName : SHORT -> int16_t *)
(* szPkSchemaName : BYTE* optional -> (ptr uint8_t) *)
(* cchPkSchemaName : SHORT -> int16_t *)
(* szPkTableName : BYTE* optional -> (ptr uint8_t) *)
(* cchPkTableName : SHORT -> int16_t *)
(* szFkCatalogName : BYTE* optional -> (ptr uint8_t) *)
(* cchFkCatalogName : SHORT -> int16_t *)
(* szFkSchemaName : BYTE* optional -> (ptr uint8_t) *)
(* cchFkSchemaName : SHORT -> int16_t *)
(* szFkTableName : BYTE* optional -> (ptr uint8_t) *)
(* cchFkTableName : 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 ("SQLForeignKeys" sqlforeign-keys :convention :stdcall) :int16
(hstmt :pointer) ; void* in/out
(sz-pk-catalog-name :pointer) ; BYTE* optional
(cch-pk-catalog-name :int16) ; SHORT
(sz-pk-schema-name :pointer) ; BYTE* optional
(cch-pk-schema-name :int16) ; SHORT
(sz-pk-table-name :pointer) ; BYTE* optional
(cch-pk-table-name :int16) ; SHORT
(sz-fk-catalog-name :pointer) ; BYTE* optional
(cch-fk-catalog-name :int16) ; SHORT
(sz-fk-schema-name :pointer) ; BYTE* optional
(cch-fk-schema-name :int16) ; SHORT
(sz-fk-table-name :pointer) ; BYTE* optional
(cch-fk-table-name :int16)) ; SHORT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLForeignKeys = Win32::API::More->new('ODBC32',
'short SQLForeignKeys(LPVOID hstmt, LPVOID szPkCatalogName, short cchPkCatalogName, LPVOID szPkSchemaName, short cchPkSchemaName, LPVOID szPkTableName, short cchPkTableName, LPVOID szFkCatalogName, short cchFkCatalogName, LPVOID szFkSchemaName, short cchFkSchemaName, LPVOID szFkTableName, short cchFkTableName)');
# my $ret = $SQLForeignKeys->Call($hstmt, $szPkCatalogName, $cchPkCatalogName, $szPkSchemaName, $cchPkSchemaName, $szPkTableName, $cchPkTableName, $szFkCatalogName, $cchFkCatalogName, $szFkSchemaName, $cchFkSchemaName, $szFkTableName, $cchFkTableName);
# hstmt : void* in/out -> LPVOID
# szPkCatalogName : BYTE* optional -> LPVOID
# cchPkCatalogName : SHORT -> short
# szPkSchemaName : BYTE* optional -> LPVOID
# cchPkSchemaName : SHORT -> short
# szPkTableName : BYTE* optional -> LPVOID
# cchPkTableName : SHORT -> short
# szFkCatalogName : BYTE* optional -> LPVOID
# cchFkCatalogName : SHORT -> short
# szFkSchemaName : BYTE* optional -> LPVOID
# cchFkSchemaName : SHORT -> short
# szFkTableName : BYTE* optional -> LPVOID
# cchFkTableName : SHORT -> short
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLForeignKeysA (ANSI版) — テーブルの外部キーと参照関係の情報を取得する。
- f SQLForeignKeysW (Unicode版) — テーブル間の外部キー関係の一覧を返す(Unicode)。