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