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