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

SQLColAttribute

関数
結果セット列の指定フィールド属性を取得する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLColAttribute(
    void* StatementHandle,
    WORD ColumnNumber,
    WORD FieldIdentifier,
    void* CharacterAttribute,   // optional
    SHORT BufferLength,
    SHORT* StringLength,   // optional
    void* NumericAttribute   // optional
);

パラメーター

名前方向説明
StatementHandlevoid*inout対象のステートメントハンドル(HSTMT)。
ColumnNumberWORDin属性を取得する結果列の番号。1始まり。
FieldIdentifierWORDin取得する属性を示すフィールド識別子(SQL_DESC_*)。
CharacterAttributevoid*outoptional文字列属性を受け取るバッファへのポインタ。NULL可。
BufferLengthSHORTinCharacterAttributeバッファのバイト長。
StringLengthSHORT*outoptional文字列属性の実際のバイト長を受け取るポインタ。
NumericAttributevoid*outoptional数値属性を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLColAttribute(
    void* StatementHandle,
    WORD ColumnNumber,
    WORD FieldIdentifier,
    void* CharacterAttribute,   // optional
    SHORT BufferLength,
    SHORT* StringLength,   // optional
    void* NumericAttribute   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLColAttribute(
    IntPtr StatementHandle,   // void* in/out
    ushort ColumnNumber,   // WORD
    ushort FieldIdentifier,   // WORD
    IntPtr CharacterAttribute,   // void* optional, out
    short BufferLength,   // SHORT
    IntPtr StringLength,   // SHORT* optional, out
    IntPtr NumericAttribute   // void* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLColAttribute(
    StatementHandle As IntPtr,   ' void* in/out
    ColumnNumber As UShort,   ' WORD
    FieldIdentifier As UShort,   ' WORD
    CharacterAttribute As IntPtr,   ' void* optional, out
    BufferLength As Short,   ' SHORT
    StringLength As IntPtr,   ' SHORT* optional, out
    NumericAttribute As IntPtr   ' void* optional, out
) As Short
End Function
' StatementHandle : void* in/out
' ColumnNumber : WORD
' FieldIdentifier : WORD
' CharacterAttribute : void* optional, out
' BufferLength : SHORT
' StringLength : SHORT* optional, out
' NumericAttribute : void* optional, out
Declare PtrSafe Function SQLColAttribute Lib "odbc32" ( _
    ByVal StatementHandle As LongPtr, _
    ByVal ColumnNumber As Integer, _
    ByVal FieldIdentifier As Integer, _
    ByVal CharacterAttribute As LongPtr, _
    ByVal BufferLength As Integer, _
    ByVal StringLength As LongPtr, _
    ByVal NumericAttribute As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLColAttribute = ctypes.windll.odbc32.SQLColAttribute
SQLColAttribute.restype = ctypes.c_short
SQLColAttribute.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.c_ushort,  # ColumnNumber : WORD
    ctypes.c_ushort,  # FieldIdentifier : WORD
    ctypes.POINTER(None),  # CharacterAttribute : void* optional, out
    ctypes.c_short,  # BufferLength : SHORT
    ctypes.POINTER(ctypes.c_short),  # StringLength : SHORT* optional, out
    ctypes.POINTER(None),  # NumericAttribute : void* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLColAttribute = odbc32.NewProc("SQLColAttribute")
)

// StatementHandle (void* in/out), ColumnNumber (WORD), FieldIdentifier (WORD), CharacterAttribute (void* optional, out), BufferLength (SHORT), StringLength (SHORT* optional, out), NumericAttribute (void* optional, out)
r1, _, err := procSQLColAttribute.Call(
	uintptr(StatementHandle),
	uintptr(ColumnNumber),
	uintptr(FieldIdentifier),
	uintptr(CharacterAttribute),
	uintptr(BufferLength),
	uintptr(StringLength),
	uintptr(NumericAttribute),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLColAttribute(
  StatementHandle: Pointer;   // void* in/out
  ColumnNumber: Word;   // WORD
  FieldIdentifier: Word;   // WORD
  CharacterAttribute: Pointer;   // void* optional, out
  BufferLength: Smallint;   // SHORT
  StringLength: Pointer;   // SHORT* optional, out
  NumericAttribute: Pointer   // void* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLColAttribute';
result := DllCall("ODBC32\SQLColAttribute"
    , "Ptr", StatementHandle   ; void* in/out
    , "UShort", ColumnNumber   ; WORD
    , "UShort", FieldIdentifier   ; WORD
    , "Ptr", CharacterAttribute   ; void* optional, out
    , "Short", BufferLength   ; SHORT
    , "Ptr", StringLength   ; SHORT* optional, out
    , "Ptr", NumericAttribute   ; void* optional, out
    , "Short")   ; return: SHORT
●SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute) = DLL("ODBC32.dll", "int SQLColAttribute(void*, int, int, void*, int, void*, void*)")
# 呼び出し: SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute)
# StatementHandle : void* in/out -> "void*"
# ColumnNumber : WORD -> "int"
# FieldIdentifier : WORD -> "int"
# CharacterAttribute : void* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# StringLength : SHORT* optional, out -> "void*"
# NumericAttribute : void* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLColAttribute(
    StatementHandle: ?*anyopaque, // void* in/out
    ColumnNumber: u16, // WORD
    FieldIdentifier: u16, // WORD
    CharacterAttribute: ?*anyopaque, // void* optional, out
    BufferLength: i16, // SHORT
    StringLength: [*c]i16, // SHORT* optional, out
    NumericAttribute: ?*anyopaque // void* optional, out
) callconv(std.os.windows.WINAPI) i16;
proc SQLColAttribute(
    StatementHandle: pointer,  # void* in/out
    ColumnNumber: uint16,  # WORD
    FieldIdentifier: uint16,  # WORD
    CharacterAttribute: pointer,  # void* optional, out
    BufferLength: int16,  # SHORT
    StringLength: ptr int16,  # SHORT* optional, out
    NumericAttribute: pointer  # void* optional, out
): int16 {.importc: "SQLColAttribute", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLColAttribute(
    void* StatementHandle,   // void* in/out
    ushort ColumnNumber,   // WORD
    ushort FieldIdentifier,   // WORD
    void* CharacterAttribute,   // void* optional, out
    short BufferLength,   // SHORT
    short* StringLength,   // SHORT* optional, out
    void* NumericAttribute   // void* optional, out
);
ccall((:SQLColAttribute, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, UInt16, UInt16, Ptr{Cvoid}, Int16, Ptr{Int16}, Ptr{Cvoid}),
      StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute)
# StatementHandle : void* in/out -> Ptr{Cvoid}
# ColumnNumber : WORD -> UInt16
# FieldIdentifier : WORD -> UInt16
# CharacterAttribute : void* optional, out -> Ptr{Cvoid}
# BufferLength : SHORT -> Int16
# StringLength : SHORT* optional, out -> Ptr{Int16}
# NumericAttribute : void* optional, out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLColAttribute(
    void* StatementHandle,
    uint16_t ColumnNumber,
    uint16_t FieldIdentifier,
    void* CharacterAttribute,
    int16_t BufferLength,
    int16_t* StringLength,
    void* NumericAttribute);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute)
