ホーム › System.Search › SQLGetInfo
SQLGetInfo
関数ドライバやデータソースの一般情報を取得する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLGetInfo(
void* ConnectionHandle,
WORD InfoType,
void* InfoValue, // optional
SHORT BufferLength,
SHORT* StringLengthPtr // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ConnectionHandle | void* | inout | 情報を取得する接続ハンドル。 |
| InfoType | WORD | in | 取得する情報の種別。SQL_*情報型定数を指定する。 |
| InfoValue | void* | outoptional | 情報値を受け取るバッファへのポインタ。 |
| BufferLength | SHORT | in | InfoValueバッファのバイト長。文字列情報で意味を持つ。 |
| StringLengthPtr | SHORT* | outoptional | 実際に書き込まれたバイト数を受け取るポインタ。NULL可。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLGetInfo(
void* ConnectionHandle,
WORD InfoType,
void* InfoValue, // optional
SHORT BufferLength,
SHORT* StringLengthPtr // optional
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLGetInfo(
IntPtr ConnectionHandle, // void* in/out
ushort InfoType, // WORD
IntPtr InfoValue, // void* optional, out
short BufferLength, // SHORT
IntPtr StringLengthPtr // SHORT* optional, out
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLGetInfo(
ConnectionHandle As IntPtr, ' void* in/out
InfoType As UShort, ' WORD
InfoValue As IntPtr, ' void* optional, out
BufferLength As Short, ' SHORT
StringLengthPtr As IntPtr ' SHORT* optional, out
) As Short
End Function' ConnectionHandle : void* in/out
' InfoType : WORD
' InfoValue : void* optional, out
' BufferLength : SHORT
' StringLengthPtr : SHORT* optional, out
Declare PtrSafe Function SQLGetInfo Lib "odbc32" ( _
ByVal ConnectionHandle As LongPtr, _
ByVal InfoType As Integer, _
ByVal InfoValue As LongPtr, _
ByVal BufferLength As Integer, _
ByVal StringLengthPtr As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLGetInfo = ctypes.windll.odbc32.SQLGetInfo
SQLGetInfo.restype = ctypes.c_short
SQLGetInfo.argtypes = [
ctypes.POINTER(None), # ConnectionHandle : void* in/out
ctypes.c_ushort, # InfoType : WORD
ctypes.POINTER(None), # InfoValue : void* optional, out
ctypes.c_short, # BufferLength : SHORT
ctypes.POINTER(ctypes.c_short), # StringLengthPtr : SHORT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLGetInfo = Fiddle::Function.new(
lib['SQLGetInfo'],
[
Fiddle::TYPE_VOIDP, # ConnectionHandle : void* in/out
-Fiddle::TYPE_SHORT, # InfoType : WORD
Fiddle::TYPE_VOIDP, # InfoValue : void* optional, out
Fiddle::TYPE_SHORT, # BufferLength : SHORT
Fiddle::TYPE_VOIDP, # StringLengthPtr : SHORT* optional, out
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLGetInfo(
ConnectionHandle: *mut (), // void* in/out
InfoType: u16, // WORD
InfoValue: *mut (), // void* optional, out
BufferLength: i16, // SHORT
StringLengthPtr: *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 SQLGetInfo(IntPtr ConnectionHandle, ushort InfoType, IntPtr InfoValue, short BufferLength, IntPtr StringLengthPtr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLGetInfo' -Namespace Win32 -PassThru
# $api::SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr)#uselib "ODBC32.dll"
#func global SQLGetInfo "SQLGetInfo" sptr, sptr, sptr, sptr, sptr
; SQLGetInfo ConnectionHandle, InfoType, InfoValue, BufferLength, varptr(StringLengthPtr) ; 戻り値は stat
; ConnectionHandle : void* in/out -> "sptr"
; InfoType : WORD -> "sptr"
; InfoValue : void* optional, out -> "sptr"
; BufferLength : SHORT -> "sptr"
; StringLengthPtr : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLGetInfo "SQLGetInfo" sptr, int, sptr, int, var ; res = SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr) ; ConnectionHandle : void* in/out -> "sptr" ; InfoType : WORD -> "int" ; InfoValue : void* optional, out -> "sptr" ; BufferLength : SHORT -> "int" ; StringLengthPtr : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLGetInfo "SQLGetInfo" sptr, int, sptr, int, sptr ; res = SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, varptr(StringLengthPtr)) ; ConnectionHandle : void* in/out -> "sptr" ; InfoType : WORD -> "int" ; InfoValue : void* optional, out -> "sptr" ; BufferLength : SHORT -> "int" ; StringLengthPtr : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLGetInfo(void* ConnectionHandle, WORD InfoType, void* InfoValue, SHORT BufferLength, SHORT* StringLengthPtr) #uselib "ODBC32.dll" #cfunc global SQLGetInfo "SQLGetInfo" intptr, int, intptr, int, var ; res = SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr) ; ConnectionHandle : void* in/out -> "intptr" ; InfoType : WORD -> "int" ; InfoValue : void* optional, out -> "intptr" ; BufferLength : SHORT -> "int" ; StringLengthPtr : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLGetInfo(void* ConnectionHandle, WORD InfoType, void* InfoValue, SHORT BufferLength, SHORT* StringLengthPtr) #uselib "ODBC32.dll" #cfunc global SQLGetInfo "SQLGetInfo" intptr, int, intptr, int, intptr ; res = SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, varptr(StringLengthPtr)) ; ConnectionHandle : void* in/out -> "intptr" ; InfoType : WORD -> "int" ; InfoValue : void* optional, out -> "intptr" ; BufferLength : SHORT -> "int" ; StringLengthPtr : SHORT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLGetInfo = odbc32.NewProc("SQLGetInfo")
)
// ConnectionHandle (void* in/out), InfoType (WORD), InfoValue (void* optional, out), BufferLength (SHORT), StringLengthPtr (SHORT* optional, out)
r1, _, err := procSQLGetInfo.Call(
uintptr(ConnectionHandle),
uintptr(InfoType),
uintptr(InfoValue),
uintptr(BufferLength),
uintptr(StringLengthPtr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLGetInfo(
ConnectionHandle: Pointer; // void* in/out
InfoType: Word; // WORD
InfoValue: Pointer; // void* optional, out
BufferLength: Smallint; // SHORT
StringLengthPtr: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetInfo';result := DllCall("ODBC32\SQLGetInfo"
, "Ptr", ConnectionHandle ; void* in/out
, "UShort", InfoType ; WORD
, "Ptr", InfoValue ; void* optional, out
, "Short", BufferLength ; SHORT
, "Ptr", StringLengthPtr ; SHORT* optional, out
, "Short") ; return: SHORT●SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr) = DLL("ODBC32.dll", "int SQLGetInfo(void*, int, void*, int, void*)")
# 呼び出し: SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr)
# ConnectionHandle : void* in/out -> "void*"
# InfoType : WORD -> "int"
# InfoValue : void* optional, out -> "void*"
# BufferLength : SHORT -> "int"
# StringLengthPtr : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLGetInfo(
ConnectionHandle: ?*anyopaque, // void* in/out
InfoType: u16, // WORD
InfoValue: ?*anyopaque, // void* optional, out
BufferLength: i16, // SHORT
StringLengthPtr: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;proc SQLGetInfo(
ConnectionHandle: pointer, # void* in/out
InfoType: uint16, # WORD
InfoValue: pointer, # void* optional, out
BufferLength: int16, # SHORT
StringLengthPtr: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLGetInfo", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLGetInfo(
void* ConnectionHandle, // void* in/out
ushort InfoType, // WORD
void* InfoValue, // void* optional, out
short BufferLength, // SHORT
short* StringLengthPtr // SHORT* optional, out
);ccall((:SQLGetInfo, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, UInt16, Ptr{Cvoid}, Int16, Ptr{Int16}),
ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr)
# ConnectionHandle : void* in/out -> Ptr{Cvoid}
# InfoType : WORD -> UInt16
# InfoValue : void* optional, out -> Ptr{Cvoid}
# BufferLength : SHORT -> Int16
# StringLengthPtr : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLGetInfo(
void* ConnectionHandle,
uint16_t InfoType,
void* InfoValue,
int16_t BufferLength,
int16_t* StringLengthPtr);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr)
-- ConnectionHandle : void* in/out
-- InfoType : WORD
-- InfoValue : void* optional, out
-- BufferLength : SHORT
-- StringLengthPtr : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLGetInfo = lib.func('__stdcall', 'SQLGetInfo', 'int16_t', ['void *', 'uint16_t', 'void *', 'int16_t', 'int16_t *']);
// SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr)
// ConnectionHandle : void* in/out -> 'void *'
// InfoType : WORD -> 'uint16_t'
// InfoValue : void* optional, out -> 'void *'
// BufferLength : SHORT -> 'int16_t'
// StringLengthPtr : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLGetInfo: { parameters: ["pointer", "u16", "pointer", "i16", "pointer"], result: "i16" },
});
// lib.symbols.SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr)
// ConnectionHandle : void* in/out -> "pointer"
// InfoType : WORD -> "u16"
// InfoValue : void* optional, out -> "pointer"
// BufferLength : SHORT -> "i16"
// StringLengthPtr : SHORT* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLGetInfo(
void* ConnectionHandle,
uint16_t InfoType,
void* InfoValue,
int16_t BufferLength,
int16_t* StringLengthPtr);
C, "ODBC32.dll");
// $ffi->SQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLengthPtr);
// ConnectionHandle : void* in/out
// InfoType : WORD
// InfoValue : void* optional, out
// BufferLength : SHORT
// StringLengthPtr : 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 SQLGetInfo(
Pointer ConnectionHandle, // void* in/out
short InfoType, // WORD
Pointer InfoValue, // void* optional, out
short BufferLength, // SHORT
ShortByReference StringLengthPtr // SHORT* optional, out
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLGetInfo = SQLGetInfo(
ConnectionHandle : Void*, # void* in/out
InfoType : UInt16, # WORD
InfoValue : Void*, # void* optional, out
BufferLength : Int16, # SHORT
StringLengthPtr : 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 SQLGetInfoNative = Int16 Function(Pointer<Void>, Uint16, Pointer<Void>, Int16, Pointer<Int16>);
typedef SQLGetInfoDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Int16>);
final SQLGetInfo = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLGetInfoNative, SQLGetInfoDart>('SQLGetInfo');
// ConnectionHandle : void* in/out -> Pointer<Void>
// InfoType : WORD -> Uint16
// InfoValue : void* optional, out -> Pointer<Void>
// BufferLength : SHORT -> Int16
// StringLengthPtr : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLGetInfo(
ConnectionHandle: Pointer; // void* in/out
InfoType: Word; // WORD
InfoValue: Pointer; // void* optional, out
BufferLength: Smallint; // SHORT
StringLengthPtr: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLGetInfo';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLGetInfo"
c_SQLGetInfo :: Ptr () -> Word16 -> Ptr () -> Int16 -> Ptr Int16 -> IO Int16
-- ConnectionHandle : void* in/out -> Ptr ()
-- InfoType : WORD -> Word16
-- InfoValue : void* optional, out -> Ptr ()
-- BufferLength : SHORT -> Int16
-- StringLengthPtr : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlgetinfo =
foreign "SQLGetInfo"
((ptr void) @-> uint16_t @-> (ptr void) @-> int16_t @-> (ptr int16_t) @-> returning int16_t)
(* ConnectionHandle : void* in/out -> (ptr void) *)
(* InfoType : WORD -> uint16_t *)
(* InfoValue : void* optional, out -> (ptr void) *)
(* BufferLength : SHORT -> int16_t *)
(* StringLengthPtr : 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 ("SQLGetInfo" sqlget-info :convention :stdcall) :int16
(connection-handle :pointer) ; void* in/out
(info-type :uint16) ; WORD
(info-value :pointer) ; void* optional, out
(buffer-length :int16) ; SHORT
(string-length-ptr :pointer)) ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLGetInfo = Win32::API::More->new('ODBC32',
'short SQLGetInfo(LPVOID ConnectionHandle, WORD InfoType, LPVOID InfoValue, short BufferLength, LPVOID StringLengthPtr)');
# my $ret = $SQLGetInfo->Call($ConnectionHandle, $InfoType, $InfoValue, $BufferLength, $StringLengthPtr);
# ConnectionHandle : void* in/out -> LPVOID
# InfoType : WORD -> WORD
# InfoValue : void* optional, out -> LPVOID
# BufferLength : SHORT -> short
# StringLengthPtr : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLGetInfoA (ANSI版) — ODBCドライバやデータソースに関する情報を取得する。
- f SQLGetInfoW (Unicode版) — ドライバやデータソースの一般情報を取得する(Unicode)。