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

SQLColAttributes

関数
結果セット列の記述属性を取得する(非推奨)。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLColAttributes(
    void* hstmt,
    WORD icol,
    WORD fDescType,
    void* rgbDesc,
    SHORT cbDescMax,
    SHORT* pcbDesc,
    INT* pfDesc
);

パラメーター

名前方向説明
hstmtvoid*inout対象のステートメントハンドル。非推奨でSQLColAttributeに置換された。
icolWORDin対象の列番号。1始まりで指定する。
fDescTypeWORDin取得する属性の種別。SQL_COLUMN_*定数を指定する。
rgbDescvoid*inout文字列属性値を受け取るバッファへのポインタ。
cbDescMaxSHORTinrgbDescバッファのバイト長。
pcbDescSHORT*inoutrgbDescに書き込まれたバイト数を受け取るポインタ。NULL可。
pfDescINT*inout数値属性値を受け取るポインタ。NULL可。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLColAttributes(
    void* hstmt,
    WORD icol,
    WORD fDescType,
    void* rgbDesc,
    SHORT cbDescMax,
    SHORT* pcbDesc,
    INT* pfDesc
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLColAttributes(
    IntPtr hstmt,   // void* in/out
    ushort icol,   // WORD
    ushort fDescType,   // WORD
    IntPtr rgbDesc,   // void* in/out
    short cbDescMax,   // SHORT
    ref short pcbDesc,   // SHORT* in/out
    ref int pfDesc   // INT* in/out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLColAttributes(
    hstmt As IntPtr,   ' void* in/out
    icol As UShort,   ' WORD
    fDescType As UShort,   ' WORD
    rgbDesc As IntPtr,   ' void* in/out
    cbDescMax As Short,   ' SHORT
    ByRef pcbDesc As Short,   ' SHORT* in/out
    ByRef pfDesc As Integer   ' INT* in/out
) As Short
End Function
' hstmt : void* in/out
' icol : WORD
' fDescType : WORD
' rgbDesc : void* in/out
' cbDescMax : SHORT
' pcbDesc : SHORT* in/out
' pfDesc : INT* in/out
Declare PtrSafe Function SQLColAttributes Lib "odbc32" ( _
    ByVal hstmt As LongPtr, _
    ByVal icol As Integer, _
    ByVal fDescType As Integer, _
    ByVal rgbDesc As LongPtr, _
    ByVal cbDescMax As Integer, _
    ByRef pcbDesc As Integer, _
    ByRef pfDesc As Long) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLColAttributes = ctypes.windll.odbc32.SQLColAttributes
SQLColAttributes.restype = ctypes.c_short
SQLColAttributes.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.c_ushort,  # icol : WORD
    ctypes.c_ushort,  # fDescType : WORD
    ctypes.POINTER(None),  # rgbDesc : void* in/out
    ctypes.c_short,  # cbDescMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbDesc : SHORT* in/out
    ctypes.POINTER(ctypes.c_int),  # pfDesc : INT* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLColAttributes = odbc32.NewProc("SQLColAttributes")
)

// hstmt (void* in/out), icol (WORD), fDescType (WORD), rgbDesc (void* in/out), cbDescMax (SHORT), pcbDesc (SHORT* in/out), pfDesc (INT* in/out)
r1, _, err := procSQLColAttributes.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   // SHORT
function SQLColAttributes(
  hstmt: Pointer;   // void* in/out
  icol: Word;   // WORD
  fDescType: Word;   // WORD
  rgbDesc: Pointer;   // void* in/out
  cbDescMax: Smallint;   // SHORT
  pcbDesc: Pointer;   // SHORT* in/out
  pfDesc: Pointer   // INT* in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLColAttributes';
result := DllCall("ODBC32\SQLColAttributes"
    , "Ptr", hstmt   ; void* in/out
    , "UShort", icol   ; WORD
    , "UShort", fDescType   ; WORD
    , "Ptr", rgbDesc   ; void* in/out
    , "Short", cbDescMax   ; SHORT
    , "Ptr", pcbDesc   ; SHORT* in/out
    , "Ptr", pfDesc   ; INT* in/out
    , "Short")   ; return: SHORT
●SQLColAttributes(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc) = DLL("ODBC32.dll", "int SQLColAttributes(void*, int, int, void*, int, void*, void*)")
# 呼び出し: SQLColAttributes(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)
# hstmt : void* in/out -> "void*"
# icol : WORD -> "int"
# fDescType : WORD -> "int"
# rgbDesc : void* in/out -> "void*"
# cbDescMax : SHORT -> "int"
# pcbDesc : SHORT* in/out -> "void*"
# pfDesc : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SQLColAttributesNative = Int16 Function(Pointer<Void>, Uint16, Uint16, Pointer<Void>, Int16, Pointer<Int16>, Pointer<Int32>);
typedef SQLColAttributesDart = int Function(Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int16>, Pointer<Int32>);
final SQLColAttributes = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLColAttributesNative, SQLColAttributesDart>('SQLColAttributes');
// hstmt : void* in/out -> Pointer<Void>
// icol : WORD -> Uint16
// fDescType : WORD -> Uint16
// rgbDesc : void* in/out -> Pointer<Void>
// cbDescMax : SHORT -> Int16
// pcbDesc : SHORT* in/out -> Pointer<Int16>
// pfDesc : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLColAttributes(
  hstmt: Pointer;   // void* in/out
  icol: Word;   // WORD
  fDescType: Word;   // WORD
  rgbDesc: Pointer;   // void* in/out
  cbDescMax: Smallint;   // SHORT
  pcbDesc: Pointer;   // SHORT* in/out
  pfDesc: Pointer   // INT* in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLColAttributes';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLColAttributes"
  c_SQLColAttributes :: Ptr () -> Word16 -> Word16 -> Ptr () -> Int16 -> Ptr Int16 -> Ptr Int32 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- icol : WORD -> Word16
-- fDescType : WORD -> Word16
-- rgbDesc : void* in/out -> Ptr ()
-- cbDescMax : SHORT -> Int16
-- pcbDesc : SHORT* in/out -> Ptr Int16
-- pfDesc : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlcolattributes =
  foreign "SQLColAttributes"
    ((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* in/out -> (ptr void) *)
(* cbDescMax : SHORT -> int16_t *)
(* pcbDesc : SHORT* in/out -> (ptr int16_t) *)
(* pfDesc : INT* in/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 ("SQLColAttributes" sqlcol-attributes :convention :stdcall) :int16
  (hstmt :pointer)   ; void* in/out
  (icol :uint16)   ; WORD
  (f-desc-type :uint16)   ; WORD
  (rgb-desc :pointer)   ; void* in/out
  (cb-desc-max :int16)   ; SHORT
  (pcb-desc :pointer)   ; SHORT* in/out
  (pf-desc :pointer))   ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLColAttributes = Win32::API::More->new('ODBC32',
    'short SQLColAttributes(LPVOID hstmt, WORD icol, WORD fDescType, LPVOID rgbDesc, short cbDescMax, LPVOID pcbDesc, LPVOID pfDesc)');
# my $ret = $SQLColAttributes->Call($hstmt, $icol, $fDescType, $rgbDesc, $cbDescMax, $pcbDesc, $pfDesc);
# hstmt : void* in/out -> LPVOID
# icol : WORD -> WORD
# fDescType : WORD -> WORD
# rgbDesc : void* in/out -> LPVOID
# cbDescMax : SHORT -> short
# pcbDesc : SHORT* in/out -> LPVOID
# pfDesc : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い