SQLSetDescField
関数シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLSetDescField(
void* DescriptorHandle,
SHORT RecNumber,
SHORT FieldIdentifier,
void* Value,
INT BufferLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DescriptorHandle | void* | inout | [入力] 記述子ハンドル。 |
| RecNumber | SHORT | in | [入力] アプリケーションが設定しようとしているフィールドを含む記述子レコードを示します。記述子レコードは 0 から番号が付けられ、レコード番号 0 がブックマークレコードです。ヘッダーフィールドの場合、RecNumber 引数は無視されます。 |
| FieldIdentifier | SHORT | in | [入力] 値を設定する記述子のフィールドを示します。詳細については、「解説」セクションの「FieldIdentifier 引数」を参照してください。 |
| Value | void* | in | 設定する値。整数または文字列バッファへのポインタ。 |
| BufferLength | INT | in | [入力] FieldIdentifier が ODBC 定義のフィールドであり、ValuePtr が文字列またはバイナリバッファーを指す場合、この引数は *ValuePtr の長さにする必要があります。文字列データの場合、この引数には文字列のバイト数を格納する必要があります。 FieldIdentifier が ODBC 定義のフィールドであり、ValuePtr が整数の場合、BufferLength は無視されます。 FieldIdentifier がドライバー定義のフィールドの場合、アプリケーションは BufferLength 引数を設定することで、そのフィールドの性質をドライバーマネージャーに示します。BufferLength には次の値を指定できます。
|
戻り値の型: SHORT
公式ドキュメント
SQLSetDescField は、記述子レコードの単一のフィールドの値を設定します。
戻り値
解説(Remarks)
アプリケーションは SQLSetDescField を呼び出して、任意の記述子フィールドを一度に 1 つずつ設定できます。SQLSetDescField の 1 回の呼び出しで、1 つの記述子内の 1 つのフィールドが設定されます。この関数は、フィールドが設定可能である限り、任意の記述子型の任意のフィールドを設定するために呼び出せます (このセクションの後半にある表を参照してください)。
SQLSetDescField の呼び出しが失敗した場合、RecNumber 引数で識別される記述子レコードの内容は未定義になります。
1 回の関数呼び出しで複数の記述子フィールドを設定するために、他の関数を呼び出すこともできます。SQLSetDescRec 関数は、列またはパラメーターにバインドされたデータ型とバッファーに影響するさまざまなフィールド (SQL_DESC_TYPE、SQL_DESC_DATETIME_INTERVAL_CODE、SQL_DESC_OCTET_LENGTH、SQL_DESC_PRECISION、SQL_DESC_SCALE、SQL_DESC_DATA_PTR、SQL_DESC_OCTET_LENGTH_PTR、および SQL_DESC_INDICATOR_PTR の各フィールド) を設定します。SQLBindCol または SQLBindParameter を使用すると、列またはパラメーターのバインドに関する完全な指定を行えます。これらの関数は、1 回の関数呼び出しで特定のグループの記述子フィールドを設定します。
SQLSetDescField を呼び出し、バインドポインター (SQL_DESC_DATA_PTR、SQL_DESC_INDICATOR_PTR、または SQL_DESC_OCTET_LENGTH_PTR) にオフセットを加算することで、バインドバッファーを変更できます。これにより、SQLBindCol や SQLBindParameter を呼び出さずにバインドバッファーを変更できるため、アプリケーションは SQL_DESC_DATA_TYPE などの他のフィールドを変更せずに SQL_DESC_DATA_PTR を変更できます。
アプリケーションが SQLSetDescField を呼び出して、SQL_DESC_COUNT および遅延フィールドである SQL_DESC_DATA_PTR、SQL_DESC_OCTET_LENGTH_PTR、SQL_DESC_INDICATOR_PTR 以外のフィールドを設定すると、そのレコードはバインドされていない状態になります。
記述子ヘッダーフィールドは、適切な FieldIdentifier を指定して SQLSetDescField を呼び出すことで設定します。多くのヘッダーフィールドはステートメント属性でもあるため、SQLSetStmtAttr の呼び出しによって設定することもできます。これにより、アプリケーションは最初に記述子ハンドルを取得しなくても記述子フィールドを設定できます。ヘッダーフィールドを設定するために SQLSetDescField を呼び出した場合、RecNumber 引数は無視されます。
RecNumber に 0 を指定すると、ブックマークフィールドが設定されます。
ブックマークフィールドを設定するために SQLSetDescField を呼び出す前に、ステートメント属性 SQL_ATTR_USE_BOOKMARKS を常に設定しておく必要があります。これは必須ではありませんが、強く推奨されます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp)
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLSetDescField(
void* DescriptorHandle,
SHORT RecNumber,
SHORT FieldIdentifier,
void* Value,
INT BufferLength
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLSetDescField(
IntPtr DescriptorHandle, // void* in/out
short RecNumber, // SHORT
short FieldIdentifier, // SHORT
IntPtr Value, // void*
int BufferLength // INT
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLSetDescField(
DescriptorHandle As IntPtr, ' void* in/out
RecNumber As Short, ' SHORT
FieldIdentifier As Short, ' SHORT
Value As IntPtr, ' void*
BufferLength As Integer ' INT
) As Short
End Function' DescriptorHandle : void* in/out
' RecNumber : SHORT
' FieldIdentifier : SHORT
' Value : void*
' BufferLength : INT
Declare PtrSafe Function SQLSetDescField Lib "odbc32" ( _
ByVal DescriptorHandle As LongPtr, _
ByVal RecNumber As Integer, _
ByVal FieldIdentifier As Integer, _
ByVal Value As LongPtr, _
ByVal BufferLength As Long) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLSetDescField = ctypes.windll.odbc32.SQLSetDescField
SQLSetDescField.restype = ctypes.c_short
SQLSetDescField.argtypes = [
ctypes.POINTER(None), # DescriptorHandle : void* in/out
ctypes.c_short, # RecNumber : SHORT
ctypes.c_short, # FieldIdentifier : SHORT
ctypes.POINTER(None), # Value : void*
ctypes.c_int, # BufferLength : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLSetDescField = Fiddle::Function.new(
lib['SQLSetDescField'],
[
Fiddle::TYPE_VOIDP, # DescriptorHandle : void* in/out
Fiddle::TYPE_SHORT, # RecNumber : SHORT
Fiddle::TYPE_SHORT, # FieldIdentifier : SHORT
Fiddle::TYPE_VOIDP, # Value : void*
Fiddle::TYPE_INT, # BufferLength : INT
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLSetDescField(
DescriptorHandle: *mut (), // void* in/out
RecNumber: i16, // SHORT
FieldIdentifier: i16, // SHORT
Value: *mut (), // void*
BufferLength: i32 // INT
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLSetDescField(IntPtr DescriptorHandle, short RecNumber, short FieldIdentifier, IntPtr Value, int BufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLSetDescField' -Namespace Win32 -PassThru
# $api::SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)#uselib "ODBC32.dll"
#func global SQLSetDescField "SQLSetDescField" sptr, sptr, sptr, sptr, sptr
; SQLSetDescField DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength ; 戻り値は stat
; DescriptorHandle : void* in/out -> "sptr"
; RecNumber : SHORT -> "sptr"
; FieldIdentifier : SHORT -> "sptr"
; Value : void* -> "sptr"
; BufferLength : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ODBC32.dll"
#cfunc global SQLSetDescField "SQLSetDescField" sptr, int, int, sptr, int
; res = SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
; DescriptorHandle : void* in/out -> "sptr"
; RecNumber : SHORT -> "int"
; FieldIdentifier : SHORT -> "int"
; Value : void* -> "sptr"
; BufferLength : INT -> "int"; SHORT SQLSetDescField(void* DescriptorHandle, SHORT RecNumber, SHORT FieldIdentifier, void* Value, INT BufferLength)
#uselib "ODBC32.dll"
#cfunc global SQLSetDescField "SQLSetDescField" intptr, int, int, intptr, int
; res = SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
; DescriptorHandle : void* in/out -> "intptr"
; RecNumber : SHORT -> "int"
; FieldIdentifier : SHORT -> "int"
; Value : void* -> "intptr"
; BufferLength : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLSetDescField = odbc32.NewProc("SQLSetDescField")
)
// DescriptorHandle (void* in/out), RecNumber (SHORT), FieldIdentifier (SHORT), Value (void*), BufferLength (INT)
r1, _, err := procSQLSetDescField.Call(
uintptr(DescriptorHandle),
uintptr(RecNumber),
uintptr(FieldIdentifier),
uintptr(Value),
uintptr(BufferLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLSetDescField(
DescriptorHandle: Pointer; // void* in/out
RecNumber: Smallint; // SHORT
FieldIdentifier: Smallint; // SHORT
Value: Pointer; // void*
BufferLength: Integer // INT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLSetDescField';result := DllCall("ODBC32\SQLSetDescField"
, "Ptr", DescriptorHandle ; void* in/out
, "Short", RecNumber ; SHORT
, "Short", FieldIdentifier ; SHORT
, "Ptr", Value ; void*
, "Int", BufferLength ; INT
, "Short") ; return: SHORT●SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength) = DLL("ODBC32.dll", "int SQLSetDescField(void*, int, int, void*, int)")
# 呼び出し: SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
# DescriptorHandle : void* in/out -> "void*"
# RecNumber : SHORT -> "int"
# FieldIdentifier : SHORT -> "int"
# Value : void* -> "void*"
# BufferLength : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLSetDescField(
DescriptorHandle: ?*anyopaque, // void* in/out
RecNumber: i16, // SHORT
FieldIdentifier: i16, // SHORT
Value: ?*anyopaque, // void*
BufferLength: i32 // INT
) callconv(std.os.windows.WINAPI) i16;proc SQLSetDescField(
DescriptorHandle: pointer, # void* in/out
RecNumber: int16, # SHORT
FieldIdentifier: int16, # SHORT
Value: pointer, # void*
BufferLength: int32 # INT
): int16 {.importc: "SQLSetDescField", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLSetDescField(
void* DescriptorHandle, // void* in/out
short RecNumber, // SHORT
short FieldIdentifier, // SHORT
void* Value, // void*
int BufferLength // INT
);ccall((:SQLSetDescField, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Int16, Int16, Ptr{Cvoid}, Int32),
DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
# DescriptorHandle : void* in/out -> Ptr{Cvoid}
# RecNumber : SHORT -> Int16
# FieldIdentifier : SHORT -> Int16
# Value : void* -> Ptr{Cvoid}
# BufferLength : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLSetDescField(
void* DescriptorHandle,
int16_t RecNumber,
int16_t FieldIdentifier,
void* Value,
int32_t BufferLength);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
-- DescriptorHandle : void* in/out
-- RecNumber : SHORT
-- FieldIdentifier : SHORT
-- Value : void*
-- BufferLength : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLSetDescField = lib.func('__stdcall', 'SQLSetDescField', 'int16_t', ['void *', 'int16_t', 'int16_t', 'void *', 'int32_t']);
// SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
// DescriptorHandle : void* in/out -> 'void *'
// RecNumber : SHORT -> 'int16_t'
// FieldIdentifier : SHORT -> 'int16_t'
// Value : void* -> 'void *'
// BufferLength : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLSetDescField: { parameters: ["pointer", "i16", "i16", "pointer", "i32"], result: "i16" },
});
// lib.symbols.SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength)
// DescriptorHandle : void* in/out -> "pointer"
// RecNumber : SHORT -> "i16"
// FieldIdentifier : SHORT -> "i16"
// Value : void* -> "pointer"
// BufferLength : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLSetDescField(
void* DescriptorHandle,
int16_t RecNumber,
int16_t FieldIdentifier,
void* Value,
int32_t BufferLength);
C, "ODBC32.dll");
// $ffi->SQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength);
// DescriptorHandle : void* in/out
// RecNumber : SHORT
// FieldIdentifier : SHORT
// Value : void*
// BufferLength : INT
// 構造体/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, W32APIOptions.ASCII_OPTIONS);
short SQLSetDescField(
Pointer DescriptorHandle, // void* in/out
short RecNumber, // SHORT
short FieldIdentifier, // SHORT
Pointer Value, // void*
int BufferLength // INT
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLSetDescField = SQLSetDescField(
DescriptorHandle : Void*, # void* in/out
RecNumber : Int16, # SHORT
FieldIdentifier : Int16, # SHORT
Value : Void*, # void*
BufferLength : Int32 # INT
) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SQLSetDescFieldNative = Int16 Function(Pointer<Void>, Int16, Int16, Pointer<Void>, Int32);
typedef SQLSetDescFieldDart = int Function(Pointer<Void>, int, int, Pointer<Void>, int);
final SQLSetDescField = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLSetDescFieldNative, SQLSetDescFieldDart>('SQLSetDescField');
// DescriptorHandle : void* in/out -> Pointer<Void>
// RecNumber : SHORT -> Int16
// FieldIdentifier : SHORT -> Int16
// Value : void* -> Pointer<Void>
// BufferLength : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLSetDescField(
DescriptorHandle: Pointer; // void* in/out
RecNumber: Smallint; // SHORT
FieldIdentifier: Smallint; // SHORT
Value: Pointer; // void*
BufferLength: Integer // INT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLSetDescField';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLSetDescField"
c_SQLSetDescField :: Ptr () -> Int16 -> Int16 -> Ptr () -> Int32 -> IO Int16
-- DescriptorHandle : void* in/out -> Ptr ()
-- RecNumber : SHORT -> Int16
-- FieldIdentifier : SHORT -> Int16
-- Value : void* -> Ptr ()
-- BufferLength : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlsetdescfield =
foreign "SQLSetDescField"
((ptr void) @-> int16_t @-> int16_t @-> (ptr void) @-> int32_t @-> returning int16_t)
(* DescriptorHandle : void* in/out -> (ptr void) *)
(* RecNumber : SHORT -> int16_t *)
(* FieldIdentifier : SHORT -> int16_t *)
(* Value : void* -> (ptr void) *)
(* BufferLength : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)
(cffi:defcfun ("SQLSetDescField" sqlset-desc-field :convention :stdcall) :int16
(descriptor-handle :pointer) ; void* in/out
(rec-number :int16) ; SHORT
(field-identifier :int16) ; SHORT
(value :pointer) ; void*
(buffer-length :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLSetDescField = Win32::API::More->new('ODBC32',
'short SQLSetDescField(LPVOID DescriptorHandle, short RecNumber, short FieldIdentifier, LPVOID Value, int BufferLength)');
# my $ret = $SQLSetDescField->Call($DescriptorHandle, $RecNumber, $FieldIdentifier, $Value, $BufferLength);
# DescriptorHandle : void* in/out -> LPVOID
# RecNumber : SHORT -> short
# FieldIdentifier : SHORT -> short
# Value : void* -> LPVOID
# BufferLength : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f SQLSetDescFieldW (Unicode版) — 記述子レコードの指定フィールドに値を設定する(Unicode)。