ホーム › System.Search › SQLGetDescRecW
SQLGetDescRecW
関数記述子レコードの複数フィールド値をまとめて取得する(Unicode)。
シグネチャ
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLGetDescRecW(
void* hdesc,
SHORT iRecord,
WORD* szName, // optional
SHORT cchNameMax,
SHORT* pcchName, // optional
SHORT* pfType, // optional
SHORT* pfSubType, // optional
INT* pLength, // optional
SHORT* pPrecision, // optional
SHORT* pScale, // optional
SHORT* pNullable // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdesc | void* | inout | 対象の記述子ハンドル。 |
| iRecord | SHORT | in | 取得対象のレコード番号。1始まりで指定する。 |
| szName | WORD* | outoptional | 列名やパラメータ名を受け取るバッファ。Unicode文字列。 |
| cchNameMax | SHORT | in | szNameバッファの文字数長。 |
| pcchName | SHORT* | outoptional | 名前の実際の文字数を受け取るポインタ。NULL可。 |
| pfType | SHORT* | outoptional | データ型(SQL型)を受け取るポインタ。NULL可。 |
| pfSubType | SHORT* | outoptional | 日時/区間型の場合のサブタイプを受け取るポインタ。NULL可。 |
| pLength | INT* | outoptional | 列の長さ(オクテット長)を受け取るポインタ。NULL可。 |
| pPrecision | SHORT* | outoptional | 数値の有効桁数(精度)を受け取るポインタ。NULL可。 |
| pScale | SHORT* | outoptional | 小数点以下桁数(スケール)を受け取るポインタ。NULL可。 |
| pNullable | SHORT* | outoptional | NULL許容フラグを受け取るポインタ。SQL_NULLABLE等。NULL可。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLGetDescRecW(
void* hdesc,
SHORT iRecord,
WORD* szName, // optional
SHORT cchNameMax,
SHORT* pcchName, // optional
SHORT* pfType, // optional
SHORT* pfSubType, // optional
INT* pLength, // optional
SHORT* pPrecision, // optional
SHORT* pScale, // optional
SHORT* pNullable // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLGetDescRecW(
IntPtr hdesc, // void* in/out
short iRecord, // SHORT
IntPtr szName, // WORD* optional, out
short cchNameMax, // SHORT
IntPtr pcchName, // SHORT* optional, out
IntPtr pfType, // SHORT* optional, out
IntPtr pfSubType, // SHORT* optional, out
IntPtr pLength, // INT* optional, out
IntPtr pPrecision, // SHORT* optional, out
IntPtr pScale, // SHORT* optional, out
IntPtr pNullable // SHORT* optional, out
);<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLGetDescRecW(
hdesc As IntPtr, ' void* in/out
iRecord As Short, ' SHORT
szName As IntPtr, ' WORD* optional, out
cchNameMax As Short, ' SHORT
pcchName As IntPtr, ' SHORT* optional, out
pfType As IntPtr, ' SHORT* optional, out
pfSubType As IntPtr, ' SHORT* optional, out
pLength As IntPtr, ' INT* optional, out
pPrecision As IntPtr, ' SHORT* optional, out
pScale As IntPtr, ' SHORT* optional, out
pNullable As IntPtr ' SHORT* optional, out
) As Short
End Function' hdesc : void* in/out
' iRecord : SHORT
' szName : WORD* optional, out
' cchNameMax : SHORT
' pcchName : SHORT* optional, out
' pfType : SHORT* optional, out
' pfSubType : SHORT* optional, out
' pLength : INT* optional, out
' pPrecision : SHORT* optional, out
' pScale : SHORT* optional, out
' pNullable : SHORT* optional, out
Declare PtrSafe Function SQLGetDescRecW Lib "odbc32" ( _
ByVal hdesc As LongPtr, _
ByVal iRecord As Integer, _
ByVal szName As LongPtr, _
ByVal cchNameMax As Integer, _
ByVal pcchName As LongPtr, _
ByVal pfType As LongPtr, _
ByVal pfSubType As LongPtr, _
ByVal pLength As LongPtr, _
ByVal pPrecision As LongPtr, _
ByVal pScale As LongPtr, _
ByVal pNullable As LongPtr) 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
SQLGetDescRecW = ctypes.windll.odbc32.SQLGetDescRecW
SQLGetDescRecW.restype = ctypes.c_short
SQLGetDescRecW.argtypes = [
ctypes.POINTER(None), # hdesc : void* in/out
ctypes.c_short, # iRecord : SHORT
ctypes.POINTER(ctypes.c_ushort), # szName : WORD* optional, out
ctypes.c_short, # cchNameMax : SHORT
ctypes.POINTER(ctypes.c_short), # pcchName : SHORT* optional, out
ctypes.POINTER(ctypes.c_short), # pfType : SHORT* optional, out
ctypes.POINTER(ctypes.c_short), # pfSubType : SHORT* optional, out
ctypes.POINTER(ctypes.c_int), # pLength : INT* optional, out
ctypes.POINTER(ctypes.c_short), # pPrecision : SHORT* optional, out
ctypes.POINTER(ctypes.c_short), # pScale : SHORT* optional, out
ctypes.POINTER(ctypes.c_short), # pNullable : SHORT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLGetDescRecW = Fiddle::Function.new(
lib['SQLGetDescRecW'],
[
Fiddle::TYPE_VOIDP, # hdesc : void* in/out
Fiddle::TYPE_SHORT, # iRecord : SHORT
Fiddle::TYPE_VOIDP, # szName : WORD* optional, out
Fiddle::TYPE_SHORT, # cchNameMax : SHORT
Fiddle::TYPE_VOIDP, # pcchName : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pfType : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pfSubType : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pLength : INT* optional, out
Fiddle::TYPE_VOIDP, # pPrecision : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pScale : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pNullable : SHORT* optional, out
],
Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "odbc32")]
extern "system" {
fn SQLGetDescRecW(
hdesc: *mut (), // void* in/out
iRecord: i16, // SHORT
szName: *mut u16, // WORD* optional, out
cchNameMax: i16, // SHORT
pcchName: *mut i16, // SHORT* optional, out
pfType: *mut i16, // SHORT* optional, out
pfSubType: *mut i16, // SHORT* optional, out
pLength: *mut i32, // INT* optional, out
pPrecision: *mut i16, // SHORT* optional, out
pScale: *mut i16, // SHORT* optional, out
pNullable: *mut i16 // SHORT* optional, out
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode)]
public static extern short SQLGetDescRecW(IntPtr hdesc, short iRecord, IntPtr szName, short cchNameMax, IntPtr pcchName, IntPtr pfType, IntPtr pfSubType, IntPtr pLength, IntPtr pPrecision, IntPtr pScale, IntPtr pNullable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetDescRecW' -Namespace Win32 -PassThru
# $api::SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable)#uselib "ODBC32.dll"
#func global SQLGetDescRecW "SQLGetDescRecW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SQLGetDescRecW hdesc, iRecord, varptr(szName), cchNameMax, varptr(pcchName), varptr(pfType), varptr(pfSubType), varptr(pLength), varptr(pPrecision), varptr(pScale), varptr(pNullable) ; 戻り値は stat
; hdesc : void* in/out -> "wptr"
; iRecord : SHORT -> "wptr"
; szName : WORD* optional, out -> "wptr"
; cchNameMax : SHORT -> "wptr"
; pcchName : SHORT* optional, out -> "wptr"
; pfType : SHORT* optional, out -> "wptr"
; pfSubType : SHORT* optional, out -> "wptr"
; pLength : INT* optional, out -> "wptr"
; pPrecision : SHORT* optional, out -> "wptr"
; pScale : SHORT* optional, out -> "wptr"
; pNullable : SHORT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLGetDescRecW "SQLGetDescRecW" sptr, int, var, int, var, var, var, var, var, var, var ; res = SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable) ; hdesc : void* in/out -> "sptr" ; iRecord : SHORT -> "int" ; szName : WORD* optional, out -> "var" ; cchNameMax : SHORT -> "int" ; pcchName : SHORT* optional, out -> "var" ; pfType : SHORT* optional, out -> "var" ; pfSubType : SHORT* optional, out -> "var" ; pLength : INT* optional, out -> "var" ; pPrecision : SHORT* optional, out -> "var" ; pScale : SHORT* optional, out -> "var" ; pNullable : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLGetDescRecW "SQLGetDescRecW" sptr, int, sptr, int, sptr, sptr, sptr, sptr, sptr, sptr, sptr ; res = SQLGetDescRecW(hdesc, iRecord, varptr(szName), cchNameMax, varptr(pcchName), varptr(pfType), varptr(pfSubType), varptr(pLength), varptr(pPrecision), varptr(pScale), varptr(pNullable)) ; hdesc : void* in/out -> "sptr" ; iRecord : SHORT -> "int" ; szName : WORD* optional, out -> "sptr" ; cchNameMax : SHORT -> "int" ; pcchName : SHORT* optional, out -> "sptr" ; pfType : SHORT* optional, out -> "sptr" ; pfSubType : SHORT* optional, out -> "sptr" ; pLength : INT* optional, out -> "sptr" ; pPrecision : SHORT* optional, out -> "sptr" ; pScale : SHORT* optional, out -> "sptr" ; pNullable : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLGetDescRecW(void* hdesc, SHORT iRecord, WORD* szName, SHORT cchNameMax, SHORT* pcchName, SHORT* pfType, SHORT* pfSubType, INT* pLength, SHORT* pPrecision, SHORT* pScale, SHORT* pNullable) #uselib "ODBC32.dll" #cfunc global SQLGetDescRecW "SQLGetDescRecW" intptr, int, var, int, var, var, var, var, var, var, var ; res = SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable) ; hdesc : void* in/out -> "intptr" ; iRecord : SHORT -> "int" ; szName : WORD* optional, out -> "var" ; cchNameMax : SHORT -> "int" ; pcchName : SHORT* optional, out -> "var" ; pfType : SHORT* optional, out -> "var" ; pfSubType : SHORT* optional, out -> "var" ; pLength : INT* optional, out -> "var" ; pPrecision : SHORT* optional, out -> "var" ; pScale : SHORT* optional, out -> "var" ; pNullable : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLGetDescRecW(void* hdesc, SHORT iRecord, WORD* szName, SHORT cchNameMax, SHORT* pcchName, SHORT* pfType, SHORT* pfSubType, INT* pLength, SHORT* pPrecision, SHORT* pScale, SHORT* pNullable) #uselib "ODBC32.dll" #cfunc global SQLGetDescRecW "SQLGetDescRecW" intptr, int, intptr, int, intptr, intptr, intptr, intptr, intptr, intptr, intptr ; res = SQLGetDescRecW(hdesc, iRecord, varptr(szName), cchNameMax, varptr(pcchName), varptr(pfType), varptr(pfSubType), varptr(pLength), varptr(pPrecision), varptr(pScale), varptr(pNullable)) ; hdesc : void* in/out -> "intptr" ; iRecord : SHORT -> "int" ; szName : WORD* optional, out -> "intptr" ; cchNameMax : SHORT -> "int" ; pcchName : SHORT* optional, out -> "intptr" ; pfType : SHORT* optional, out -> "intptr" ; pfSubType : SHORT* optional, out -> "intptr" ; pLength : INT* optional, out -> "intptr" ; pPrecision : SHORT* optional, out -> "intptr" ; pScale : SHORT* optional, out -> "intptr" ; pNullable : SHORT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLGetDescRecW = odbc32.NewProc("SQLGetDescRecW")
)
// hdesc (void* in/out), iRecord (SHORT), szName (WORD* optional, out), cchNameMax (SHORT), pcchName (SHORT* optional, out), pfType (SHORT* optional, out), pfSubType (SHORT* optional, out), pLength (INT* optional, out), pPrecision (SHORT* optional, out), pScale (SHORT* optional, out), pNullable (SHORT* optional, out)
r1, _, err := procSQLGetDescRecW.Call(
uintptr(hdesc),
uintptr(iRecord),
uintptr(szName),
uintptr(cchNameMax),
uintptr(pcchName),
uintptr(pfType),
uintptr(pfSubType),
uintptr(pLength),
uintptr(pPrecision),
uintptr(pScale),
uintptr(pNullable),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLGetDescRecW(
hdesc: Pointer; // void* in/out
iRecord: Smallint; // SHORT
szName: Pointer; // WORD* optional, out
cchNameMax: Smallint; // SHORT
pcchName: Pointer; // SHORT* optional, out
pfType: Pointer; // SHORT* optional, out
pfSubType: Pointer; // SHORT* optional, out
pLength: Pointer; // INT* optional, out
pPrecision: Pointer; // SHORT* optional, out
pScale: Pointer; // SHORT* optional, out
pNullable: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetDescRecW';result := DllCall("ODBC32\SQLGetDescRecW"
, "Ptr", hdesc ; void* in/out
, "Short", iRecord ; SHORT
, "Ptr", szName ; WORD* optional, out
, "Short", cchNameMax ; SHORT
, "Ptr", pcchName ; SHORT* optional, out
, "Ptr", pfType ; SHORT* optional, out
, "Ptr", pfSubType ; SHORT* optional, out
, "Ptr", pLength ; INT* optional, out
, "Ptr", pPrecision ; SHORT* optional, out
, "Ptr", pScale ; SHORT* optional, out
, "Ptr", pNullable ; SHORT* optional, out
, "Short") ; return: SHORT●SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable) = DLL("ODBC32.dll", "int SQLGetDescRecW(void*, int, void*, int, void*, void*, void*, void*, void*, void*, void*)")
# 呼び出し: SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable)
# hdesc : void* in/out -> "void*"
# iRecord : SHORT -> "int"
# szName : WORD* optional, out -> "void*"
# cchNameMax : SHORT -> "int"
# pcchName : SHORT* optional, out -> "void*"
# pfType : SHORT* optional, out -> "void*"
# pfSubType : SHORT* optional, out -> "void*"
# pLength : INT* optional, out -> "void*"
# pPrecision : SHORT* optional, out -> "void*"
# pScale : SHORT* optional, out -> "void*"
# pNullable : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "odbc32" fn SQLGetDescRecW(
hdesc: ?*anyopaque, // void* in/out
iRecord: i16, // SHORT
szName: [*c]u16, // WORD* optional, out
cchNameMax: i16, // SHORT
pcchName: [*c]i16, // SHORT* optional, out
pfType: [*c]i16, // SHORT* optional, out
pfSubType: [*c]i16, // SHORT* optional, out
pLength: [*c]i32, // INT* optional, out
pPrecision: [*c]i16, // SHORT* optional, out
pScale: [*c]i16, // SHORT* optional, out
pNullable: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SQLGetDescRecW(
hdesc: pointer, # void* in/out
iRecord: int16, # SHORT
szName: ptr uint16, # WORD* optional, out
cchNameMax: int16, # SHORT
pcchName: ptr int16, # SHORT* optional, out
pfType: ptr int16, # SHORT* optional, out
pfSubType: ptr int16, # SHORT* optional, out
pLength: ptr int32, # INT* optional, out
pPrecision: ptr int16, # SHORT* optional, out
pScale: ptr int16, # SHORT* optional, out
pNullable: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLGetDescRecW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "odbc32");
extern(Windows)
short SQLGetDescRecW(
void* hdesc, // void* in/out
short iRecord, // SHORT
ushort* szName, // WORD* optional, out
short cchNameMax, // SHORT
short* pcchName, // SHORT* optional, out
short* pfType, // SHORT* optional, out
short* pfSubType, // SHORT* optional, out
int* pLength, // INT* optional, out
short* pPrecision, // SHORT* optional, out
short* pScale, // SHORT* optional, out
short* pNullable // SHORT* optional, out
);ccall((:SQLGetDescRecW, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Int16, Ptr{UInt16}, Int16, Ptr{Int16}, Ptr{Int16}, Ptr{Int16}, Ptr{Int32}, Ptr{Int16}, Ptr{Int16}, Ptr{Int16}),
hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable)
# hdesc : void* in/out -> Ptr{Cvoid}
# iRecord : SHORT -> Int16
# szName : WORD* optional, out -> Ptr{UInt16}
# cchNameMax : SHORT -> Int16
# pcchName : SHORT* optional, out -> Ptr{Int16}
# pfType : SHORT* optional, out -> Ptr{Int16}
# pfSubType : SHORT* optional, out -> Ptr{Int16}
# pLength : INT* optional, out -> Ptr{Int32}
# pPrecision : SHORT* optional, out -> Ptr{Int16}
# pScale : SHORT* optional, out -> Ptr{Int16}
# pNullable : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetDescRecW(
void* hdesc,
int16_t iRecord,
uint16_t* szName,
int16_t cchNameMax,
int16_t* pcchName,
int16_t* pfType,
int16_t* pfSubType,
int32_t* pLength,
int16_t* pPrecision,
int16_t* pScale,
int16_t* pNullable);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable)
-- hdesc : void* in/out
-- iRecord : SHORT
-- szName : WORD* optional, out
-- cchNameMax : SHORT
-- pcchName : SHORT* optional, out
-- pfType : SHORT* optional, out
-- pfSubType : SHORT* optional, out
-- pLength : INT* optional, out
-- pPrecision : SHORT* optional, out
-- pScale : SHORT* optional, out
-- pNullable : SHORT* optional, out
-- 構造体/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 SQLGetDescRecW = lib.func('__stdcall', 'SQLGetDescRecW', 'int16_t', ['void *', 'int16_t', 'uint16_t *', 'int16_t', 'int16_t *', 'int16_t *', 'int16_t *', 'int32_t *', 'int16_t *', 'int16_t *', 'int16_t *']);
// SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable)
// hdesc : void* in/out -> 'void *'
// iRecord : SHORT -> 'int16_t'
// szName : WORD* optional, out -> 'uint16_t *'
// cchNameMax : SHORT -> 'int16_t'
// pcchName : SHORT* optional, out -> 'int16_t *'
// pfType : SHORT* optional, out -> 'int16_t *'
// pfSubType : SHORT* optional, out -> 'int16_t *'
// pLength : INT* optional, out -> 'int32_t *'
// pPrecision : SHORT* optional, out -> 'int16_t *'
// pScale : SHORT* optional, out -> 'int16_t *'
// pNullable : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLGetDescRecW: { parameters: ["pointer", "i16", "pointer", "i16", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable)
// hdesc : void* in/out -> "pointer"
// iRecord : SHORT -> "i16"
// szName : WORD* optional, out -> "pointer"
// cchNameMax : SHORT -> "i16"
// pcchName : SHORT* optional, out -> "pointer"
// pfType : SHORT* optional, out -> "pointer"
// pfSubType : SHORT* optional, out -> "pointer"
// pLength : INT* optional, out -> "pointer"
// pPrecision : SHORT* optional, out -> "pointer"
// pScale : SHORT* optional, out -> "pointer"
// pNullable : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetDescRecW(
void* hdesc,
int16_t iRecord,
uint16_t* szName,
int16_t cchNameMax,
int16_t* pcchName,
int16_t* pfType,
int16_t* pfSubType,
int32_t* pLength,
int16_t* pPrecision,
int16_t* pScale,
int16_t* pNullable);
C, "ODBC32.dll");
// $ffi->SQLGetDescRecW(hdesc, iRecord, szName, cchNameMax, pcchName, pfType, pfSubType, pLength, pPrecision, pScale, pNullable);
// hdesc : void* in/out
// iRecord : SHORT
// szName : WORD* optional, out
// cchNameMax : SHORT
// pcchName : SHORT* optional, out
// pfType : SHORT* optional, out
// pfSubType : SHORT* optional, out
// pLength : INT* optional, out
// pPrecision : SHORT* optional, out
// pScale : SHORT* optional, out
// pNullable : 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.UNICODE_OPTIONS);
short SQLGetDescRecW(
Pointer hdesc, // void* in/out
short iRecord, // SHORT
ShortByReference szName, // WORD* optional, out
short cchNameMax, // SHORT
ShortByReference pcchName, // SHORT* optional, out
ShortByReference pfType, // SHORT* optional, out
ShortByReference pfSubType, // SHORT* optional, out
IntByReference pLength, // INT* optional, out
ShortByReference pPrecision, // SHORT* optional, out
ShortByReference pScale, // SHORT* optional, out
ShortByReference pNullable // SHORT* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("odbc32")]
lib LibODBC32
fun SQLGetDescRecW = SQLGetDescRecW(
hdesc : Void*, # void* in/out
iRecord : Int16, # SHORT
szName : UInt16*, # WORD* optional, out
cchNameMax : Int16, # SHORT
pcchName : Int16*, # SHORT* optional, out
pfType : Int16*, # SHORT* optional, out
pfSubType : Int16*, # SHORT* optional, out
pLength : Int32*, # INT* optional, out
pPrecision : Int16*, # SHORT* optional, out
pScale : Int16*, # SHORT* optional, out
pNullable : 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 SQLGetDescRecWNative = Int16 Function(Pointer<Void>, Int16, Pointer<Uint16>, Int16, Pointer<Int16>, Pointer<Int16>, Pointer<Int16>, Pointer<Int32>, Pointer<Int16>, Pointer<Int16>, Pointer<Int16>);
typedef SQLGetDescRecWDart = int Function(Pointer<Void>, int, Pointer<Uint16>, int, Pointer<Int16>, Pointer<Int16>, Pointer<Int16>, Pointer<Int32>, Pointer<Int16>, Pointer<Int16>, Pointer<Int16>);
final SQLGetDescRecW = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLGetDescRecWNative, SQLGetDescRecWDart>('SQLGetDescRecW');
// hdesc : void* in/out -> Pointer<Void>
// iRecord : SHORT -> Int16
// szName : WORD* optional, out -> Pointer<Uint16>
// cchNameMax : SHORT -> Int16
// pcchName : SHORT* optional, out -> Pointer<Int16>
// pfType : SHORT* optional, out -> Pointer<Int16>
// pfSubType : SHORT* optional, out -> Pointer<Int16>
// pLength : INT* optional, out -> Pointer<Int32>
// pPrecision : SHORT* optional, out -> Pointer<Int16>
// pScale : SHORT* optional, out -> Pointer<Int16>
// pNullable : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLGetDescRecW(
hdesc: Pointer; // void* in/out
iRecord: Smallint; // SHORT
szName: Pointer; // WORD* optional, out
cchNameMax: Smallint; // SHORT
pcchName: Pointer; // SHORT* optional, out
pfType: Pointer; // SHORT* optional, out
pfSubType: Pointer; // SHORT* optional, out
pLength: Pointer; // INT* optional, out
pPrecision: Pointer; // SHORT* optional, out
pScale: Pointer; // SHORT* optional, out
pNullable: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetDescRecW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLGetDescRecW"
c_SQLGetDescRecW :: Ptr () -> Int16 -> Ptr Word16 -> Int16 -> Ptr Int16 -> Ptr Int16 -> Ptr Int16 -> Ptr Int32 -> Ptr Int16 -> Ptr Int16 -> Ptr Int16 -> IO Int16
-- hdesc : void* in/out -> Ptr ()
-- iRecord : SHORT -> Int16
-- szName : WORD* optional, out -> Ptr Word16
-- cchNameMax : SHORT -> Int16
-- pcchName : SHORT* optional, out -> Ptr Int16
-- pfType : SHORT* optional, out -> Ptr Int16
-- pfSubType : SHORT* optional, out -> Ptr Int16
-- pLength : INT* optional, out -> Ptr Int32
-- pPrecision : SHORT* optional, out -> Ptr Int16
-- pScale : SHORT* optional, out -> Ptr Int16
-- pNullable : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlgetdescrecw =
foreign "SQLGetDescRecW"
((ptr void) @-> int16_t @-> (ptr uint16_t) @-> int16_t @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr int32_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> returning int16_t)
(* hdesc : void* in/out -> (ptr void) *)
(* iRecord : SHORT -> int16_t *)
(* szName : WORD* optional, out -> (ptr uint16_t) *)
(* cchNameMax : SHORT -> int16_t *)
(* pcchName : SHORT* optional, out -> (ptr int16_t) *)
(* pfType : SHORT* optional, out -> (ptr int16_t) *)
(* pfSubType : SHORT* optional, out -> (ptr int16_t) *)
(* pLength : INT* optional, out -> (ptr int32_t) *)
(* pPrecision : SHORT* optional, out -> (ptr int16_t) *)
(* pScale : SHORT* optional, out -> (ptr int16_t) *)
(* pNullable : 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 ("SQLGetDescRecW" sqlget-desc-rec-w :convention :stdcall) :int16
(hdesc :pointer) ; void* in/out
(i-record :int16) ; SHORT
(sz-name :pointer) ; WORD* optional, out
(cch-name-max :int16) ; SHORT
(pcch-name :pointer) ; SHORT* optional, out
(pf-type :pointer) ; SHORT* optional, out
(pf-sub-type :pointer) ; SHORT* optional, out
(p-length :pointer) ; INT* optional, out
(p-precision :pointer) ; SHORT* optional, out
(p-scale :pointer) ; SHORT* optional, out
(p-nullable :pointer)) ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLGetDescRecW = Win32::API::More->new('ODBC32',
'short SQLGetDescRecW(LPVOID hdesc, short iRecord, LPVOID szName, short cchNameMax, LPVOID pcchName, LPVOID pfType, LPVOID pfSubType, LPVOID pLength, LPVOID pPrecision, LPVOID pScale, LPVOID pNullable)');
# my $ret = $SQLGetDescRecW->Call($hdesc, $iRecord, $szName, $cchNameMax, $pcchName, $pfType, $pfSubType, $pLength, $pPrecision, $pScale, $pNullable);
# hdesc : void* in/out -> LPVOID
# iRecord : SHORT -> short
# szName : WORD* optional, out -> LPVOID
# cchNameMax : SHORT -> short
# pcchName : SHORT* optional, out -> LPVOID
# pfType : SHORT* optional, out -> LPVOID
# pfSubType : SHORT* optional, out -> LPVOID
# pLength : INT* optional, out -> LPVOID
# pPrecision : SHORT* optional, out -> LPVOID
# pScale : SHORT* optional, out -> LPVOID
# pNullable : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SQLGetDescRecA (ANSI版) — 記述子レコードの複数フィールド値をまとめて取得する(ANSI)。