ホーム › System.Search › SQLDescribeParam
SQLDescribeParam
関数準備済みSQL文のパラメータの型情報を取得する。
シグネチャ
// ODBC32.dll
#include <windows.h>
SHORT SQLDescribeParam(
void* hstmt,
WORD ipar,
SHORT* pfSqlType, // optional
DWORD* pcbParamDef, // optional
SHORT* pibScale, // optional
SHORT* pfNullable // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hstmt | void* | inout | 対象のステートメントハンドル。準備済みSQL文のパラメータを記述する。 |
| ipar | WORD | in | 記述するパラメータ番号。1始まりで指定する。 |
| pfSqlType | SHORT* | outoptional | パラメータのSQLデータ型を受け取るポインタ。 |
| pcbParamDef | DWORD* | outoptional | 列のサイズ(精度)を受け取るポインタ。 |
| pibScale | SHORT* | outoptional | 小数点以下桁数(スケール)を受け取るポインタ。 |
| pfNullable | SHORT* | outoptional | NULL許容フラグを受け取るポインタ。SQL_NULLABLE等。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll
#include <windows.h>
SHORT SQLDescribeParam(
void* hstmt,
WORD ipar,
SHORT* pfSqlType, // optional
DWORD* pcbParamDef, // optional
SHORT* pibScale, // optional
SHORT* pfNullable // optional
);[DllImport("ODBC32.dll", ExactSpelling = true)]
static extern short SQLDescribeParam(
IntPtr hstmt, // void* in/out
ushort ipar, // WORD
IntPtr pfSqlType, // SHORT* optional, out
IntPtr pcbParamDef, // DWORD* optional, out
IntPtr pibScale, // SHORT* optional, out
IntPtr pfNullable // SHORT* optional, out
);<DllImport("ODBC32.dll", ExactSpelling:=True)>
Public Shared Function SQLDescribeParam(
hstmt As IntPtr, ' void* in/out
ipar As UShort, ' WORD
pfSqlType As IntPtr, ' SHORT* optional, out
pcbParamDef As IntPtr, ' DWORD* optional, out
pibScale As IntPtr, ' SHORT* optional, out
pfNullable As IntPtr ' SHORT* optional, out
) As Short
End Function' hstmt : void* in/out
' ipar : WORD
' pfSqlType : SHORT* optional, out
' pcbParamDef : DWORD* optional, out
' pibScale : SHORT* optional, out
' pfNullable : SHORT* optional, out
Declare PtrSafe Function SQLDescribeParam Lib "odbc32" ( _
ByVal hstmt As LongPtr, _
ByVal ipar As Integer, _
ByVal pfSqlType As LongPtr, _
ByVal pcbParamDef As LongPtr, _
ByVal pibScale As LongPtr, _
ByVal pfNullable As LongPtr) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLDescribeParam = ctypes.windll.odbc32.SQLDescribeParam
SQLDescribeParam.restype = ctypes.c_short
SQLDescribeParam.argtypes = [
ctypes.POINTER(None), # hstmt : void* in/out
ctypes.c_ushort, # ipar : WORD
ctypes.POINTER(ctypes.c_short), # pfSqlType : SHORT* optional, out
ctypes.POINTER(wintypes.DWORD), # pcbParamDef : DWORD* optional, out
ctypes.POINTER(ctypes.c_short), # pibScale : SHORT* optional, out
ctypes.POINTER(ctypes.c_short), # pfNullable : SHORT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLDescribeParam = Fiddle::Function.new(
lib['SQLDescribeParam'],
[
Fiddle::TYPE_VOIDP, # hstmt : void* in/out
-Fiddle::TYPE_SHORT, # ipar : WORD
Fiddle::TYPE_VOIDP, # pfSqlType : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pcbParamDef : DWORD* optional, out
Fiddle::TYPE_VOIDP, # pibScale : SHORT* optional, out
Fiddle::TYPE_VOIDP, # pfNullable : SHORT* optional, out
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLDescribeParam(
hstmt: *mut (), // void* in/out
ipar: u16, // WORD
pfSqlType: *mut i16, // SHORT* optional, out
pcbParamDef: *mut u32, // DWORD* optional, out
pibScale: *mut i16, // SHORT* optional, out
pfNullable: *mut i16 // SHORT* optional, out
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll")]
public static extern short SQLDescribeParam(IntPtr hstmt, ushort ipar, IntPtr pfSqlType, IntPtr pcbParamDef, IntPtr pibScale, IntPtr pfNullable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLDescribeParam' -Namespace Win32 -PassThru
# $api::SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable)#uselib "ODBC32.dll"
#func global SQLDescribeParam "SQLDescribeParam" sptr, sptr, sptr, sptr, sptr, sptr
; SQLDescribeParam hstmt, ipar, varptr(pfSqlType), varptr(pcbParamDef), varptr(pibScale), varptr(pfNullable) ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; ipar : WORD -> "sptr"
; pfSqlType : SHORT* optional, out -> "sptr"
; pcbParamDef : DWORD* optional, out -> "sptr"
; pibScale : SHORT* optional, out -> "sptr"
; pfNullable : SHORT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLDescribeParam "SQLDescribeParam" sptr, int, var, var, var, var ; res = SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable) ; hstmt : void* in/out -> "sptr" ; ipar : WORD -> "int" ; pfSqlType : SHORT* optional, out -> "var" ; pcbParamDef : DWORD* optional, out -> "var" ; pibScale : SHORT* optional, out -> "var" ; pfNullable : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLDescribeParam "SQLDescribeParam" sptr, int, sptr, sptr, sptr, sptr ; res = SQLDescribeParam(hstmt, ipar, varptr(pfSqlType), varptr(pcbParamDef), varptr(pibScale), varptr(pfNullable)) ; hstmt : void* in/out -> "sptr" ; ipar : WORD -> "int" ; pfSqlType : SHORT* optional, out -> "sptr" ; pcbParamDef : DWORD* optional, out -> "sptr" ; pibScale : SHORT* optional, out -> "sptr" ; pfNullable : SHORT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLDescribeParam(void* hstmt, WORD ipar, SHORT* pfSqlType, DWORD* pcbParamDef, SHORT* pibScale, SHORT* pfNullable) #uselib "ODBC32.dll" #cfunc global SQLDescribeParam "SQLDescribeParam" intptr, int, var, var, var, var ; res = SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable) ; hstmt : void* in/out -> "intptr" ; ipar : WORD -> "int" ; pfSqlType : SHORT* optional, out -> "var" ; pcbParamDef : DWORD* optional, out -> "var" ; pibScale : SHORT* optional, out -> "var" ; pfNullable : SHORT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLDescribeParam(void* hstmt, WORD ipar, SHORT* pfSqlType, DWORD* pcbParamDef, SHORT* pibScale, SHORT* pfNullable) #uselib "ODBC32.dll" #cfunc global SQLDescribeParam "SQLDescribeParam" intptr, int, intptr, intptr, intptr, intptr ; res = SQLDescribeParam(hstmt, ipar, varptr(pfSqlType), varptr(pcbParamDef), varptr(pibScale), varptr(pfNullable)) ; hstmt : void* in/out -> "intptr" ; ipar : WORD -> "int" ; pfSqlType : SHORT* optional, out -> "intptr" ; pcbParamDef : DWORD* optional, out -> "intptr" ; pibScale : SHORT* optional, out -> "intptr" ; pfNullable : SHORT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLDescribeParam = odbc32.NewProc("SQLDescribeParam")
)
// hstmt (void* in/out), ipar (WORD), pfSqlType (SHORT* optional, out), pcbParamDef (DWORD* optional, out), pibScale (SHORT* optional, out), pfNullable (SHORT* optional, out)
r1, _, err := procSQLDescribeParam.Call(
uintptr(hstmt),
uintptr(ipar),
uintptr(pfSqlType),
uintptr(pcbParamDef),
uintptr(pibScale),
uintptr(pfNullable),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLDescribeParam(
hstmt: Pointer; // void* in/out
ipar: Word; // WORD
pfSqlType: Pointer; // SHORT* optional, out
pcbParamDef: Pointer; // DWORD* optional, out
pibScale: Pointer; // SHORT* optional, out
pfNullable: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLDescribeParam';result := DllCall("ODBC32\SQLDescribeParam"
, "Ptr", hstmt ; void* in/out
, "UShort", ipar ; WORD
, "Ptr", pfSqlType ; SHORT* optional, out
, "Ptr", pcbParamDef ; DWORD* optional, out
, "Ptr", pibScale ; SHORT* optional, out
, "Ptr", pfNullable ; SHORT* optional, out
, "Short") ; return: SHORT●SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable) = DLL("ODBC32.dll", "int SQLDescribeParam(void*, int, void*, void*, void*, void*)")
# 呼び出し: SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable)
# hstmt : void* in/out -> "void*"
# ipar : WORD -> "int"
# pfSqlType : SHORT* optional, out -> "void*"
# pcbParamDef : DWORD* optional, out -> "void*"
# pibScale : SHORT* optional, out -> "void*"
# pfNullable : SHORT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLDescribeParam(
hstmt: ?*anyopaque, // void* in/out
ipar: u16, // WORD
pfSqlType: [*c]i16, // SHORT* optional, out
pcbParamDef: [*c]u32, // DWORD* optional, out
pibScale: [*c]i16, // SHORT* optional, out
pfNullable: [*c]i16 // SHORT* optional, out
) callconv(std.os.windows.WINAPI) i16;proc SQLDescribeParam(
hstmt: pointer, # void* in/out
ipar: uint16, # WORD
pfSqlType: ptr int16, # SHORT* optional, out
pcbParamDef: ptr uint32, # DWORD* optional, out
pibScale: ptr int16, # SHORT* optional, out
pfNullable: ptr int16 # SHORT* optional, out
): int16 {.importc: "SQLDescribeParam", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLDescribeParam(
void* hstmt, // void* in/out
ushort ipar, // WORD
short* pfSqlType, // SHORT* optional, out
uint* pcbParamDef, // DWORD* optional, out
short* pibScale, // SHORT* optional, out
short* pfNullable // SHORT* optional, out
);ccall((:SQLDescribeParam, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, UInt16, Ptr{Int16}, Ptr{UInt32}, Ptr{Int16}, Ptr{Int16}),
hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable)
# hstmt : void* in/out -> Ptr{Cvoid}
# ipar : WORD -> UInt16
# pfSqlType : SHORT* optional, out -> Ptr{Int16}
# pcbParamDef : DWORD* optional, out -> Ptr{UInt32}
# pibScale : SHORT* optional, out -> Ptr{Int16}
# pfNullable : SHORT* optional, out -> Ptr{Int16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLDescribeParam(
void* hstmt,
uint16_t ipar,
int16_t* pfSqlType,
uint32_t* pcbParamDef,
int16_t* pibScale,
int16_t* pfNullable);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable)
-- hstmt : void* in/out
-- ipar : WORD
-- pfSqlType : SHORT* optional, out
-- pcbParamDef : DWORD* optional, out
-- pibScale : SHORT* optional, out
-- pfNullable : SHORT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLDescribeParam = lib.func('__stdcall', 'SQLDescribeParam', 'int16_t', ['void *', 'uint16_t', 'int16_t *', 'uint32_t *', 'int16_t *', 'int16_t *']);
// SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable)
// hstmt : void* in/out -> 'void *'
// ipar : WORD -> 'uint16_t'
// pfSqlType : SHORT* optional, out -> 'int16_t *'
// pcbParamDef : DWORD* optional, out -> 'uint32_t *'
// pibScale : SHORT* optional, out -> 'int16_t *'
// pfNullable : SHORT* optional, out -> 'int16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLDescribeParam: { parameters: ["pointer", "u16", "pointer", "pointer", "pointer", "pointer"], result: "i16" },
});
// lib.symbols.SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable)
// hstmt : void* in/out -> "pointer"
// ipar : WORD -> "u16"
// pfSqlType : SHORT* optional, out -> "pointer"
// pcbParamDef : DWORD* optional, out -> "pointer"
// pibScale : SHORT* optional, out -> "pointer"
// pfNullable : SHORT* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLDescribeParam(
void* hstmt,
uint16_t ipar,
int16_t* pfSqlType,
uint32_t* pcbParamDef,
int16_t* pibScale,
int16_t* pfNullable);
C, "ODBC32.dll");
// $ffi->SQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable);
// hstmt : void* in/out
// ipar : WORD
// pfSqlType : SHORT* optional, out
// pcbParamDef : DWORD* optional, out
// pibScale : SHORT* optional, out
// pfNullable : SHORT* optional, 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 SQLDescribeParam(
Pointer hstmt, // void* in/out
short ipar, // WORD
ShortByReference pfSqlType, // SHORT* optional, out
IntByReference pcbParamDef, // DWORD* optional, out
ShortByReference pibScale, // SHORT* optional, out
ShortByReference pfNullable // SHORT* optional, out
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLDescribeParam = SQLDescribeParam(
hstmt : Void*, # void* in/out
ipar : UInt16, # WORD
pfSqlType : Int16*, # SHORT* optional, out
pcbParamDef : UInt32*, # DWORD* optional, out
pibScale : Int16*, # SHORT* optional, out
pfNullable : Int16* # SHORT* optional, out
) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SQLDescribeParamNative = Int16 Function(Pointer<Void>, Uint16, Pointer<Int16>, Pointer<Uint32>, Pointer<Int16>, Pointer<Int16>);
typedef SQLDescribeParamDart = int Function(Pointer<Void>, int, Pointer<Int16>, Pointer<Uint32>, Pointer<Int16>, Pointer<Int16>);
final SQLDescribeParam = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLDescribeParamNative, SQLDescribeParamDart>('SQLDescribeParam');
// hstmt : void* in/out -> Pointer<Void>
// ipar : WORD -> Uint16
// pfSqlType : SHORT* optional, out -> Pointer<Int16>
// pcbParamDef : DWORD* optional, out -> Pointer<Uint32>
// pibScale : SHORT* optional, out -> Pointer<Int16>
// pfNullable : SHORT* optional, out -> Pointer<Int16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLDescribeParam(
hstmt: Pointer; // void* in/out
ipar: Word; // WORD
pfSqlType: Pointer; // SHORT* optional, out
pcbParamDef: Pointer; // DWORD* optional, out
pibScale: Pointer; // SHORT* optional, out
pfNullable: Pointer // SHORT* optional, out
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLDescribeParam';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLDescribeParam"
c_SQLDescribeParam :: Ptr () -> Word16 -> Ptr Int16 -> Ptr Word32 -> Ptr Int16 -> Ptr Int16 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- ipar : WORD -> Word16
-- pfSqlType : SHORT* optional, out -> Ptr Int16
-- pcbParamDef : DWORD* optional, out -> Ptr Word32
-- pibScale : SHORT* optional, out -> Ptr Int16
-- pfNullable : SHORT* optional, out -> Ptr Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqldescribeparam =
foreign "SQLDescribeParam"
((ptr void) @-> uint16_t @-> (ptr int16_t) @-> (ptr uint32_t) @-> (ptr int16_t) @-> (ptr int16_t) @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* ipar : WORD -> uint16_t *)
(* pfSqlType : SHORT* optional, out -> (ptr int16_t) *)
(* pcbParamDef : DWORD* optional, out -> (ptr uint32_t) *)
(* pibScale : SHORT* optional, out -> (ptr int16_t) *)
(* pfNullable : SHORT* optional, out -> (ptr int16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)
(cffi:defcfun ("SQLDescribeParam" sqldescribe-param :convention :stdcall) :int16
(hstmt :pointer) ; void* in/out
(ipar :uint16) ; WORD
(pf-sql-type :pointer) ; SHORT* optional, out
(pcb-param-def :pointer) ; DWORD* optional, out
(pib-scale :pointer) ; SHORT* optional, out
(pf-nullable :pointer)) ; SHORT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLDescribeParam = Win32::API::More->new('ODBC32',
'short SQLDescribeParam(LPVOID hstmt, WORD ipar, LPVOID pfSqlType, LPVOID pcbParamDef, LPVOID pibScale, LPVOID pfNullable)');
# my $ret = $SQLDescribeParam->Call($hstmt, $ipar, $pfSqlType, $pcbParamDef, $pibScale, $pfNullable);
# hstmt : void* in/out -> LPVOID
# ipar : WORD -> WORD
# pfSqlType : SHORT* optional, out -> LPVOID
# pcbParamDef : DWORD* optional, out -> LPVOID
# pibScale : SHORT* optional, out -> LPVOID
# pfNullable : SHORT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。