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

SQLSetPos

関数
結果セット内のカーソル位置を設定し行を操作する。
DLLODBC32.dll呼出規約winapi

シグネチャ

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

SHORT SQLSetPos(
    void* hstmt,
    WORD irow,
    WORD fOption,
    WORD fLock
);

パラメーター

名前方向説明
hstmtvoid*inout対象のステートメントハンドル。行セット内のカーソル位置を操作する。
irowWORDin操作対象の行セット内の行位置。0で全行を対象とする。
fOptionWORDin実行する操作。SQL_POSITION/SQL_REFRESH/SQL_UPDATE/SQL_DELETE。
fLockWORDinロック方法。SQL_LOCK_NO_CHANGE/EXCLUSIVE/UNLOCKを指定する。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLSetPos(
    void* hstmt,
    WORD irow,
    WORD fOption,
    WORD fLock
);
[DllImport("ODBC32.dll", ExactSpelling = true)]
static extern short SQLSetPos(
    IntPtr hstmt,   // void* in/out
    ushort irow,   // WORD
    ushort fOption,   // WORD
    ushort fLock   // WORD
);
<DllImport("ODBC32.dll", ExactSpelling:=True)>
Public Shared Function SQLSetPos(
    hstmt As IntPtr,   ' void* in/out
    irow As UShort,   ' WORD
    fOption As UShort,   ' WORD
    fLock As UShort   ' WORD
) As Short
End Function
' hstmt : void* in/out
' irow : WORD
' fOption : WORD
' fLock : WORD
Declare PtrSafe Function SQLSetPos Lib "odbc32" ( _
    ByVal hstmt As LongPtr, _
    ByVal irow As Integer, _
    ByVal fOption As Integer, _
    ByVal fLock As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLSetPos = ctypes.windll.odbc32.SQLSetPos
SQLSetPos.restype = ctypes.c_short
SQLSetPos.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.c_ushort,  # irow : WORD
    ctypes.c_ushort,  # fOption : WORD
    ctypes.c_ushort,  # fLock : WORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLSetPos = Fiddle::Function.new(
  lib['SQLSetPos'],
  [
    Fiddle::TYPE_VOIDP,  # hstmt : void* in/out
    -Fiddle::TYPE_SHORT,  # irow : WORD
    -Fiddle::TYPE_SHORT,  # fOption : WORD
    -Fiddle::TYPE_SHORT,  # fLock : WORD
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLSetPos(
        hstmt: *mut (),  // void* in/out
        irow: u16,  // WORD
        fOption: u16,  // WORD
        fLock: u16  // WORD
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll")]
public static extern short SQLSetPos(IntPtr hstmt, ushort irow, ushort fOption, ushort fLock);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLSetPos' -Namespace Win32 -PassThru
# $api::SQLSetPos(hstmt, irow, fOption, fLock)
#uselib "ODBC32.dll"
#func global SQLSetPos "SQLSetPos" sptr, sptr, sptr, sptr
; SQLSetPos hstmt, irow, fOption, fLock   ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; irow : WORD -> "sptr"
; fOption : WORD -> "sptr"
; fLock : WORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ODBC32.dll"
#cfunc global SQLSetPos "SQLSetPos" sptr, int, int, int
; res = SQLSetPos(hstmt, irow, fOption, fLock)
; hstmt : void* in/out -> "sptr"
; irow : WORD -> "int"
; fOption : WORD -> "int"
; fLock : WORD -> "int"
; SHORT SQLSetPos(void* hstmt, WORD irow, WORD fOption, WORD fLock)
#uselib "ODBC32.dll"
#cfunc global SQLSetPos "SQLSetPos" intptr, int, int, int
; res = SQLSetPos(hstmt, irow, fOption, fLock)
; hstmt : void* in/out -> "intptr"
; irow : WORD -> "int"
; fOption : WORD -> "int"
; fLock : WORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLSetPos = odbc32.NewProc("SQLSetPos")
)

// hstmt (void* in/out), irow (WORD), fOption (WORD), fLock (WORD)
r1, _, err := procSQLSetPos.Call(
	uintptr(hstmt),
	uintptr(irow),
	uintptr(fOption),
	uintptr(fLock),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLSetPos(
  hstmt: Pointer;   // void* in/out
  irow: Word;   // WORD
  fOption: Word;   // WORD
  fLock: Word   // WORD
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLSetPos';
result := DllCall("ODBC32\SQLSetPos"
    , "Ptr", hstmt   ; void* in/out
    , "UShort", irow   ; WORD
    , "UShort", fOption   ; WORD
    , "UShort", fLock   ; WORD
    , "Short")   ; return: SHORT
●SQLSetPos(hstmt, irow, fOption, fLock) = DLL("ODBC32.dll", "int SQLSetPos(void*, int, int, int)")
# 呼び出し: SQLSetPos(hstmt, irow, fOption, fLock)
# hstmt : void* in/out -> "void*"
# irow : WORD -> "int"
# fOption : WORD -> "int"
# fLock : WORD -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLSetPos(
    hstmt: ?*anyopaque, // void* in/out
    irow: u16, // WORD
    fOption: u16, // WORD
    fLock: u16 // WORD
) callconv(std.os.windows.WINAPI) i16;
proc SQLSetPos(
    hstmt: pointer,  # void* in/out
    irow: uint16,  # WORD
    fOption: uint16,  # WORD
    fLock: uint16  # WORD
): int16 {.importc: "SQLSetPos", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLSetPos(
    void* hstmt,   // void* in/out
    ushort irow,   // WORD
    ushort fOption,   // WORD
    ushort fLock   // WORD
);
ccall((:SQLSetPos, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, UInt16, UInt16, UInt16),
      hstmt, irow, fOption, fLock)
# hstmt : void* in/out -> Ptr{Cvoid}
# irow : WORD -> UInt16
# fOption : WORD -> UInt16
# fLock : WORD -> UInt16
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLSetPos(
    void* hstmt,
    uint16_t irow,
    uint16_t fOption,
    uint16_t fLock);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLSetPos(hstmt, irow, fOption, fLock)
-- hstmt : void* in/out
-- irow : WORD
-- fOption : WORD
-- fLock : WORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLSetPos = lib.func('__stdcall', 'SQLSetPos', 'int16_t', ['void *', 'uint16_t', 'uint16_t', 'uint16_t']);
// SQLSetPos(hstmt, irow, fOption, fLock)
// hstmt : void* in/out -> 'void *'
// irow : WORD -> 'uint16_t'
// fOption : WORD -> 'uint16_t'
// fLock : WORD -> 'uint16_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLSetPos: { parameters: ["pointer", "u16", "u16", "u16"], result: "i16" },
});
// lib.symbols.SQLSetPos(hstmt, irow, fOption, fLock)
// hstmt : void* in/out -> "pointer"
// irow : WORD -> "u16"
// fOption : WORD -> "u16"
// fLock : WORD -> "u16"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLSetPos(
    void* hstmt,
    uint16_t irow,
    uint16_t fOption,
    uint16_t fLock);
C, "ODBC32.dll");
// $ffi->SQLSetPos(hstmt, irow, fOption, fLock);
// hstmt : void* in/out
// irow : WORD
// fOption : WORD
// fLock : WORD
// 構造体/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 SQLSetPos(
        Pointer hstmt,   // void* in/out
        short irow,   // WORD
        short fOption,   // WORD
        short fLock   // WORD
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLSetPos = SQLSetPos(
    hstmt : Void*,   # void* in/out
    irow : UInt16,   # WORD
    fOption : UInt16,   # WORD
    fLock : UInt16   # WORD
  ) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SQLSetPosNative = Int16 Function(Pointer<Void>, Uint16, Uint16, Uint16);
