ホーム › System.Search › SQLColAttributesW
SQLColAttributesW
関数結果セット列の記述属性を取得する(Unicode・非推奨)。
シグネチャ
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLColAttributesW(
void* hstmt,
WORD icol,
WORD fDescType,
void* rgbDesc, // optional
SHORT cbDescMax,
SHORT* pcbDesc, // optional
INT* pfDesc // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hstmt | void* | inout | 対象のステートメントハンドル。非推奨でSQLColAttributeWに置換された。 |
| icol | WORD | in | 対象の列番号。1始まりで指定する。 |
| fDescType | WORD | in | 取得する属性の種別。SQL_COLUMN_*定数を指定する。 |
| rgbDesc | void* | outoptional | 文字列属性値を受け取るバッファ。Unicode文字列。 |
| cbDescMax | SHORT | in | rgbDescバッファのバイト長。 |
| pcbDesc | SHORT* | outoptional | rgbDescに書き込まれたバイト数を受け取るポインタ。NULL可。 |
| pfDesc | INT* | outoptional | 数値属性値を受け取るポインタ。NULL可。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLColAttributesW(
void* hstmt,
WORD icol,
WORD fDescType,
void* rgbDesc, // optional
SHORT cbDescMax,
SHORT* pcbDesc, // optional
INT* pfDesc // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLColAttributesW(
IntPtr hstmt, // void* in/out
ushort icol, // WORD
ushort fDescType, // WORD
IntPtr rgbDesc, // void* optional, out
short cbDescMax, // SHORT
IntPtr pcbDesc, // SHORT* optional, out
IntPtr pfDesc // INT* optional, out
);<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLColAttributesW(
hstmt As IntPtr, ' void* in/out
icol As UShort, ' WORD
fDescType As UShort, ' WORD
rgbDesc As IntPtr, ' void* optional, out
cbDescMax As Short, ' SHORT
pcbDesc As IntPtr, ' SHORT* optional, out
pfDesc As IntPtr ' INT* optional, out
) As Short
End Function' hstmt : void* in/out
' icol : WORD
' fDescType : WORD
' rgbDesc : void* optional, out
' cbDescMax : SHORT
' pcbDesc : SHORT* optional, out
' pfDesc : INT* optional, out
Declare PtrSafe Function SQLColAttributesW Lib "odbc32" ( _
ByVal hstmt As LongPtr, _
ByVal icol As Integer, _
ByVal fDescType As Integer, _
ByVal rgbDesc As LongPtr, _
ByVal cbDescMax As Integer, _
ByVal pcbDesc As LongPtr, _
ByVal pfDesc 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
SQLColAttributesW = ctypes.windll.odbc32.SQLColAttributesW
SQLColAttributesW.restype = ctypes.c_short
SQLColAttributesW.argtypes = [
ctypes.POINTER(None), # hstmt : void* in/out
ctypes.c_ushort, # icol : WORD
ctypes.c_ushort, # fDescType : WORD
ctypes.POINTER(None), # rgbDesc : void* optional, out
ctypes.c_short, # cbDescMax : SHORT
ctypes.POINTER(ctypes.c_short), # pcbDesc : SHORT* optional, out
ctypes.POINTER(ctypes.c_int), # pfDesc : INT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLColAttributesW = Fiddle::Function.new(
lib['SQLColAttributesW'],
[
Fiddle::TYPE_VOIDP, # hstmt : void* in/out
-Fiddle::TYPE_SHORT, # icol : WORD
-Fiddle::TYPE_SHORT, # fDescType : WORD
Fiddle::TYPE_VOIDP, # rgbDesc : void* optional, out
Fiddle::TYPE_SHORT, # cbDescMax : SHORT
Fiddle::TYPE_VOIDP, # pcbDesc : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pfDesc : INT* optional, out
],
Fiddle::TYPE_SHORT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "odbc32")]
extern "system" {
fn SQLColAttributesW(
hstmt: *mut (), // void* in/out
icol: u16, // WORD
fDescType: u16, // WORD
rgbDesc: *mut (), // void* optional, out
cbDescMax: i16, // SHORT
pcbDesc: *mut i16, // SHORT* optional, out
pfDesc: *mut i32 // INT* optional, out
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode)]
public static extern short SQLColAttributesW(IntPtr hstmt, ushort icol, ushort fDescType, IntPtr rgbDesc, short cbDescMax, IntPtr pcbDesc, IntPtr pfDesc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLColAttributesW' -Namespace Win32 -PassThru
# $api::SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)#uselib "ODBC32.dll"
#func global SQLColAttributesW "SQLColAttributesW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SQLColAttributesW hstmt, icol, fDescType, rgbDesc, cbDescMax, varptr(pcbDesc), varptr(pfDesc) ; 戻り値は stat
; hstmt : void* in/out -> "wptr"
; icol : WORD -> "wptr"
; fDescType : WORD -> "wptr"
; rgbDesc : void* optional, out -> "wptr"
; cbDescMax : SHORT -> "wptr"
; pcbDesc : SHORT* optional, out -> "wptr"
; pfDesc : INT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLColAttributesW "SQLColAttributesW" sptr, int, int, sptr, int, var, var ; res = SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc) ; hstmt : void* in/out -> "sptr" ; icol : WORD -> "int" ; fDescType : WORD -> "int" ; rgbDesc : void* optional, out -> "sptr" ; cbDescMax : SHORT -> "int" ; pcbDesc : SHORT* optional, out -> "var" ; pfDesc : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLColAttributesW "SQLColAttributesW" sptr, int, int, sptr, int, sptr, sptr ; res = SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, varptr(pcbDesc), varptr(pfDesc)) ; hstmt : void* in/out -> "sptr" ; icol : WORD -> "int" ; fDescType : WORD -> "int" ; rgbDesc : void* optional, out -> "sptr" ; cbDescMax : SHORT -> "int" ; pcbDesc : SHORT* optional, out -> "sptr" ; pfDesc : INT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLColAttributesW(void* hstmt, WORD icol, WORD fDescType, void* rgbDesc, SHORT cbDescMax, SHORT* pcbDesc, INT* pfDesc) #uselib "ODBC32.dll" #cfunc global SQLColAttributesW "SQLColAttributesW" intptr, int, int, intptr, int, var, var ; res = SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc) ; hstmt : void* in/out -> "intptr" ; icol : WORD -> "int" ; fDescType : WORD -> "int" ; rgbDesc : void* optional, out -> "intptr" ; cbDescMax : SHORT -> "int" ; pcbDesc : SHORT* optional, out -> "var" ; pfDesc : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLColAttributesW(void* hstmt, WORD icol, WORD fDescType, void* rgbDesc, SHORT cbDescMax, SHORT* pcbDesc, INT* pfDesc) #uselib "ODBC32.dll" #cfunc global SQLColAttributesW "SQLColAttributesW" intptr, int, int, intptr, int, intptr, intptr ; res = SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, varptr(pcbDesc), varptr(pfDesc)) ; hstmt : void* in/out -> "intptr" ; icol : WORD -> "int" ; fDescType : WORD -> "int" ; rgbDesc : void* optional, out -> "intptr" ; cbDescMax : SHORT -> "int" ; pcbDesc : SHORT* optional, out -> "intptr" ; pfDesc : INT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLColAttributesW = odbc32.NewProc("SQLColAttributesW")
)
// hstmt (void* in/out), icol (WORD), fDescType (WORD), rgbDesc (void* optional, out), cbDescMax (SHORT), pcbDesc (SHORT* optional, out), pfDesc (INT* optional, out)
r1, _, err := procSQLColAttributesW.Call(
uintptr(hstmt),
uintptr(icol),
uintptr(fDescType),
uintptr(rgbDesc),
uintptr(cbDescMax),
uintptr(pcbDesc),
uintptr(pfDesc),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLColAttributesW(
hstmt: Pointer; // void* in/out
icol: Word; // WORD
fDescType: Word; // WORD
rgbDesc: Pointer; // void* optional, out
cbDescMax: Smallint; // SHORT
pcbDesc: Pointer; // SHORT* optional, out
pfDesc: Pointer // INT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLColAttributesW';result := DllCall("ODBC32\SQLColAttributesW"
, "Ptr", hstmt ; void* in/out
, "UShort", icol ; WORD
, "UShort", fDescType ; WORD
, "Ptr", rgbDesc ; void* optional, out
, "Short", cbDescMax ; SHORT
, "Ptr", pcbDesc ; SHORT* optional, out
, "Ptr", pfDesc ; INT* optional, out
, "Short") ; return: SHORT●SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc) = DLL("ODBC32.dll", "int SQLColAttributesW(void*, int, int, void*, int, void*, void*)")
# 呼び出し: SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)
# hstmt : void* in/out -> "void*"
# icol : WORD -> "int"
# fDescType : WORD -> "int"
# rgbDesc : void* optional, out -> "void*"
# cbDescMax : SHORT -> "int"
# pcbDesc : SHORT* optional, out -> "void*"
# pfDesc : INT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "odbc32" fn SQLColAttributesW(
hstmt: ?*anyopaque, // void* in/out
icol: u16, // WORD
fDescType: u16, // WORD
rgbDesc: ?*anyopaque, // void* optional, out
cbDescMax: i16, // SHORT
pcbDesc: [*c]i16, // SHORT* optional, out
pfDesc: [*c]i32 // INT* optional, out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SQLColAttributesW(
hstmt: pointer, # void* in/out
icol: uint16, # WORD
fDescType: uint16, # WORD
rgbDesc: pointer, # void* optional, out
cbDescMax: int16, # SHORT
pcbDesc: ptr int16, # SHORT* optional, out
pfDesc: ptr int32 # INT* optional, out
): int16 {.importc: "SQLColAttributesW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "odbc32");
extern(Windows)
short SQLColAttributesW(
void* hstmt, // void* in/out
ushort icol, // WORD
ushort fDescType, // WORD
void* rgbDesc, // void* optional, out
short cbDescMax, // SHORT
short* pcbDesc, // SHORT* optional, out
int* pfDesc // INT* optional, out
);ccall((:SQLColAttributesW, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, UInt16, UInt16, Ptr{Cvoid}, Int16, Ptr{Int16}, Ptr{Int32}),
hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)
# hstmt : void* in/out -> Ptr{Cvoid}
# icol : WORD -> UInt16
# fDescType : WORD -> UInt16
# rgbDesc : void* optional, out -> Ptr{Cvoid}
# cbDescMax : SHORT -> Int16
# pcbDesc : SHORT* optional, out -> Ptr{Int16}
# pfDesc : INT* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLColAttributesW(
void* hstmt,
uint16_t icol,
uint16_t fDescType,
void* rgbDesc,
int16_t cbDescMax,
int16_t* pcbDesc,
int32_t* pfDesc);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)
-- hstmt : void* in/out
-- icol : WORD
-- fDescType : WORD
-- rgbDesc : void* optional, out
-- cbDescMax : SHORT
-- pcbDesc : SHORT* optional, out
-- pfDesc : INT* 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 SQLColAttributesW = lib.func('__stdcall', 'SQLColAttributesW', 'int16_t', ['void *', 'uint16_t', 'uint16_t', 'void *', 'int16_t', 'int16_t *', 'int32_t *']);
// SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)
// hstmt : void* in/out -> 'void *'
// icol : WORD -> 'uint16_t'
// fDescType : WORD -> 'uint16_t'
// rgbDesc : void* optional, out -> 'void *'
// cbDescMax : SHORT -> 'int16_t'
// pcbDesc : SHORT* optional, out -> 'int16_t *'
// pfDesc : INT* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLColAttributesW: { parameters: ["pointer", "u16", "u16", "pointer", "i16", "pointer", "pointer"], result: "i16" },
});
// lib.symbols.SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)
// hstmt : void* in/out -> "pointer"
// icol : WORD -> "u16"
// fDescType : WORD -> "u16"
// rgbDesc : void* optional, out -> "pointer"
// cbDescMax : SHORT -> "i16"
// pcbDesc : SHORT* optional, out -> "pointer"
// pfDesc : INT* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLColAttributesW(
void* hstmt,
uint16_t icol,
uint16_t fDescType,
void* rgbDesc,
int16_t cbDescMax,
int16_t* pcbDesc,
int32_t* pfDesc);
C, "ODBC32.dll");
// $ffi->SQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc);
// hstmt : void* in/out
// icol : WORD
// fDescType : WORD
// rgbDesc : void* optional, out
// cbDescMax : SHORT
// pcbDesc : SHORT* optional, out
// pfDesc : INT* 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 SQLColAttributesW(
Pointer hstmt, // void* in/out
short icol, // WORD
short fDescType, // WORD
Pointer rgbDesc, // void* optional, out
short cbDescMax, // SHORT
ShortByReference pcbDesc, // SHORT* optional, out
IntByReference pfDesc // INT* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("odbc32")]
lib LibODBC32
fun SQLColAttributesW = SQLColAttributesW(
hstmt : Void*, # void* in/out
icol : UInt16, # WORD
fDescType : UInt16, # WORD
rgbDesc : Void*, # void* optional, out
cbDescMax : Int16, # SHORT
pcbDesc : Int16*, # SHORT* optional, out
pfDesc : Int32* # INT* 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 SQLColAttributesWNative = Int16 Function(Pointer<Void>, Uint16, Uint16, Pointer<Void>, Int16, Pointer<Int16>, Pointer<Int32>);
typedef SQLColAttributesWDart = int Function(Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int16>, Pointer<Int32>);
final SQLColAttributesW = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLColAttributesWNative, SQLColAttributesWDart>('SQLColAttributesW');
// hstmt : void* in/out -> Pointer<Void>
// icol : WORD -> Uint16
// fDescType : WORD -> Uint16
// rgbDesc : void* optional, out -> Pointer<Void>
// cbDescMax : SHORT -> Int16
// pcbDesc : SHORT* optional, out -> Pointer<Int16>
// pfDesc : INT* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLColAttributesW(
hstmt: Pointer; // void* in/out
icol: Word; // WORD
fDescType: Word; // WORD
rgbDesc: Pointer; // void* optional, out
cbDescMax: Smallint; // SHORT
pcbDesc: Pointer; // SHORT* optional, out
pfDesc: Pointer // INT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLColAttributesW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLColAttributesW"
c_SQLColAttributesW :: Ptr () -> Word16 -> Word16 -> Ptr () -> Int16 -> Ptr Int16 -> Ptr Int32 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- icol : WORD -> Word16
-- fDescType : WORD -> Word16
-- rgbDesc : void* optional, out -> Ptr ()
-- cbDescMax : SHORT -> Int16
-- pcbDesc : SHORT* optional, out -> Ptr Int16
-- pfDesc : INT* optional, out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlcolattributesw =
foreign "SQLColAttributesW"
((ptr void) @-> uint16_t @-> uint16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> (ptr int32_t) @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* icol : WORD -> uint16_t *)
(* fDescType : WORD -> uint16_t *)
(* rgbDesc : void* optional, out -> (ptr void) *)
(* cbDescMax : SHORT -> int16_t *)
(* pcbDesc : SHORT* optional, out -> (ptr int16_t) *)
(* pfDesc : INT* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)
(cffi:defcfun ("SQLColAttributesW" sqlcol-attributes-w :convention :stdcall) :int16
(hstmt :pointer) ; void* in/out
(icol :uint16) ; WORD
(f-desc-type :uint16) ; WORD
(rgb-desc :pointer) ; void* optional, out
(cb-desc-max :int16) ; SHORT
(pcb-desc :pointer) ; SHORT* optional, out
(pf-desc :pointer)) ; INT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLColAttributesW = Win32::API::More->new('ODBC32',
'short SQLColAttributesW(LPVOID hstmt, WORD icol, WORD fDescType, LPVOID rgbDesc, short cbDescMax, LPVOID pcbDesc, LPVOID pfDesc)');
# my $ret = $SQLColAttributesW->Call($hstmt, $icol, $fDescType, $rgbDesc, $cbDescMax, $pcbDesc, $pfDesc);
# hstmt : void* in/out -> LPVOID
# icol : WORD -> WORD
# fDescType : WORD -> WORD
# rgbDesc : void* optional, out -> LPVOID
# cbDescMax : SHORT -> short
# pcbDesc : SHORT* optional, out -> LPVOID
# pfDesc : INT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SQLColAttributesA (ANSI版) — 結果セット列の記述属性を取得する(ANSI・非推奨)。