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パラメータを設定する対象のステートメントハンドル。非推奨API。
ParameterNumberWORDinパラメータ番号。1始まりで指定する。
ValueTypeSHORTinパラメータ値のCデータ型。SQL_C_*定数を指定する。
ParameterTypeSHORTinパラメータのSQLデータ型を指定する。
LengthPrecisionDWORDinパラメータの精度または列定義の長さを指定する。
ParameterScaleSHORTinパラメータの小数点以下桁数(スケール)を指定する。
ParameterValuevoid*inパラメータ値を格納するバッファへのポインタ。
StrLen_or_IndINT*inout値のバイト長またはSQL_NULL_DATA等の標識を受け取るポインタ。

戻り値の型: 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)。
const std = @import("std");

extern "odbc32" fn SQLSetParam(
    StatementHandle: ?*anyopaque, // void* in/out
    ParameterNumber: u16, // WORD
    ValueType: i16, // SHORT
    ParameterType: i16, // SHORT
    LengthPrecision: u32, // DWORD
    ParameterScale: i16, // SHORT
    ParameterValue: ?*anyopaque, // void*
    StrLen_or_Ind: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) i16;
proc SQLSetParam(
    StatementHandle: pointer,  # void* in/out
    ParameterNumber: uint16,  # WORD
    ValueType: int16,  # SHORT
    ParameterType: int16,  # SHORT
    LengthPrecision: uint32,  # DWORD
    ParameterScale: int16,  # SHORT
    ParameterValue: pointer,  # void*
    StrLen_or_Ind: ptr int32  # INT* in/out
): int16 {.importc: "SQLSetParam", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLSetParam(
    void* StatementHandle,   // void* in/out
    ushort ParameterNumber,   // WORD
    short ValueType,   // SHORT
    short ParameterType,   // SHORT
    uint LengthPrecision,   // DWORD
    short ParameterScale,   // SHORT
    void* ParameterValue,   // void*
    int* StrLen_or_Ind   // INT* in/out
);
ccall((:SQLSetParam, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, UInt16, Int16, Int16, UInt32, Int16, Ptr{Cvoid}, Ptr{Int32}),
      StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind)
# StatementHandle : void* in/out -> Ptr{Cvoid}
# ParameterNumber : WORD -> UInt16
# ValueType : SHORT -> Int16
# ParameterType : SHORT -> Int16
# LengthPrecision : DWORD -> UInt32
# ParameterScale : SHORT -> Int16
# ParameterValue : void* -> Ptr{Cvoid}
# StrLen_or_Ind : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLSetParam(
    void* StatementHandle,
    uint16_t ParameterNumber,
    int16_t ValueType,
    int16_t ParameterType,
    uint32_t LengthPrecision,
    int16_t ParameterScale,
    void* ParameterValue,
    int32_t* StrLen_or_Ind);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind)
-- StatementHandle : void* in/out
-- ParameterNumber : WORD
-- ValueType : SHORT
-- ParameterType : SHORT
-- LengthPrecision : DWORD
-- ParameterScale : SHORT
-- ParameterValue : void*
-- StrLen_or_Ind : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLSetParam = lib.func('__stdcall', 'SQLSetParam', 'int16_t', ['void *', 'uint16_t', 'int16_t', 'int16_t', 'uint32_t', 'int16_t', 'void *', 'int32_t *']);
// SQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind)
// StatementHandle : void* in/out -> 'void *'
// ParameterNumber : WORD -> 'uint16_t'
// ValueType : SHORT -> 'int16_t'
// ParameterType : SHORT -> 'int16_t'
// LengthPrecision : DWORD -> 'uint32_t'
// ParameterScale : SHORT -> 'int16_t'
// ParameterValue : void* -> 'void *'
// StrLen_or_Ind : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLSetParam: { parameters: ["pointer", "u16", "i16", "i16", "u32", "i16", "pointer", "pointer"], result: "i16" },
});
// lib.symbols.SQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind)
// StatementHandle : void* in/out -> "pointer"
// ParameterNumber : WORD -> "u16"
// ValueType : SHORT -> "i16"
// ParameterType : SHORT -> "i16"
// LengthPrecision : DWORD -> "u32"
// ParameterScale : SHORT -> "i16"
// ParameterValue : void* -> "pointer"
// StrLen_or_Ind : INT* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLSetParam(
    void* StatementHandle,
    uint16_t ParameterNumber,
    int16_t ValueType,
    int16_t ParameterType,
    uint32_t LengthPrecision,
    int16_t ParameterScale,
    void* ParameterValue,
    int32_t* StrLen_or_Ind);