typedef SQLSetPosDart = int Function(Pointer<Void>, int, int, int);
final SQLSetPos = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLSetPosNative, SQLSetPosDart>('SQLSetPos');
// hstmt : void* in/out -> Pointer<Void>
// irow : WORD -> Uint16
// fOption : WORD -> Uint16
// fLock : WORD -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLSetPos(
  hstmt: Pointer;   // void* in/out
  irow: Word;   // WORD
  fOption: Word;   // WORD
  fLock: Word   // WORD
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLSetPos';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLSetPos"
  c_SQLSetPos :: Ptr () -> Word16 -> Word16 -> Word16 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- irow : WORD -> Word16
-- fOption : WORD -> Word16
-- fLock : WORD -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlsetpos =
  foreign "SQLSetPos"
    ((ptr void) @-> uint16_t @-> uint16_t @-> uint16_t @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* irow : WORD -> uint16_t *)
(* fOption : WORD -> uint16_t *)
(* fLock : WORD -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLSetPos" sqlset-pos :convention :stdcall) :int16
  (hstmt :pointer)   ; void* in/out
  (irow :uint16)   ; WORD
  (f-option :uint16)   ; WORD
  (f-lock :uint16))   ; WORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLSetPos = Win32::API::More->new('ODBC32',
    'short SQLSetPos(LPVOID hstmt, WORD irow, WORD fOption, WORD fLock)');
# my $ret = $SQLSetPos->Call($hstmt, $irow, $fOption, $fLock);
# hstmt : void* in/out -> LPVOID
# irow : WORD -> WORD
# fOption : WORD -> WORD
# fLock : WORD -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。