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

SQLSetConnectAttrA

関数
ODBC接続ハンドルの属性値を設定する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLSetConnectAttrA(
    void* hdbc,
    INT fAttribute,
    void* rgbValue,   // optional
    INT cbValue
);

パラメーター

名前方向説明
hdbcvoid*inoutODBCの接続ハンドル。属性設定対象。
fAttributeINTin設定する接続属性の識別子。SQL_ATTR_*定数。
rgbValuevoid*inoptional設定する属性値。整数値またはバッファへのポインタ。
cbValueINTinrgbValueのバイト長。文字列の場合はSQL_NTS指定可。

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLSetConnectAttrA = ctypes.windll.odbc32.SQLSetConnectAttrA
SQLSetConnectAttrA.restype = ctypes.c_short
SQLSetConnectAttrA.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.c_int,  # fAttribute : INT
    ctypes.POINTER(None),  # rgbValue : void* optional
    ctypes.c_int,  # cbValue : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLSetConnectAttrA = Fiddle::Function.new(
  lib['SQLSetConnectAttrA'],
  [
    Fiddle::TYPE_VOIDP,  # hdbc : void* in/out
    Fiddle::TYPE_INT,  # fAttribute : INT
    Fiddle::TYPE_VOIDP,  # rgbValue : void* optional
    Fiddle::TYPE_INT,  # cbValue : INT
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLSetConnectAttrA(
        hdbc: *mut (),  // void* in/out
        fAttribute: i32,  // INT
        rgbValue: *mut (),  // void* optional
        cbValue: i32  // INT
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLSetConnectAttrA(IntPtr hdbc, int fAttribute, IntPtr rgbValue, int cbValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLSetConnectAttrA' -Namespace Win32 -PassThru
# $api::SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue)
#uselib "ODBC32.dll"
#func global SQLSetConnectAttrA "SQLSetConnectAttrA" sptr, sptr, sptr, sptr
; SQLSetConnectAttrA hdbc, fAttribute, rgbValue, cbValue   ; 戻り値は stat
; hdbc : void* in/out -> "sptr"
; fAttribute : INT -> "sptr"
; rgbValue : void* optional -> "sptr"
; cbValue : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ODBC32.dll"
#cfunc global SQLSetConnectAttrA "SQLSetConnectAttrA" sptr, int, sptr, int
; res = SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue)
; hdbc : void* in/out -> "sptr"
; fAttribute : INT -> "int"
; rgbValue : void* optional -> "sptr"
; cbValue : INT -> "int"
; SHORT SQLSetConnectAttrA(void* hdbc, INT fAttribute, void* rgbValue, INT cbValue)
#uselib "ODBC32.dll"
#cfunc global SQLSetConnectAttrA "SQLSetConnectAttrA" intptr, int, intptr, int
; res = SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue)
; hdbc : void* in/out -> "intptr"
; fAttribute : INT -> "int"
; rgbValue : void* optional -> "intptr"
; cbValue : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLSetConnectAttrA = odbc32.NewProc("SQLSetConnectAttrA")
)

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

extern "odbc32" fn SQLSetConnectAttrA(
    hdbc: ?*anyopaque, // void* in/out
    fAttribute: i32, // INT
    rgbValue: ?*anyopaque, // void* optional
    cbValue: i32 // INT
) callconv(std.os.windows.WINAPI) i16;
proc SQLSetConnectAttrA(
    hdbc: pointer,  # void* in/out
    fAttribute: int32,  # INT
    rgbValue: pointer,  # void* optional
    cbValue: int32  # INT
): int16 {.importc: "SQLSetConnectAttrA", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLSetConnectAttrA(
    void* hdbc,   // void* in/out
    int fAttribute,   // INT
    void* rgbValue,   // void* optional
    int cbValue   // INT
);
ccall((:SQLSetConnectAttrA, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, Int32),
      hdbc, fAttribute, rgbValue, cbValue)
# hdbc : void* in/out -> Ptr{Cvoid}
# fAttribute : INT -> Int32
# rgbValue : void* optional -> Ptr{Cvoid}
# cbValue : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLSetConnectAttrA(
    void* hdbc,
    int32_t fAttribute,
    void* rgbValue,
    int32_t cbValue);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue)