-- StatementHandle : void* in/out
-- ColumnNumber : WORD
-- FieldIdentifier : WORD
-- CharacterAttribute : void* optional, out
-- BufferLength : SHORT
-- StringLength : SHORT* optional, out
-- NumericAttribute : void* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLColAttribute = lib.func('__stdcall', 'SQLColAttribute', 'int16_t', ['void *', 'uint16_t', 'uint16_t', 'void *', 'int16_t', 'int16_t *', 'void *']);
// SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute)
// StatementHandle : void* in/out -> 'void *'
// ColumnNumber : WORD -> 'uint16_t'
// FieldIdentifier : WORD -> 'uint16_t'
// CharacterAttribute : void* optional, out -> 'void *'
// BufferLength : SHORT -> 'int16_t'
// StringLength : SHORT* optional, out -> 'int16_t *'
// NumericAttribute : void* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLColAttribute: { parameters: ["pointer", "u16", "u16", "pointer", "i16", "pointer", "pointer"], result: "i16" },
});
// lib.symbols.SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute)
// StatementHandle : void* in/out -> "pointer"
// ColumnNumber : WORD -> "u16"
// FieldIdentifier : WORD -> "u16"
// CharacterAttribute : void* optional, out -> "pointer"
// BufferLength : SHORT -> "i16"
// StringLength : SHORT* optional, out -> "pointer"
// NumericAttribute : void* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLColAttribute(
    void* StatementHandle,
    uint16_t ColumnNumber,
    uint16_t FieldIdentifier,
    void* CharacterAttribute,
    int16_t BufferLength,
    int16_t* StringLength,
    void* NumericAttribute);
