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

SQLColAttributeA

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

シグネチャ

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

SHORT SQLColAttributeA(
    void* hstmt,
    SHORT iCol,
    SHORT iField,
    void* pCharAttr,   // optional
    SHORT cbCharAttrMax,
    SHORT* pcbCharAttr,   // optional
    void* pNumAttr   // optional
);

パラメーター

名前方向説明
hstmtvoid*inoutODBCのステートメントハンドル。属性取得対象の結果セットを保持する。
iColSHORTin対象列番号。1始まりで指定する。
iFieldSHORTin取得したいフィールド識別子。SQL_DESC_*定数を指定する。
pCharAttrvoid*outoptional文字列属性を受け取るバッファ。数値属性の場合はNULL可。
cbCharAttrMaxSHORTinpCharAttrバッファのバイト長。
pcbCharAttrSHORT*outoptional実際に返された文字列属性のバイト長を受け取るポインタ。
pNumAttrvoid*outoptional数値属性を受け取るポインタ。SQLLEN型として格納される。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLColAttributeA(
    void* hstmt,
    SHORT iCol,
    SHORT iField,
    void* pCharAttr,   // optional
    SHORT cbCharAttrMax,
    SHORT* pcbCharAttr,   // optional
    void* pNumAttr   // optional
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLColAttributeA(
    IntPtr hstmt,   // void* in/out
    short iCol,   // SHORT
    short iField,   // SHORT
    IntPtr pCharAttr,   // void* optional, out
    short cbCharAttrMax,   // SHORT
    IntPtr pcbCharAttr,   // SHORT* optional, out
    IntPtr pNumAttr   // void* optional, out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLColAttributeA(
    hstmt As IntPtr,   ' void* in/out
    iCol As Short,   ' SHORT
    iField As Short,   ' SHORT
    pCharAttr As IntPtr,   ' void* optional, out
    cbCharAttrMax As Short,   ' SHORT
    pcbCharAttr As IntPtr,   ' SHORT* optional, out
    pNumAttr As IntPtr   ' void* optional, out
) As Short
End Function
' hstmt : void* in/out
' iCol : SHORT
' iField : SHORT
' pCharAttr : void* optional, out
' cbCharAttrMax : SHORT
' pcbCharAttr : SHORT* optional, out
' pNumAttr : void* optional, out
Declare PtrSafe Function SQLColAttributeA Lib "odbc32" ( _
    ByVal hstmt As LongPtr, _
    ByVal iCol As Integer, _
    ByVal iField As Integer, _
    ByVal pCharAttr As LongPtr, _
    ByVal cbCharAttrMax As Integer, _
    ByVal pcbCharAttr As LongPtr, _
    ByVal pNumAttr As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLColAttributeA = ctypes.windll.odbc32.SQLColAttributeA
SQLColAttributeA.restype = ctypes.c_short
SQLColAttributeA.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.c_short,  # iCol : SHORT
    ctypes.c_short,  # iField : SHORT
    ctypes.POINTER(None),  # pCharAttr : void* optional, out
    ctypes.c_short,  # cbCharAttrMax : 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')
SQLColAttributeA = Fiddle::Function.new(
  lib['SQLColAttributeA'],
  [
    Fiddle::TYPE_VOIDP,  # hstmt : void* in/out
    Fiddle::TYPE_SHORT,  # iCol : SHORT
    Fiddle::TYPE_SHORT,  # iField : SHORT
    Fiddle::TYPE_VOIDP,  # pCharAttr : void* optional, out
    Fiddle::TYPE_SHORT,  # cbCharAttrMax : SHORT
    Fiddle::TYPE_VOIDP,  # pcbCharAttr : SHORT* optional, out
    Fiddle::TYPE_VOIDP,  # pNumAttr : void* optional, out
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLColAttributeA(
        hstmt: *mut (),  // void* in/out
        iCol: i16,  // SHORT
        iField: i16,  // SHORT
        pCharAttr: *mut (),  // void* optional, out
        cbCharAttrMax: 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.Ansi)]
public static extern short SQLColAttributeA(IntPtr hstmt, short iCol, short iField, IntPtr pCharAttr, short cbCharAttrMax, IntPtr pcbCharAttr, IntPtr pNumAttr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLColAttributeA' -Namespace Win32 -PassThru
# $api::SQLColAttributeA(hstmt, iCol, iField, pCharAttr, cbCharAttrMax, pcbCharAttr, pNumAttr)
#uselib "ODBC32.dll"
#func global SQLColAttributeA "SQLColAttributeA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLColAttributeA hstmt, iCol, iField, pCharAttr, cbCharAttrMax, varptr(pcbCharAttr), pNumAttr   ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; iCol : SHORT -> "sptr"
; iField : SHORT -> "sptr"
; pCharAttr : void* optional, out -> "sptr"
; cbCharAttrMax : SHORT -> "sptr"
; pcbCharAttr : SHORT* optional, out -> "sptr"
; pNumAttr : void* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLColAttributeA "SQLColAttributeA" sptr, int, int, sptr, int, var, sptr
; res = SQLColAttributeA(hstmt, iCol, iField, pCharAttr, cbCharAttrMax, pcbCharAttr, pNumAttr)
; hstmt : void* in/out -> "sptr"
; iCol : SHORT -> "int"
; iField : SHORT -> "int"
; pCharAttr : void* optional, out -> "sptr"
; cbCharAttrMax : SHORT -> "int"
; pcbCharAttr : SHORT* optional, out -> "var"
; pNumAttr : void* optional, out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLColAttributeA(void* hstmt, SHORT iCol, SHORT iField, void* pCharAttr, SHORT cbCharAttrMax, SHORT* pcbCharAttr, void* pNumAttr)
#uselib "ODBC32.dll"
#cfunc global SQLColAttributeA "SQLColAttributeA" intptr, int, int, intptr, int, var, intptr
; res = SQLColAttributeA(hstmt, iCol, iField, pCharAttr, cbCharAttrMax, pcbCharAttr, pNumAttr)
; hstmt : void* in/out -> "intptr"
; iCol : SHORT -> "int"
; iField : SHORT -> "int"
; pCharAttr : void* optional, out -> "intptr"
; cbCharAttrMax : SHORT -> "int"
; pcbCharAttr : SHORT* optional, out -> "var"
; pNumAttr : void* optional, out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLColAttributeA = odbc32.NewProc("SQLColAttributeA")
)

// hstmt (void* in/out), iCol (SHORT), iField (SHORT), pCharAttr (void* optional, out), cbCharAttrMax (SHORT), pcbCharAttr (SHORT* optional, out), pNumAttr (void* optional, out)
r1, _, err := procSQLColAttributeA.Call(
	uintptr(hstmt),
	uintptr(iCol),
	uintptr(iField),
	uintptr(pCharAttr),
	uintptr(cbCharAttrMax),
	uintptr(pcbCharAttr),
	uintptr(pNumAttr),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLColAttributeA(
  hstmt: Pointer;   // void* in/out
  iCol: Smallint;   // SHORT
  iField: Smallint;   // SHORT
  pCharAttr: Pointer;   // void* optional, out
  cbCharAttrMax: Smallint;   // SHORT
  pcbCharAttr: Pointer;   // SHORT* optional, out
  pNumAttr: Pointer   // void* optional, out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLColAttributeA';
result := DllCall("ODBC32\SQLColAttributeA"
    , "Ptr", hstmt   ; void* in/out
    , "Short", iCol   ; SHORT
    , "Short", iField   ; SHORT
    , "Ptr", pCharAttr   ; void* optional, out
    , "Short", cbCharAttrMax   ; SHORT
    , "Ptr", pcbCharAttr   ; SHORT* optional, out
    , "Ptr", pNumAttr   ; void* optional, out
    , "Short")   ; return: SHORT
●SQLColAttributeA(hstmt, iCol, iField, pCharAttr, cbCharAttrMax, pcbCharAttr, pNumAttr) = DLL("ODBC32.dll", "int SQLColAttributeA(void*, int, int, void*, int, void*, void*)")
# 呼び出し: SQLColAttributeA(hstmt, iCol, iField, pCharAttr, cbCharAttrMax, pcbCharAttr, pNumAttr)
# hstmt : void* in/out -> "void*"
# iCol : SHORT -> "int"
# iField : SHORT -> "int"
# pCharAttr : void* optional, out -> "void*"
# cbCharAttrMax : SHORT -> "int"
# pcbCharAttr : SHORT* optional, out -> "void*"
# pNumAttr : void* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

foreign import stdcall safe "SQLColAttributeA"
  c_SQLColAttributeA :: Ptr () -> Int16 -> Int16 -> Ptr () -> Int16 -> Ptr Int16 -> Ptr () -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- iCol : SHORT -> Int16
-- iField : SHORT -> Int16
-- pCharAttr : void* optional, out -> Ptr ()
-- cbCharAttrMax : 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 sqlcolattributea =
  foreign "SQLColAttributeA"
    ((ptr void) @-> int16_t @-> int16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> (ptr void) @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* iCol : SHORT -> int16_t *)
(* iField : SHORT -> int16_t *)
(* pCharAttr : void* optional, out -> (ptr void) *)
(* cbCharAttrMax : 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 ("SQLColAttributeA" sqlcol-attribute-a :convention :stdcall) :int16
  (hstmt :pointer)   ; void* in/out
  (i-col :int16)   ; SHORT
  (i-field :int16)   ; SHORT
  (p-char-attr :pointer)   ; void* optional, out
  (cb-char-attr-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 $SQLColAttributeA = Win32::API::More->new('ODBC32',
    'short SQLColAttributeA(LPVOID hstmt, short iCol, short iField, LPVOID pCharAttr, short cbCharAttrMax, LPVOID pcbCharAttr, LPVOID pNumAttr)');
# my $ret = $SQLColAttributeA->Call($hstmt, $iCol, $iField, $pCharAttr, $cbCharAttrMax, $pcbCharAttr, $pNumAttr);
# hstmt : void* in/out -> LPVOID
# iCol : SHORT -> short
# iField : SHORT -> short
# pCharAttr : void* optional, out -> LPVOID
# cbCharAttrMax : SHORT -> short
# pcbCharAttr : SHORT* optional, out -> LPVOID
# pNumAttr : void* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い