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

SQLGetInfoA

関数
ODBCドライバやデータソースに関する情報を取得する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLGetInfoA(
    void* hdbc,
    WORD fInfoType,
    void* rgbInfoValue,   // optional
    SHORT cbInfoValueMax,
    SHORT* pcbInfoValue   // optional
);

パラメーター

名前方向説明
hdbcvoid*inoutODBCの接続ハンドル。ドライバ/データソース情報の取得対象。
fInfoTypeWORDin取得する情報の種類。SQL_*情報型定数を指定する。
rgbInfoValuevoid*outoptional情報値を受け取るバッファ。出力用。
cbInfoValueMaxSHORTinrgbInfoValueバッファのバイト長。
pcbInfoValueSHORT*outoptional実際に返された情報のバイト長を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLGetInfoA = ctypes.windll.odbc32.SQLGetInfoA
SQLGetInfoA.restype = ctypes.c_short
SQLGetInfoA.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.c_ushort,  # fInfoType : WORD
    ctypes.POINTER(None),  # rgbInfoValue : void* optional, out
    ctypes.c_short,  # cbInfoValueMax : SHORT
    ctypes.POINTER(ctypes.c_short),  # pcbInfoValue : SHORT* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetInfoA = odbc32.NewProc("SQLGetInfoA")
)

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

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

foreign import stdcall safe "SQLGetInfoA"
  c_SQLGetInfoA :: Ptr () -> Word16 -> Ptr () -> Int16 -> Ptr Int16 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- fInfoType : WORD -> Word16
-- rgbInfoValue : void* optional, out -> Ptr ()
-- cbInfoValueMax : SHORT -> Int16
-- pcbInfoValue : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlgetinfoa =
  foreign "SQLGetInfoA"
    ((ptr void) @-> uint16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* fInfoType : WORD -> uint16_t *)
(* rgbInfoValue : void* optional, out -> (ptr void) *)
(* cbInfoValueMax : SHORT -> int16_t *)
(* pcbInfoValue : SHORT* optional, out -> (ptr int16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLGetInfoA" sqlget-info-a :convention :stdcall) :int16
  (hdbc :pointer)   ; void* in/out
  (f-info-type :uint16)   ; WORD
  (rgb-info-value :pointer)   ; void* optional, out
  (cb-info-value-max :int16)   ; SHORT
  (pcb-info-value :pointer))   ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLGetInfoA = Win32::API::More->new('ODBC32',
    'short SQLGetInfoA(LPVOID hdbc, WORD fInfoType, LPVOID rgbInfoValue, short cbInfoValueMax, LPVOID pcbInfoValue)');
# my $ret = $SQLGetInfoA->Call($hdbc, $fInfoType, $rgbInfoValue, $cbInfoValueMax, $pcbInfoValue);
# hdbc : void* in/out -> LPVOID
# fInfoType : WORD -> WORD
# rgbInfoValue : void* optional, out -> LPVOID
# cbInfoValueMax : SHORT -> short
# pcbInfoValue : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い