ホーム › System.Search › SQLGetInfoW
SQLGetInfoW
関数ドライバやデータソースの一般情報を取得する(Unicode)。
シグネチャ
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLGetInfoW(
void* hdbc,
WORD fInfoType,
void* rgbInfoValue, // optional
SHORT cbInfoValueMax,
SHORT* pcbInfoValue // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdbc | void* | inout | 情報を取得する接続ハンドル。 |
| fInfoType | WORD | in | 取得する情報の種別。SQL_*情報型定数を指定する。 |
| rgbInfoValue | void* | outoptional | 情報値を受け取るバッファ。文字列はUnicode。 |
| cbInfoValueMax | SHORT | in | rgbInfoValueバッファのバイト長。文字列情報で意味を持つ。 |
| pcbInfoValue | SHORT* | outoptional | 実際に書き込まれたバイト数を受け取るポインタ。NULL可。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLGetInfoW(
void* hdbc,
WORD fInfoType,
void* rgbInfoValue, // optional
SHORT cbInfoValueMax,
SHORT* pcbInfoValue // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLGetInfoW(
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.Unicode, ExactSpelling:=True)>
Public Shared Function SQLGetInfoW(
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 SQLGetInfoW Lib "odbc32" ( _
ByVal hdbc As LongPtr, _
ByVal fInfoType As Integer, _
ByVal rgbInfoValue As LongPtr, _
ByVal cbInfoValueMax As Integer, _
ByVal pcbInfoValue 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
SQLGetInfoW = ctypes.windll.odbc32.SQLGetInfoW
SQLGetInfoW.restype = ctypes.c_short
SQLGetInfoW.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')
SQLGetInfoW = Fiddle::Function.new(
lib['SQLGetInfoW'],
[
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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "odbc32")]
extern "system" {
fn SQLGetInfoW(
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.Unicode)]
public static extern short SQLGetInfoW(IntPtr hdbc, ushort fInfoType, IntPtr rgbInfoValue, short cbInfoValueMax, IntPtr pcbInfoValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetInfoW' -Namespace Win32 -PassThru
# $api::SQLGetInfoW(hdbc, fInfoType, rgbInfoValue, cbInfoValueMax, pcbInfoValue)#uselib "ODBC32.dll"
#func global SQLGetInfoW "SQLGetInfoW" wptr, wptr, wptr, wptr, wptr
; SQLGetInfoW hdbc, fInfoType, rgbInfoValue, cbInfoValueMax, varptr(pcbInfoValue) ; 戻り値は stat
; hdbc : void* in/out -> "wptr"
; fInfoType : WORD -> "wptr"
; rgbInfoValue : void* optional, out -> "wptr"
; cbInfoValueMax : SHORT -> "wptr"
; pcbInfoValue : SHORT* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLGetInfoW "SQLGetInfoW" sptr, int, sptr, int, var ; res = SQLGetInfoW(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 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLGetInfoW "SQLGetInfoW" sptr, int, sptr, int, sptr ; res = SQLGetInfoW(hdbc, fInfoType, rgbInfoValue, cbInfoValueMax, varptr(pcbInfoValue)) ; hdbc : void* in/out -> "sptr" ; fInfoType : WORD -> "int" ; rgbInfoValue : void* optional, out -> "sptr" ; cbInfoValueMax : SHORT -> "int" ; pcbInfoValue : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLGetInfoW(void* hdbc, WORD fInfoType, void* rgbInfoValue, SHORT cbInfoValueMax, SHORT* pcbInfoValue) #uselib "ODBC32.dll" #cfunc global SQLGetInfoW "SQLGetInfoW" intptr, int, intptr, int, var ; res = SQLGetInfoW(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 方式にも切替可。; SHORT SQLGetInfoW(void* hdbc, WORD fInfoType, void* rgbInfoValue, SHORT cbInfoValueMax, SHORT* pcbInfoValue) #uselib "ODBC32.dll" #cfunc global SQLGetInfoW "SQLGetInfoW" intptr, int, intptr, int, intptr ; res = SQLGetInfoW(hdbc, fInfoType, rgbInfoValue, cbInfoValueMax, varptr(pcbInfoValue)) ; hdbc : void* in/out -> "intptr" ; fInfoType : WORD -> "int" ; rgbInfoValue : void* optional, out -> "intptr" ; cbInfoValueMax : SHORT -> "int" ; pcbInfoValue : SHORT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLGetInfoW = odbc32.NewProc("SQLGetInfoW")
)
// hdbc (void* in/out), fInfoType (WORD), rgbInfoValue (void* optional, out), cbInfoValueMax (SHORT), pcbInfoValue (SHORT* optional, out)
r1, _, err := procSQLGetInfoW.Call(
uintptr(hdbc),
uintptr(fInfoType),
uintptr(rgbInfoValue),
uintptr(cbInfoValueMax),
uintptr(pcbInfoValue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLGetInfoW(
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 'SQLGetInfoW';result := DllCall("ODBC32\SQLGetInfoW"
, "Ptr", hdbc ; void* in/out
, "UShort", fInfoType ; WORD
, "Ptr", rgbInfoValue ; void* optional, out
, "Short", cbInfoValueMax ; SHORT
, "Ptr", pcbInfoValue ; SHORT* optional, out
, "Short") ; return: SHORT●SQLGetInfoW(hdbc, fInfoType, rgbInfoValue, cbInfoValueMax, pcbInfoValue) = DLL("ODBC32.dll", "int SQLGetInfoW(void*, int, void*, int, void*)")
# 呼び出し: SQLGetInfoW(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)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "odbc32" fn SQLGetInfoW(
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;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SQLGetInfoW(
hdbc: pointer, # void* in/out
fInfoType: uint16, # WORD
rgbInfoValue: pointer, # void* optional, out
cbInfoValueMax: int16, # SHORT
pcbInfoValue: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLGetInfoW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "odbc32");
extern(Windows)
short SQLGetInfoW(
void* hdbc, // void* in/out
ushort fInfoType, // WORD
void* rgbInfoValue, // void* optional, out
short cbInfoValueMax, // SHORT
short* pcbInfoValue // SHORT* optional, out
);ccall((:SQLGetInfoW, "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 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetInfoW(
void* hdbc,
uint16_t fInfoType,
void* rgbInfoValue,
int16_t cbInfoValueMax,
int16_t* pcbInfoValue);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetInfoW(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 に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetInfoW = lib.func('__stdcall', 'SQLGetInfoW', 'int16_t', ['void *', 'uint16_t', 'void *', 'int16_t', 'int16_t *']);
// SQLGetInfoW(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", {
SQLGetInfoW: { parameters: ["pointer", "u16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetInfoW(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"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetInfoW(
void* hdbc,
uint16_t fInfoType,
void* rgbInfoValue,
int16_t cbInfoValueMax,
int16_t* pcbInfoValue);
C, "ODBC32.dll");
// $ffi->SQLGetInfoW(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.UNICODE_OPTIONS);
short SQLGetInfoW(
Pointer hdbc, // void* in/out
short fInfoType, // WORD
Pointer rgbInfoValue, // void* optional, out
short cbInfoValueMax, // SHORT
ShortByReference pcbInfoValue // SHORT* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("odbc32")]
lib LibODBC32
fun SQLGetInfoW = SQLGetInfoW(
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 SQLGetInfoWNative = Int16 Function(Pointer<Void>, Uint16, Pointer<Void>, Int16, Pointer<Int16>);
typedef SQLGetInfoWDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Int16>);
final SQLGetInfoW = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLGetInfoWNative, SQLGetInfoWDart>('SQLGetInfoW');
// 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 SQLGetInfoW(
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 'SQLGetInfoW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLGetInfoW"
c_SQLGetInfoW :: 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 sqlgetinfow =
foreign "SQLGetInfoW"
((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 ("SQLGetInfoW" sqlget-info-w :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 $SQLGetInfoW = Win32::API::More->new('ODBC32',
'short SQLGetInfoW(LPVOID hdbc, WORD fInfoType, LPVOID rgbInfoValue, short cbInfoValueMax, LPVOID pcbInfoValue)');
# my $ret = $SQLGetInfoW->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 を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SQLGetInfoA (ANSI版) — ODBCドライバやデータソースに関する情報を取得する。