C, "ODBC32.dll");
// $ffi->SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, StringLength, NumericAttribute);
// StatementHandle : void* in/out
// ColumnNumber : WORD
// FieldIdentifier : WORD
// CharacterAttribute : void* optional, out
// BufferLength : SHORT
// StringLength : SHORT* optional, out
// NumericAttribute : 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.ASCII_OPTIONS);
    short SQLColAttribute(
        Pointer StatementHandle,   // void* in/out
        short ColumnNumber,   // WORD
        short FieldIdentifier,   // WORD
        Pointer CharacterAttribute,   // void* optional, out
        short BufferLength,   // SHORT
        ShortByReference StringLength,   // SHORT* optional, out
        Pointer NumericAttribute   // void* optional, out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLColAttribute = SQLColAttribute(
    StatementHandle : Void*,   # void* in/out
    ColumnNumber : UInt16,   # WORD
    FieldIdentifier : UInt16,   # WORD
    CharacterAttribute : Void*,   # void* optional, out
    BufferLength : Int16,   # SHORT
    StringLength : Int16*,   # SHORT* optional, out
    NumericAttribute : 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 SQLColAttributeNative = Int16 Function(Pointer<Void>, Uint16, Uint16, Pointer<Void>, Int16, Pointer<Int16>, Pointer<Void>);
typedef SQLColAttributeDart = int Function(Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int16>, Pointer<Void>);
final SQLColAttribute = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLColAttributeNative, SQLColAttributeDart>('SQLColAttribute');
// StatementHandle : void* in/out -> Pointer<Void>
// ColumnNumber : WORD -> Uint16
// FieldIdentifier : WORD -> Uint16
// CharacterAttribute : void* optional, out -> Pointer<Void>
// BufferLength : SHORT -> Int16
// StringLength : SHORT* optional, out -> Pointer<Int16>
// NumericAttribute : void* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLColAttribute(
  StatementHandle: Pointer;   // void* in/out
  ColumnNumber: Word;   // WORD
  FieldIdentifier: Word;   // WORD
  CharacterAttribute: Pointer;   // void* optional, out
  BufferLength: Smallint;   // SHORT
  StringLength: Pointer;   // SHORT* optional, out
  NumericAttribute: Pointer   // void* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLColAttribute';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLColAttribute"
  c_SQLColAttribute :: Ptr () -> Word16 -> Word16 -> Ptr () -> Int16 -> Ptr Int16 -> Ptr () -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- ColumnNumber : WORD -> Word16
-- FieldIdentifier : WORD -> Word16
-- CharacterAttribute : void* optional, out -> Ptr ()
-- BufferLength : SHORT -> Int16
-- StringLength : SHORT* optional, out -> Ptr Int16
-- NumericAttribute : void* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlcolattribute =
  foreign "SQLColAttribute"
    ((ptr void) @-> uint16_t @-> uint16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> (ptr void) @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* ColumnNumber : WORD -> uint16_t *)
(* FieldIdentifier : WORD -> uint16_t *)
(* CharacterAttribute : void* optional, out -> (ptr void) *)
(* BufferLength : SHORT -> int16_t *)
(* StringLength : SHORT* optional, out -> (ptr int16_t) *)
(* NumericAttribute : 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 ("SQLColAttribute" sqlcol-attribute :convention :stdcall) :int16
  (statement-handle :pointer)   ; void* in/out
  (column-number :uint16)   ; WORD
  (field-identifier :uint16)   ; WORD
  (character-attribute :pointer)   ; void* optional, out
  (buffer-length :int16)   ; SHORT
  (string-length :pointer)   ; SHORT* optional, out
  (numeric-attribute :pointer))   ; void* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLColAttribute = Win32::API::More->new('ODBC32',
    'short SQLColAttribute(LPVOID StatementHandle, WORD ColumnNumber, WORD FieldIdentifier, LPVOID CharacterAttribute, short BufferLength, LPVOID StringLength, LPVOID NumericAttribute)');
# my $ret = $SQLColAttribute->Call($StatementHandle, $ColumnNumber, $FieldIdentifier, $CharacterAttribute, $BufferLength, $StringLength, $NumericAttribute);
# StatementHandle : void* in/out -> LPVOID
# ColumnNumber : WORD -> WORD
# FieldIdentifier : WORD -> WORD
# CharacterAttribute : void* optional, out -> LPVOID
# BufferLength : SHORT -> short
# StringLength : SHORT* optional, out -> LPVOID
# NumericAttribute : void* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い