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

SQLGetData

関数
結果セット列のデータを部分的に取得する。
DLLODBC32.dll呼出規約winapi

シグネチャ

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

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

パラメーター

名前方向
StatementHandlevoid*inout
ColumnNumberWORDin
TargetTypeSHORTin
TargetValuevoid*outoptional
BufferLengthINTin
StrLen_or_IndPtrINT*outoptional

戻り値の型: SHORT

各言語での呼び出し定義

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

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

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

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLGetData = odbc32.NewProc("SQLGetData")
)

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