-- hdbc : void* in/out
-- fAttribute : INT
-- rgbValue : void* optional
-- cbValue : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLSetConnectAttrA = lib.func('__stdcall', 'SQLSetConnectAttrA', 'int16_t', ['void *', 'int32_t', 'void *', 'int32_t']);
// SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue)
// hdbc : void* in/out -> 'void *'
// fAttribute : INT -> 'int32_t'
// rgbValue : void* optional -> 'void *'
// cbValue : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLSetConnectAttrA: { parameters: ["pointer", "i32", "pointer", "i32"], result: "i16" },
});
// lib.symbols.SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue)
// hdbc : void* in/out -> "pointer"
// fAttribute : INT -> "i32"
// rgbValue : void* optional -> "pointer"
// cbValue : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLSetConnectAttrA(
    void* hdbc,
    int32_t fAttribute,
    void* rgbValue,
    int32_t cbValue);
C, "ODBC32.dll");
// $ffi->SQLSetConnectAttrA(hdbc, fAttribute, rgbValue, cbValue);
// hdbc : void* in/out
// fAttribute : INT
// rgbValue : void* optional
// cbValue : INT
// 構造体/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 SQLSetConnectAttrA(
        Pointer hdbc,   // void* in/out
        int fAttribute,   // INT
        Pointer rgbValue,   // void* optional
        int cbValue   // INT
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLSetConnectAttrA = SQLSetConnectAttrA(
    hdbc : Void*,   # void* in/out
    fAttribute : Int32,   # INT
    rgbValue : Void*,   # void* optional
    cbValue : Int32   # INT
  ) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SQLSetConnectAttrANative = Int16 Function(Pointer<Void>, Int32, Pointer<Void>, Int32);
typedef SQLSetConnectAttrADart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final SQLSetConnectAttrA = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLSetConnectAttrANative, SQLSetConnectAttrADart>('SQLSetConnectAttrA');
// hdbc : void* in/out -> Pointer<Void>
// fAttribute : INT -> Int32
// rgbValue : void* optional -> Pointer<Void>
// cbValue : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLSetConnectAttrA(
  hdbc: Pointer;   // void* in/out
  fAttribute: Integer;   // INT
  rgbValue: Pointer;   // void* optional
  cbValue: Integer   // INT
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLSetConnectAttrA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLSetConnectAttrA"
  c_SQLSetConnectAttrA :: Ptr () -> Int32 -> Ptr () -> Int32 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- fAttribute : INT -> Int32
-- rgbValue : void* optional -> Ptr ()
-- cbValue : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlsetconnectattra =
  foreign "SQLSetConnectAttrA"
    ((ptr void) @-> int32_t @-> (ptr void) @-> int32_t @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* fAttribute : INT -> int32_t *)
(* rgbValue : void* optional -> (ptr void) *)
(* cbValue : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLSetConnectAttrA" sqlset-connect-attr-a :convention :stdcall) :int16
  (hdbc :pointer)   ; void* in/out
  (f-attribute :int32)   ; INT
  (rgb-value :pointer)   ; void* optional
  (cb-value :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLSetConnectAttrA = Win32::API::More->new('ODBC32',
    'short SQLSetConnectAttrA(LPVOID hdbc, int fAttribute, LPVOID rgbValue, int cbValue)');
# my $ret = $SQLSetConnectAttrA->Call($hdbc, $fAttribute, $rgbValue, $cbValue);
# hdbc : void* in/out -> LPVOID
# fAttribute : INT -> int
# rgbValue : void* optional -> LPVOID
# cbValue : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い