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

SQLSetParam

関数
SQL文のパラメータにバッファを割り当てる(非推奨)。
DLLODBC32.dll呼出規約winapi

シグネチャ

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

SHORT SQLSetParam(
    void* StatementHandle,
    WORD ParameterNumber,
    SHORT ValueType,
    SHORT ParameterType,
    DWORD LengthPrecision,
    SHORT ParameterScale,
    void* ParameterValue,
    INT* StrLen_or_Ind
);

パラメーター

名前方向
StatementHandlevoid*inout
ParameterNumberWORDin
ValueTypeSHORTin
ParameterTypeSHORTin
LengthPrecisionDWORDin
ParameterScaleSHORTin
ParameterValuevoid*in
StrLen_or_IndINT*inout

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLSetParam(
    void* StatementHandle,
    WORD ParameterNumber,
    SHORT ValueType,
    SHORT ParameterType,
    DWORD LengthPrecision,
    SHORT ParameterScale,
    void* ParameterValue,
    INT* StrLen_or_Ind
);
[DllImport("ODBC32.dll", ExactSpelling = true)]
static extern short SQLSetParam(
    IntPtr StatementHandle,   // void* in/out
    ushort ParameterNumber,   // WORD
    short ValueType,   // SHORT
    short ParameterType,   // SHORT
    uint LengthPrecision,   // DWORD
    short ParameterScale,   // SHORT
    IntPtr ParameterValue,   // void*
    ref int StrLen_or_Ind   // INT* in/out
);
<DllImport("ODBC32.dll", ExactSpelling:=True)>
Public Shared Function SQLSetParam(
    StatementHandle As IntPtr,   ' void* in/out
    ParameterNumber As UShort,   ' WORD
    ValueType As Short,   ' SHORT
    ParameterType As Short,   ' SHORT
    LengthPrecision As UInteger,   ' DWORD
    ParameterScale As Short,   ' SHORT
    ParameterValue As IntPtr,   ' void*
    ByRef StrLen_or_Ind As Integer   ' INT* in/out
) As Short
End Function
' StatementHandle : void* in/out
' ParameterNumber : WORD
' ValueType : SHORT
' ParameterType : SHORT
' LengthPrecision : DWORD
' ParameterScale : SHORT
' ParameterValue : void*
' StrLen_or_Ind : INT* in/out
Declare PtrSafe Function SQLSetParam Lib "odbc32" ( _
    ByVal StatementHandle As LongPtr, _
    ByVal ParameterNumber As Integer, _
    ByVal ValueType As Integer, _
    ByVal ParameterType As Integer, _
    ByVal LengthPrecision As Long, _
    ByVal ParameterScale As Integer, _
    ByVal ParameterValue As LongPtr, _
    ByRef StrLen_or_Ind As Long) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLSetParam = ctypes.windll.odbc32.SQLSetParam
SQLSetParam.restype = ctypes.c_short
SQLSetParam.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.c_ushort,  # ParameterNumber : WORD
    ctypes.c_short,  # ValueType : SHORT
    ctypes.c_short,  # ParameterType : SHORT
    wintypes.DWORD,  # LengthPrecision : DWORD
    ctypes.c_short,  # ParameterScale : SHORT
    ctypes.POINTER(None),  # ParameterValue : void*
    ctypes.POINTER(ctypes.c_int),  # StrLen_or_Ind : INT* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLSetParam = odbc32.NewProc("SQLSetParam")
)

// StatementHandle (void* in/out), ParameterNumber (WORD), ValueType (SHORT), ParameterType (SHORT), LengthPrecision (DWORD), ParameterScale (SHORT), ParameterValue (void*), StrLen_or_Ind (INT* in/out)
r1, _, err := procSQLSetParam.Call(
	uintptr(StatementHandle),
	uintptr(ParameterNumber),
	uintptr(ValueType),
	uintptr(ParameterType),
	uintptr(LengthPrecision),
	uintptr(ParameterScale),
	uintptr(ParameterValue),
	uintptr(StrLen_or_Ind),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLSetParam(
  StatementHandle: Pointer;   // void* in/out
  ParameterNumber: Word;   // WORD
  ValueType: Smallint;   // SHORT
  ParameterType: Smallint;   // SHORT
  LengthPrecision: DWORD;   // DWORD
  ParameterScale: Smallint;   // SHORT
  ParameterValue: Pointer;   // void*
  StrLen_or_Ind: Pointer   // INT* in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLSetParam';
result := DllCall("ODBC32\SQLSetParam"
    , "Ptr", StatementHandle   ; void* in/out
    , "UShort", ParameterNumber   ; WORD
    , "Short", ValueType   ; SHORT
    , "Short", ParameterType   ; SHORT
    , "UInt", LengthPrecision   ; DWORD
    , "Short", ParameterScale   ; SHORT
    , "Ptr", ParameterValue   ; void*
    , "Ptr", StrLen_or_Ind   ; INT* in/out
    , "Short")   ; return: SHORT
●SQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind) = DLL("ODBC32.dll", "int SQLSetParam(void*, int, int, int, dword, int, void*, void*)")
# 呼び出し: SQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind)
# StatementHandle : void* in/out -> "void*"
# ParameterNumber : WORD -> "int"
# ValueType : SHORT -> "int"
# ParameterType : SHORT -> "int"
# LengthPrecision : DWORD -> "dword"
# ParameterScale : SHORT -> "int"
# ParameterValue : void* -> "void*"
# StrLen_or_Ind : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。