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

SQLSetCursorName

関数
ステートメントにカーソル名を設定する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

SHORT SQLSetCursorName(
    void* StatementHandle,
    BYTE* CursorName,
    SHORT NameLength
);

パラメーター

名前型方向説明
StatementHandlevoid*inout[入力] ステートメント ハンドル。
CursorNameBYTE*in[入力] カーソル名。効率的に処理するため、カーソル名の先頭および末尾にスペースを含めないようにし、カーソル名に区切り識別子が含まれる場合は、区切り文字をカーソル名の先頭の文字に配置してください。
NameLengthSHORTin[入力] *CursorName の文字数単位の長さ。

戻り値の型: SHORT

公式ドキュメント

SQLSetCursorName は、カーソル名をアクティブなステートメントに関連付けます。アプリケーションが SQLSetCursorName を呼び出さない場合、ドライバーは SQL ステートメントの処理に必要なカーソル名を生成します。

戻り値

SQL_SUCCESS、SQL_SUCCESS_WITH_INFO、SQL_ERROR、または SQL_INVALID_HANDLE。

解説(Remarks)

カーソル名は、位置指定の更新ステートメントおよび削除ステートメントでのみ使用されます (例: UPDATE table-name ...WHERE CURRENT OF cursor-name)。詳細については、Positioned Update and Delete Statements を参照してください。アプリケーションが SQLSetCursorName を呼び出してカーソル名を定義しない場合、クエリ ステートメントの実行時に、ドライバーは SQL_CUR で始まり、長さが 18 文字を超えない名前を生成します。

接続内のすべてのカーソル名は一意である必要があります。カーソル名の最大長はドライバーによって定義されます。相互運用性を最大にするため、アプリケーションではカーソル名を 18 文字以内に制限することをお勧めします。ODBC 3*.x* では、カーソル名が引用符付き識別子の場合、大文字と小文字が区別されて扱われ、空白や予約キーワードなど、SQL の構文では許可されない文字や特別に扱われる文字を含めることができます。カーソル名を大文字と小文字を区別して扱う必要がある場合は、引用符付き識別子として渡す必要があります。

明示的または暗黙的に設定されたカーソル名は、関連付けられたステートメントが SQLFreeHandle によって破棄されるまで有効です。カーソルが割り当て済みまたは準備済みの状態にある限り、SQLSetCursorName を呼び出してステートメント上のカーソルの名前を変更できます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp)

各言語での呼び出し定義

// ODBC32.dll  (ANSI / -A)
#include <windows.h>

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

SQLSetCursorName = ctypes.windll.odbc32.SQLSetCursorName
SQLSetCursorName.restype = ctypes.c_short
SQLSetCursorName.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # CursorName : BYTE*
    ctypes.c_short,  # NameLength : SHORT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ODBC32.dll')
SQLSetCursorName = Fiddle::Function.new(
  lib['SQLSetCursorName'],
  [
    Fiddle::TYPE_VOIDP,  # StatementHandle : void* in/out
    Fiddle::TYPE_VOIDP,  # CursorName : BYTE*
    Fiddle::TYPE_SHORT,  # NameLength : SHORT
  ],
  Fiddle::TYPE_SHORT)
#[link(name = "odbc32")]
extern "system" {
    fn SQLSetCursorName(
        StatementHandle: *mut (),  // void* in/out
        CursorName: *mut u8,  // BYTE*
        NameLength: i16  // SHORT
    ) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLSetCursorName(IntPtr StatementHandle, IntPtr CursorName, short NameLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLSetCursorName' -Namespace Win32 -PassThru
# $api::SQLSetCursorName(StatementHandle, CursorName, NameLength)
#uselib "ODBC32.dll"
#func global SQLSetCursorName "SQLSetCursorName" sptr, sptr, sptr
; SQLSetCursorName StatementHandle, varptr(CursorName), NameLength   ; 戻り値は stat
; StatementHandle : void* in/out -> "sptr"
; CursorName : BYTE* -> "sptr"
; NameLength : SHORT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ODBC32.dll"
#cfunc global SQLSetCursorName "SQLSetCursorName" sptr, var, int
; res = SQLSetCursorName(StatementHandle, CursorName, NameLength)
; StatementHandle : void* in/out -> "sptr"
; CursorName : BYTE* -> "var"
; NameLength : SHORT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; SHORT SQLSetCursorName(void* StatementHandle, BYTE* CursorName, SHORT NameLength)
#uselib "ODBC32.dll"
#cfunc global SQLSetCursorName "SQLSetCursorName" intptr, var, int
; res = SQLSetCursorName(StatementHandle, CursorName, NameLength)
; StatementHandle : void* in/out -> "intptr"
; CursorName : BYTE* -> "var"
; NameLength : SHORT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLSetCursorName = odbc32.NewProc("SQLSetCursorName")
)

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

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

typedef SQLSetCursorNameNative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int16);
typedef SQLSetCursorNameDart = int Function(Pointer<Void>, Pointer<Uint8>, int);
final SQLSetCursorName = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLSetCursorNameNative, SQLSetCursorNameDart>('SQLSetCursorName');
// StatementHandle : void* in/out -> Pointer<Void>
// CursorName : BYTE* -> Pointer<Uint8>
// NameLength : SHORT -> Int16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLSetCursorName(
  StatementHandle: Pointer;   // void* in/out
  CursorName: Pointer;   // BYTE*
  NameLength: Smallint   // SHORT
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLSetCursorName';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLSetCursorName"
  c_SQLSetCursorName :: Ptr () -> Ptr Word8 -> Int16 -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- CursorName : BYTE* -> Ptr Word8
-- NameLength : SHORT -> Int16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlsetcursorname =
  foreign "SQLSetCursorName"
    ((ptr void) @-> (ptr uint8_t) @-> int16_t @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* CursorName : BYTE* -> (ptr uint8_t) *)
(* NameLength : SHORT -> int16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)

(cffi:defcfun ("SQLSetCursorName" sqlset-cursor-name :convention :stdcall) :int16
  (statement-handle :pointer)   ; void* in/out
  (cursor-name :pointer)   ; BYTE*
  (name-length :int16))   ; SHORT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLSetCursorName = Win32::API::More->new('ODBC32',
    'short SQLSetCursorName(LPVOID StatementHandle, LPVOID CursorName, short NameLength)');
# my $ret = $SQLSetCursorName->Call($StatementHandle, $CursorName, $NameLength);
# StatementHandle : void* in/out -> LPVOID
# CursorName : BYTE* -> LPVOID
# NameLength : SHORT -> short
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い