ホーム › System.Search › SQLBindParameter
SQLBindParameter
関数SQL文のパラメータに変数とデータ型を結び付ける。
シグネチャ
// ODBC32.dll
#include <windows.h>
SHORT SQLBindParameter(
void* hstmt,
WORD ipar,
SHORT fParamType,
SHORT fCType,
SHORT fSqlType,
DWORD cbColDef,
SHORT ibScale,
void* rgbValue,
INT cbValueMax,
INT* pcbValue
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hstmt | void* | inout |
| ipar | WORD | in |
| fParamType | SHORT | in |
| fCType | SHORT | in |
| fSqlType | SHORT | in |
| cbColDef | DWORD | in |
| ibScale | SHORT | in |
| rgbValue | void* | inout |
| cbValueMax | INT | in |
| pcbValue | INT* | inout |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll
#include <windows.h>
SHORT SQLBindParameter(
void* hstmt,
WORD ipar,
SHORT fParamType,
SHORT fCType,
SHORT fSqlType,
DWORD cbColDef,
SHORT ibScale,
void* rgbValue,
INT cbValueMax,
INT* pcbValue
);[DllImport("ODBC32.dll", ExactSpelling = true)]
static extern short SQLBindParameter(
IntPtr hstmt, // void* in/out
ushort ipar, // WORD
short fParamType, // SHORT
short fCType, // SHORT
short fSqlType, // SHORT
uint cbColDef, // DWORD
short ibScale, // SHORT
IntPtr rgbValue, // void* in/out
int cbValueMax, // INT
ref int pcbValue // INT* in/out
);<DllImport("ODBC32.dll", ExactSpelling:=True)>
Public Shared Function SQLBindParameter(
hstmt As IntPtr, ' void* in/out
ipar As UShort, ' WORD
fParamType As Short, ' SHORT
fCType As Short, ' SHORT
fSqlType As Short, ' SHORT
cbColDef As UInteger, ' DWORD
ibScale As Short, ' SHORT
rgbValue As IntPtr, ' void* in/out
cbValueMax As Integer, ' INT
ByRef pcbValue As Integer ' INT* in/out
) As Short
End Function' hstmt : void* in/out
' ipar : WORD
' fParamType : SHORT
' fCType : SHORT
' fSqlType : SHORT
' cbColDef : DWORD
' ibScale : SHORT
' rgbValue : void* in/out
' cbValueMax : INT
' pcbValue : INT* in/out
Declare PtrSafe Function SQLBindParameter Lib "odbc32" ( _
ByVal hstmt As LongPtr, _
ByVal ipar As Integer, _
ByVal fParamType As Integer, _
ByVal fCType As Integer, _
ByVal fSqlType As Integer, _
ByVal cbColDef As Long, _
ByVal ibScale As Integer, _
ByVal rgbValue As LongPtr, _
ByVal cbValueMax As Long, _
ByRef pcbValue As Long) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLBindParameter = ctypes.windll.odbc32.SQLBindParameter
SQLBindParameter.restype = ctypes.c_short
SQLBindParameter.argtypes = [
ctypes.POINTER(None), # hstmt : void* in/out
ctypes.c_ushort, # ipar : WORD
ctypes.c_short, # fParamType : SHORT
ctypes.c_short, # fCType : SHORT
ctypes.c_short, # fSqlType : SHORT
wintypes.DWORD, # cbColDef : DWORD
ctypes.c_short, # ibScale : SHORT
ctypes.POINTER(None), # rgbValue : void* in/out
ctypes.c_int, # cbValueMax : INT
ctypes.POINTER(ctypes.c_int), # pcbValue : INT* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLBindParameter = Fiddle::Function.new(
lib['SQLBindParameter'],
[
Fiddle::TYPE_VOIDP, # hstmt : void* in/out
-Fiddle::TYPE_SHORT, # ipar : WORD
Fiddle::TYPE_SHORT, # fParamType : SHORT
Fiddle::TYPE_SHORT, # fCType : SHORT
Fiddle::TYPE_SHORT, # fSqlType : SHORT
-Fiddle::TYPE_INT, # cbColDef : DWORD
Fiddle::TYPE_SHORT, # ibScale : SHORT
Fiddle::TYPE_VOIDP, # rgbValue : void* in/out
Fiddle::TYPE_INT, # cbValueMax : INT
Fiddle::TYPE_VOIDP, # pcbValue : INT* in/out
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLBindParameter(
hstmt: *mut (), // void* in/out
ipar: u16, // WORD
fParamType: i16, // SHORT
fCType: i16, // SHORT
fSqlType: i16, // SHORT
cbColDef: u32, // DWORD
ibScale: i16, // SHORT
rgbValue: *mut (), // void* in/out
cbValueMax: i32, // INT
pcbValue: *mut i32 // INT* in/out
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll")]
public static extern short SQLBindParameter(IntPtr hstmt, ushort ipar, short fParamType, short fCType, short fSqlType, uint cbColDef, short ibScale, IntPtr rgbValue, int cbValueMax, ref int pcbValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLBindParameter' -Namespace Win32 -PassThru
# $api::SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue)#uselib "ODBC32.dll"
#func global SQLBindParameter "SQLBindParameter" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLBindParameter hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, varptr(pcbValue) ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; ipar : WORD -> "sptr"
; fParamType : SHORT -> "sptr"
; fCType : SHORT -> "sptr"
; fSqlType : SHORT -> "sptr"
; cbColDef : DWORD -> "sptr"
; ibScale : SHORT -> "sptr"
; rgbValue : void* in/out -> "sptr"
; cbValueMax : INT -> "sptr"
; pcbValue : INT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLBindParameter "SQLBindParameter" sptr, int, int, int, int, int, int, sptr, int, var ; res = SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue) ; hstmt : void* in/out -> "sptr" ; ipar : WORD -> "int" ; fParamType : SHORT -> "int" ; fCType : SHORT -> "int" ; fSqlType : SHORT -> "int" ; cbColDef : DWORD -> "int" ; ibScale : SHORT -> "int" ; rgbValue : void* in/out -> "sptr" ; cbValueMax : INT -> "int" ; pcbValue : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLBindParameter "SQLBindParameter" sptr, int, int, int, int, int, int, sptr, int, sptr ; res = SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, varptr(pcbValue)) ; hstmt : void* in/out -> "sptr" ; ipar : WORD -> "int" ; fParamType : SHORT -> "int" ; fCType : SHORT -> "int" ; fSqlType : SHORT -> "int" ; cbColDef : DWORD -> "int" ; ibScale : SHORT -> "int" ; rgbValue : void* in/out -> "sptr" ; cbValueMax : INT -> "int" ; pcbValue : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLBindParameter(void* hstmt, WORD ipar, SHORT fParamType, SHORT fCType, SHORT fSqlType, DWORD cbColDef, SHORT ibScale, void* rgbValue, INT cbValueMax, INT* pcbValue) #uselib "ODBC32.dll" #cfunc global SQLBindParameter "SQLBindParameter" intptr, int, int, int, int, int, int, intptr, int, var ; res = SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue) ; hstmt : void* in/out -> "intptr" ; ipar : WORD -> "int" ; fParamType : SHORT -> "int" ; fCType : SHORT -> "int" ; fSqlType : SHORT -> "int" ; cbColDef : DWORD -> "int" ; ibScale : SHORT -> "int" ; rgbValue : void* in/out -> "intptr" ; cbValueMax : INT -> "int" ; pcbValue : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLBindParameter(void* hstmt, WORD ipar, SHORT fParamType, SHORT fCType, SHORT fSqlType, DWORD cbColDef, SHORT ibScale, void* rgbValue, INT cbValueMax, INT* pcbValue) #uselib "ODBC32.dll" #cfunc global SQLBindParameter "SQLBindParameter" intptr, int, int, int, int, int, int, intptr, int, intptr ; res = SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, varptr(pcbValue)) ; hstmt : void* in/out -> "intptr" ; ipar : WORD -> "int" ; fParamType : SHORT -> "int" ; fCType : SHORT -> "int" ; fSqlType : SHORT -> "int" ; cbColDef : DWORD -> "int" ; ibScale : SHORT -> "int" ; rgbValue : void* in/out -> "intptr" ; cbValueMax : INT -> "int" ; pcbValue : INT* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLBindParameter = odbc32.NewProc("SQLBindParameter")
)
// hstmt (void* in/out), ipar (WORD), fParamType (SHORT), fCType (SHORT), fSqlType (SHORT), cbColDef (DWORD), ibScale (SHORT), rgbValue (void* in/out), cbValueMax (INT), pcbValue (INT* in/out)
r1, _, err := procSQLBindParameter.Call(
uintptr(hstmt),
uintptr(ipar),
uintptr(fParamType),
uintptr(fCType),
uintptr(fSqlType),
uintptr(cbColDef),
uintptr(ibScale),
uintptr(rgbValue),
uintptr(cbValueMax),
uintptr(pcbValue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLBindParameter(
hstmt: Pointer; // void* in/out
ipar: Word; // WORD
fParamType: Smallint; // SHORT
fCType: Smallint; // SHORT
fSqlType: Smallint; // SHORT
cbColDef: DWORD; // DWORD
ibScale: Smallint; // SHORT
rgbValue: Pointer; // void* in/out
cbValueMax: Integer; // INT
pcbValue: Pointer // INT* in/out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLBindParameter';result := DllCall("ODBC32\SQLBindParameter"
, "Ptr", hstmt ; void* in/out
, "UShort", ipar ; WORD
, "Short", fParamType ; SHORT
, "Short", fCType ; SHORT
, "Short", fSqlType ; SHORT
, "UInt", cbColDef ; DWORD
, "Short", ibScale ; SHORT
, "Ptr", rgbValue ; void* in/out
, "Int", cbValueMax ; INT
, "Ptr", pcbValue ; INT* in/out
, "Short") ; return: SHORT●SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue) = DLL("ODBC32.dll", "int SQLBindParameter(void*, int, int, int, int, dword, int, void*, int, void*)")
# 呼び出し: SQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue)
# hstmt : void* in/out -> "void*"
# ipar : WORD -> "int"
# fParamType : SHORT -> "int"
# fCType : SHORT -> "int"
# fSqlType : SHORT -> "int"
# cbColDef : DWORD -> "dword"
# ibScale : SHORT -> "int"
# rgbValue : void* in/out -> "void*"
# cbValueMax : INT -> "int"
# pcbValue : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。