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

SQLSetConnectAttr

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

シグネチャ

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

SHORT SQLSetConnectAttr(
    void* ConnectionHandle,
    INT Attribute,
    void* Value,   // optional
    INT StringLength
);

パラメーター

名前方向説明
ConnectionHandlevoid*inout属性を設定する接続ハンドル。
AttributeINTin設定する接続属性のID。SQL_ATTR_*定数を指定する。
Valuevoid*inoptional設定する属性値。整数または文字列バッファへのポインタ。
StringLengthINTinValueが文字列の場合のバイト長。整数値ならSQL_IS_INTEGER等。

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLSetConnectAttr = ctypes.windll.odbc32.SQLSetConnectAttr
SQLSetConnectAttr.restype = ctypes.c_short
SQLSetConnectAttr.argtypes = [
    ctypes.POINTER(None),  # ConnectionHandle : void* in/out
    ctypes.c_int,  # Attribute : INT
    ctypes.POINTER(None),  # Value : void* optional
    ctypes.c_int,  # StringLength : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLSetConnectAttr = odbc32.NewProc("SQLSetConnectAttr")
)

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

extern "odbc32" fn SQLSetConnectAttr(
    ConnectionHandle: ?*anyopaque, // void* in/out
    Attribute: i32, // INT
    Value: ?*anyopaque, // void* optional
    StringLength: i32 // INT
) callconv(std.os.windows.WINAPI) i16;
proc SQLSetConnectAttr(
    ConnectionHandle: pointer,  # void* in/out
    Attribute: int32,  # INT
    Value: pointer,  # void* optional
    StringLength: int32  # INT
): int16 {.importc: "SQLSetConnectAttr", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLSetConnectAttr(
    void* ConnectionHandle,   // void* in/out
    int Attribute,   // INT
    void* Value,   // void* optional
    int StringLength   // INT
);
ccall((:SQLSetConnectAttr, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, Int32),
      ConnectionHandle, Attribute, Value, StringLength)
# ConnectionHandle : void* in/out -> Ptr{Cvoid}
# Attribute : INT -> Int32
# Value : void* optional -> Ptr{Cvoid}
# StringLength : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLSetConnectAttr(
    void* ConnectionHandle,
    int32_t Attribute,
    void* Value,
    int32_t StringLength);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLSetConnectAttr(ConnectionHandle, Attribute, Value, StringLength)
-- ConnectionHandle : void* in/out
-- Attribute : INT
-- Value : void* optional
-- StringLength : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLSetConnectAttr = lib.func('__stdcall', 'SQLSetConnectAttr', 'int16_t', ['void *', 'int32_t', 'void *', 'int32_t']);
// SQLSetConnectAttr(ConnectionHandle, Attribute, Value, StringLength)
// ConnectionHandle : void* in/out -> 'void *'
// Attribute : INT -> 'int32_t'
// Value : void* optional -> 'void *'
// StringLength : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLSetConnectAttr: { parameters: ["pointer", "i32", "pointer", "i32"], result: "i16" },
});
// lib.symbols.SQLSetConnectAttr(ConnectionHandle, Attribute, Value, StringLength)
// ConnectionHandle : void* in/out -> "pointer"
// Attribute : INT -> "i32"
// Value : void* optional -> "pointer"
// StringLength : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLSetConnectAttr(
    void* ConnectionHandle,
    int32_t Attribute,
    void* Value,
    int32_t StringLength);
C, "ODBC32.dll");
// $ffi->SQLSetConnectAttr(ConnectionHandle, Attribute, Value, StringLength);
// ConnectionHandle : void* in/out
// Attribute : INT
// Value : void* optional
// StringLength : 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 SQLSetConnectAttr(
        Pointer ConnectionHandle,   // void* in/out
        int Attribute,   // INT
        Pointer Value,   // void* optional
        int StringLength   // INT
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLSetConnectAttr = SQLSetConnectAttr(
    ConnectionHandle : Void*,   # void* in/out
    Attribute : Int32,   # INT
    Value : Void*,   # void* optional
    StringLength : 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 SQLSetConnectAttrNative = Int16 Function(Pointer<Void>, Int32, Pointer<Void>, Int32);
typedef SQLSetConnectAttrDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final SQLSetConnectAttr = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLSetConnectAttrNative, SQLSetConnectAttrDart>('SQLSetConnectAttr');
// ConnectionHandle : void* in/out -> Pointer<Void>
// Attribute : INT -> Int32
// Value : void* optional -> Pointer<Void>
// StringLength : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLSetConnectAttr(
  ConnectionHandle: Pointer;   // void* in/out
  Attribute: Integer;   // INT
  Value: Pointer;   // void* optional
  StringLength: Integer   // INT
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLSetConnectAttr';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let sqlsetconnectattr =
  foreign "SQLSetConnectAttr"
    ((ptr void) @-> int32_t @-> (ptr void) @-> int32_t @-> returning int16_t)
(* ConnectionHandle : void* in/out -> (ptr void) *)
(* Attribute : INT -> int32_t *)
(* Value : void* optional -> (ptr void) *)
(* StringLength : 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 ("SQLSetConnectAttr" sqlset-connect-attr :convention :stdcall) :int16
  (connection-handle :pointer)   ; void* in/out
  (attribute :int32)   ; INT
  (value :pointer)   ; void* optional
  (string-length :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLSetConnectAttr = Win32::API::More->new('ODBC32',
    'short SQLSetConnectAttr(LPVOID ConnectionHandle, int Attribute, LPVOID Value, int StringLength)');
# my $ret = $SQLSetConnectAttr->Call($ConnectionHandle, $Attribute, $Value, $StringLength);
# ConnectionHandle : void* in/out -> LPVOID
# Attribute : INT -> int
# Value : void* optional -> LPVOID
# StringLength : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い