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