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

SQLBindCol

関数
結果セットの列をアプリケーションのバッファに割り当てる。
DLLODBC32.dll呼出規約winapi

シグネチャ

// ODBC32.dll
#include <windows.h>

SHORT SQLBindCol(
    void* StatementHandle,
    WORD ColumnNumber,
    SHORT TargetType,
    void* TargetValue,   // optional
    INT BufferLength,
    INT* StrLen_or_Ind   // optional
);

パラメーター

名前方向説明
StatementHandlevoid*inout対象のステートメントハンドル(HSTMT)。
ColumnNumberWORDinバインドする結果列の番号。1始まり、0はブックマーク列。
TargetTypeSHORTin受信データのCデータ型を示す識別子(SQL_C_*)。
TargetValuevoid*inoutoptional取得した列値を格納するバッファへのポインタ。NULLでバインド解除。
BufferLengthINTinTargetValueバッファのバイト長。
StrLen_or_IndINT*inoutoptional実際のデータ長またはNULLインジケータを受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll
#include <windows.h>

SHORT SQLBindCol(
    void* StatementHandle,
    WORD ColumnNumber,
    SHORT TargetType,
    void* TargetValue,   // optional
    INT BufferLength,
    INT* StrLen_or_Ind   // optional
);
[DllImport("ODBC32.dll", ExactSpelling = true)]
static extern short SQLBindCol(
    IntPtr StatementHandle,   // void* in/out
    ushort ColumnNumber,   // WORD
    short TargetType,   // SHORT
    IntPtr TargetValue,   // void* optional, in/out
    int BufferLength,   // INT
    IntPtr StrLen_or_Ind   // INT* optional, in/out
);
<DllImport("ODBC32.dll", ExactSpelling:=True)>
Public Shared Function SQLBindCol(
    StatementHandle As IntPtr,   ' void* in/out
    ColumnNumber As UShort,   ' WORD
    TargetType As Short,   ' SHORT
    TargetValue As IntPtr,   ' void* optional, in/out
    BufferLength As Integer,   ' INT
    StrLen_or_Ind As IntPtr   ' INT* optional, in/out
) As Short
End Function
' StatementHandle : void* in/out
' ColumnNumber : WORD
' TargetType : SHORT
' TargetValue : void* optional, in/out
' BufferLength : INT
' StrLen_or_Ind : INT* optional, in/out
Declare PtrSafe Function SQLBindCol Lib "odbc32" ( _
    ByVal StatementHandle As LongPtr, _
    ByVal ColumnNumber As Integer, _
    ByVal TargetType As Integer, _
    ByVal TargetValue As LongPtr, _
    ByVal BufferLength As Long, _
    ByVal StrLen_or_Ind As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLBindCol = ctypes.windll.odbc32.SQLBindCol
SQLBindCol.restype = ctypes.c_short
SQLBindCol.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.c_ushort,  # ColumnNumber : WORD
    ctypes.c_short,  # TargetType : SHORT
    ctypes.POINTER(None),  # TargetValue : void* optional, in/out
    ctypes.c_int,  # BufferLength : INT
    ctypes.POINTER(ctypes.c_int),  # StrLen_or_Ind : INT* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLBindCol = Fiddle::Function.new(
  lib['SQLBindCol'],
  [
    Fiddle::TYPE_VOIDP,  # StatementHandle : void* in/out
    -Fiddle::TYPE_SHORT,  # ColumnNumber : WORD
    Fiddle::TYPE_SHORT,  # TargetType : SHORT
    Fiddle::TYPE_VOIDP,  # TargetValue : void* optional, in/out
    Fiddle::TYPE_INT,  # BufferLength : INT
    Fiddle::TYPE_VOIDP,  # StrLen_or_Ind : INT* optional, in/out
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLBindCol(
        StatementHandle: *mut (),  // void* in/out
        ColumnNumber: u16,  // WORD
        TargetType: i16,  // SHORT
        TargetValue: *mut (),  // void* optional, in/out
        BufferLength: i32,  // INT
        StrLen_or_Ind: *mut i32  // INT* optional, in/out
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll")]
public static extern short SQLBindCol(IntPtr StatementHandle, ushort ColumnNumber, short TargetType, IntPtr TargetValue, int BufferLength, IntPtr StrLen_or_Ind);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLBindCol' -Namespace Win32 -PassThru
# $api::SQLBindCol(StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, StrLen_or_Ind)
#uselib "ODBC32.dll"
#func global SQLBindCol "SQLBindCol" sptr, sptr, sptr, sptr, sptr, sptr
; SQLBindCol StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, varptr(StrLen_or_Ind)   ; 戻り値は stat
; StatementHandle : void* in/out -> "sptr"
; ColumnNumber : WORD -> "sptr"
; TargetType : SHORT -> "sptr"
; TargetValue : void* optional, in/out -> "sptr"
; BufferLength : INT -> "sptr"
; StrLen_or_Ind : INT* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLBindCol "SQLBindCol" sptr, int, int, sptr, int, var
; res = SQLBindCol(StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, StrLen_or_Ind)
; StatementHandle : void* in/out -> "sptr"
; ColumnNumber : WORD -> "int"
; TargetType : SHORT -> "int"
; TargetValue : void* optional, in/out -> "sptr"
; BufferLength : INT -> "int"
; StrLen_or_Ind : INT* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLBindCol(void* StatementHandle, WORD ColumnNumber, SHORT TargetType, void* TargetValue, INT BufferLength, INT* StrLen_or_Ind)
#uselib "ODBC32.dll"
#cfunc global SQLBindCol "SQLBindCol" intptr, int, int, intptr, int, var
; res = SQLBindCol(StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, StrLen_or_Ind)
; StatementHandle : void* in/out -> "intptr"
; ColumnNumber : WORD -> "int"
; TargetType : SHORT -> "int"
; TargetValue : void* optional, in/out -> "intptr"
; BufferLength : INT -> "int"
; StrLen_or_Ind : INT* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLBindCol = odbc32.NewProc("SQLBindCol")
)

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

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

typedef SQLBindColNative = Int16 Function(Pointer<Void>, Uint16, Int16, Pointer<Void>, Int32, Pointer<Int32>);
typedef SQLBindColDart = int Function(Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Int32>);
final SQLBindCol = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLBindColNative, SQLBindColDart>('SQLBindCol');
// StatementHandle : void* in/out -> Pointer<Void>
// ColumnNumber : WORD -> Uint16
// TargetType : SHORT -> Int16
// TargetValue : void* optional, in/out -> Pointer<Void>
// BufferLength : INT -> Int32
// StrLen_or_Ind : INT* optional, in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLBindCol(
  StatementHandle: Pointer;   // void* in/out
  ColumnNumber: Word;   // WORD
  TargetType: Smallint;   // SHORT
  TargetValue: Pointer;   // void* optional, in/out
  BufferLength: Integer;   // INT
  StrLen_or_Ind: Pointer   // INT* optional, in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLBindCol';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLBindCol"
  c_SQLBindCol :: Ptr () -> Word16 -> Int16 -> Ptr () -> Int32 -> Ptr Int32 -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- ColumnNumber : WORD -> Word16
-- TargetType : SHORT -> Int16
-- TargetValue : void* optional, in/out -> Ptr ()
-- BufferLength : INT -> Int32
-- StrLen_or_Ind : INT* optional, in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlbindcol =
  foreign "SQLBindCol"
    ((ptr void) @-> uint16_t @-> int16_t @-> (ptr void) @-> int32_t @-> (ptr int32_t) @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* ColumnNumber : WORD -> uint16_t *)
(* TargetType : SHORT -> int16_t *)
(* TargetValue : void* optional, in/out -> (ptr void) *)
(* BufferLength : INT -> int32_t *)
(* StrLen_or_Ind : INT* optional, in/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 ("SQLBindCol" sqlbind-col :convention :stdcall) :int16
  (statement-handle :pointer)   ; void* in/out
  (column-number :uint16)   ; WORD
  (target-type :int16)   ; SHORT
  (target-value :pointer)   ; void* optional, in/out
  (buffer-length :int32)   ; INT
  (str-len-or-ind :pointer))   ; INT* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLBindCol = Win32::API::More->new('ODBC32',
    'short SQLBindCol(LPVOID StatementHandle, WORD ColumnNumber, short TargetType, LPVOID TargetValue, int BufferLength, LPVOID StrLen_or_Ind)');
# my $ret = $SQLBindCol->Call($StatementHandle, $ColumnNumber, $TargetType, $TargetValue, $BufferLength, $StrLen_or_Ind);
# StatementHandle : void* in/out -> LPVOID
# ColumnNumber : WORD -> WORD
# TargetType : SHORT -> short
# TargetValue : void* optional, in/out -> LPVOID
# BufferLength : INT -> int
# StrLen_or_Ind : INT* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。