C, "ODBC32.dll");
// $ffi->SQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, StrLen_or_Ind);
// StatementHandle : void* in/out
// ParameterNumber : WORD
// ValueType : SHORT
// ParameterType : SHORT
// LengthPrecision : DWORD
// ParameterScale : SHORT
// ParameterValue : void*
// StrLen_or_Ind : INT* 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 SQLSetParam(
        Pointer StatementHandle,   // void* in/out
        short ParameterNumber,   // WORD
        short ValueType,   // SHORT
        short ParameterType,   // SHORT
        int LengthPrecision,   // DWORD
        short ParameterScale,   // SHORT
        Pointer ParameterValue,   // void*
        IntByReference StrLen_or_Ind   // INT* in/out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLSetParam = SQLSetParam(
    StatementHandle : Void*,   # void* in/out
    ParameterNumber : UInt16,   # WORD
    ValueType : Int16,   # SHORT
    ParameterType : Int16,   # SHORT
    LengthPrecision : UInt32,   # DWORD
    ParameterScale : Int16,   # SHORT
    ParameterValue : Void*,   # void*
    StrLen_or_Ind : Int32*   # INT* 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 SQLSetParamNative = Int16 Function(Pointer<Void>, Uint16, Int16, Int16, Uint32, Int16, Pointer<Void>, Pointer<Int32>);
typedef SQLSetParamDart = int Function(Pointer<Void>, int, int, int, int, int, Pointer<Void>, Pointer<Int32>);
final SQLSetParam = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLSetParamNative, SQLSetParamDart>('SQLSetParam');
// StatementHandle : void* in/out -> Pointer<Void>
// ParameterNumber : WORD -> Uint16
// ValueType : SHORT -> Int16
// ParameterType : SHORT -> Int16
// LengthPrecision : DWORD -> Uint32
// ParameterScale : SHORT -> Int16
// ParameterValue : void* -> Pointer<Void>
// StrLen_or_Ind : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLSetParam"
  c_SQLSetParam :: Ptr () -> Word16 -> Int16 -> Int16 -> Word32 -> Int16 -> Ptr () -> Ptr Int32 -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- ParameterNumber : WORD -> Word16
-- ValueType : SHORT -> Int16
-- ParameterType : SHORT -> Int16
-- LengthPrecision : DWORD -> Word32
-- ParameterScale : SHORT -> Int16
-- ParameterValue : void* -> Ptr ()
-- StrLen_or_Ind : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlsetparam =
  foreign "SQLSetParam"
    ((ptr void) @-> uint16_t @-> int16_t @-> int16_t @-> uint32_t @-> int16_t @-> (ptr void) @-> (ptr int32_t) @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* ParameterNumber : WORD -> uint16_t *)
(* ValueType : SHORT -> int16_t *)
(* ParameterType : SHORT -> int16_t *)
(* LengthPrecision : DWORD -> uint32_t *)
(* ParameterScale : SHORT -> int16_t *)
(* ParameterValue : void* -> (ptr void) *)
(* StrLen_or_Ind : INT* 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 ("SQLSetParam" sqlset-param :convention :stdcall) :int16
  (statement-handle :pointer)   ; void* in/out
  (parameter-number :uint16)   ; WORD
  (value-type :int16)   ; SHORT
  (parameter-type :int16)   ; SHORT
  (length-precision :uint32)   ; DWORD
  (parameter-scale :int16)   ; SHORT
  (parameter-value :pointer)   ; void*
  (str-len-or-ind :pointer))   ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLSetParam = Win32::API::More->new('ODBC32',
    'short SQLSetParam(LPVOID StatementHandle, WORD ParameterNumber, short ValueType, short ParameterType, DWORD LengthPrecision, short ParameterScale, LPVOID ParameterValue, LPVOID StrLen_or_Ind)');
# my $ret = $SQLSetParam->Call($StatementHandle, $ParameterNumber, $ValueType, $ParameterType, $LengthPrecision, $ParameterScale, $ParameterValue, $StrLen_or_Ind);
# StatementHandle : void* in/out -> LPVOID
# ParameterNumber : WORD -> WORD
# ValueType : SHORT -> short
# ParameterType : SHORT -> short
# LengthPrecision : DWORD -> DWORD
# ParameterScale : SHORT -> short
# ParameterValue : void* -> LPVOID
# StrLen_or_Ind : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。