Win32 API 日本語リファレンス
ホーム › Storage.Jet › JetGetCurrentIndexA

JetGetCurrentIndexA

関数
カーソルの現在のインデックス名を取得する(ANSI版)。
DLLESENT.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

INT JetGetCurrentIndexA(
    JET_SESID sesid,
    JET_TABLEID tableid,
    CHAR* szIndexName,
    DWORD cbIndexName
);

パラメーター

名前型方向説明
sesidJET_SESIDin現在インデックス取得を行うセッションのJET_SESIDハンドル。
tableidJET_TABLEIDin対象テーブルのカーソルハンドル。
szIndexNameCHAR*out現在の有効インデックス名を受け取る出力ANSI文字列バッファポインタ。
cbIndexNameDWORDinszIndexNameバッファのサイズをバイト単位で指定する値。

戻り値の型: INT

公式ドキュメント

JetGetCurrentIndex 関数は、指定したカーソルの現在のインデックスの名前を取得します。この名前は、後で JetSetCurrentIndex を使用してそのインデックスを現在のインデックスとして再選択する際にも使用されます。また、JetGetTableIndexInfo を使用してそのインデックスのプロパティを調べる際にも使用できます。

戻り値

この関数は JET_ERR データ型を返し、次のいずれかのリターン コードを含みます。ESE エラーの詳細については、Extensible Storage Engine Errors および Error Handling Parameters を参照してください。

リターン コード

説明

JET_errSuccess

操作は正常に完了しました。

JET_errClientRequestToStopJetService

JetStopService の呼び出しによって、セッションに関連付けられたインスタンス上のすべての動作が停止しているため、操作を完了できません。

JET_errInstanceUnavailable

セッションに関連付けられたインスタンスで、データの整合性を保護するためにすべてのデータへのアクセスを取り消す必要がある致命的なエラーが発生したため、操作を完了できません。このエラーは Windows XP 以降のリリースでのみ返されます。

JET_errNotInitialized

セッションに関連付けられたインスタンスがまだ初期化されていないため、操作を完了できません。

JET_errRestoreInProgress

セッションに関連付けられたインスタンスで復元操作が進行中であるため、操作を完了できません。

JET_errSessionSharingViolation

同じセッションを複数のスレッドで同時に使用することはできません。このエラーは Windows XP 以降のリリースでのみ返されます。

JET_errTermInProgress

セッションに関連付けられたインスタンスがシャットダウン中であるため、操作を完了できません。

JET_wrnBufferTruncated

操作は正常に完了しましたが、出力バッファーが小さすぎてインデックス名全体を受け取ることができませんでした。

出力バッファーには、収まる範囲でインデックス名が格納されます。出力バッファーの長さが 1 文字以上であれば、その出力バッファー内の文字列は null で終端されます。

注意 cchIndexName が 0 の場合、このエラーは返されません。詳細については「解説」セクションを参照してください。

成功した場合、指定したカーソルの現在のインデックスの名前が出力バッファーに返されます。JET_wrnBufferTruncated が返された場合、出力バッファーには、指定された領域に収まる範囲でインデックス名が格納されます。出力バッファーの長さが 1 文字以上であれば、そのバッファーに返される文字列は null で終端されます。データベースの状態は変更されません。

失敗した場合、出力バッファーの状態は未定義です。データベースの状態は変更されません。

解説

カーソルに現在のインデックスが存在しない場合は、空の文字列が返されます。これは、カーソルがテーブルのクラスター化インデックス上にあり、主インデックスが定義されていない場合に発生することがあります。このインデックスはテーブルのシーケンシャル インデックスと呼ばれ、定義を持ちません。いずれの場合も、JetSetCurrentIndex を使用して現在のインデックスに空の文字列を設定すると、主インデックスの定義の有無にかかわらずクラスター化インデックスが選択されます。

この関数には、すべてのリリースに存在する重要なバグがあります。出力バッファーが小さすぎてインデックス名全体を受け取れない場合でも、出力バッファーの長さが 1 文字以上であれば JET_wrnBufferTruncated は返されません。代わりに JET_errSuccess が返されます。この問題を回避するため、出力バッファーの長さは常に JET_cbNameMost + 1 (65) 文字以上にしてください。

要件

要件 値

クライアント

Windows Vista、Windows XP、または Windows 2000 Professional が必要です。

サーバー

Windows Server 2008、Windows Server 2003、または Windows 2000 Server が必要です。

ヘッダー

Esent.h で宣言されています。

ライブラリ

ESENT.lib を使用します。

DLL

ESENT.dll が必要です。

Unicode

JetGetCurrentIndexW (Unicode) および JetGetCurrentIndexA (ANSI) として実装されています。

関連項目

JET_ERR
JET_SESID
JET_TABLEID
JetGetTableIndexInfo
JetSetCurrentIndex

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

各言語での呼び出し定義

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

INT JetGetCurrentIndexA(
    JET_SESID sesid,
    JET_TABLEID tableid,
    CHAR* szIndexName,
    DWORD cbIndexName
);
[DllImport("ESENT.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int JetGetCurrentIndexA(
    UIntPtr sesid,   // JET_SESID
    UIntPtr tableid,   // JET_TABLEID
    IntPtr szIndexName,   // CHAR* out
    uint cbIndexName   // DWORD
);
<DllImport("ESENT.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function JetGetCurrentIndexA(
    sesid As UIntPtr,   ' JET_SESID
    tableid As UIntPtr,   ' JET_TABLEID
    szIndexName As IntPtr,   ' CHAR* out
    cbIndexName As UInteger   ' DWORD
) As Integer
End Function
' sesid : JET_SESID
' tableid : JET_TABLEID
' szIndexName : CHAR* out
' cbIndexName : DWORD
Declare PtrSafe Function JetGetCurrentIndexA Lib "esent" ( _
    ByVal sesid As LongPtr, _
    ByVal tableid As LongPtr, _
    ByVal szIndexName As LongPtr, _
    ByVal cbIndexName As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

JetGetCurrentIndexA = ctypes.windll.esent.JetGetCurrentIndexA
JetGetCurrentIndexA.restype = ctypes.c_int
JetGetCurrentIndexA.argtypes = [
    ctypes.c_size_t,  # sesid : JET_SESID
    ctypes.c_size_t,  # tableid : JET_TABLEID
    ctypes.POINTER(ctypes.c_byte),  # szIndexName : CHAR* out
    wintypes.DWORD,  # cbIndexName : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ESENT.dll')
JetGetCurrentIndexA = Fiddle::Function.new(
  lib['JetGetCurrentIndexA'],
  [
    Fiddle::TYPE_UINTPTR_T,  # sesid : JET_SESID
    Fiddle::TYPE_UINTPTR_T,  # tableid : JET_TABLEID
    Fiddle::TYPE_VOIDP,  # szIndexName : CHAR* out
    -Fiddle::TYPE_INT,  # cbIndexName : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "esent")]
extern "system" {
    fn JetGetCurrentIndexA(
        sesid: usize,  // JET_SESID
        tableid: usize,  // JET_TABLEID
        szIndexName: *mut i8,  // CHAR* out
        cbIndexName: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ESENT.dll", CharSet = CharSet.Ansi)]
public static extern int JetGetCurrentIndexA(UIntPtr sesid, UIntPtr tableid, IntPtr szIndexName, uint cbIndexName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ESENT_JetGetCurrentIndexA' -Namespace Win32 -PassThru
# $api::JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
#uselib "ESENT.dll"
#func global JetGetCurrentIndexA "JetGetCurrentIndexA" sptr, sptr, sptr, sptr
; JetGetCurrentIndexA sesid, tableid, varptr(szIndexName), cbIndexName   ; 戻り値は stat
; sesid : JET_SESID -> "sptr"
; tableid : JET_TABLEID -> "sptr"
; szIndexName : CHAR* out -> "sptr"
; cbIndexName : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ESENT.dll"
#cfunc global JetGetCurrentIndexA "JetGetCurrentIndexA" sptr, sptr, var, int
; res = JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
; sesid : JET_SESID -> "sptr"
; tableid : JET_TABLEID -> "sptr"
; szIndexName : CHAR* out -> "var"
; cbIndexName : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT JetGetCurrentIndexA(JET_SESID sesid, JET_TABLEID tableid, CHAR* szIndexName, DWORD cbIndexName)
#uselib "ESENT.dll"
#cfunc global JetGetCurrentIndexA "JetGetCurrentIndexA" intptr, intptr, var, int
; res = JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
; sesid : JET_SESID -> "intptr"
; tableid : JET_TABLEID -> "intptr"
; szIndexName : CHAR* out -> "var"
; cbIndexName : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	esent = windows.NewLazySystemDLL("ESENT.dll")
	procJetGetCurrentIndexA = esent.NewProc("JetGetCurrentIndexA")
)

// sesid (JET_SESID), tableid (JET_TABLEID), szIndexName (CHAR* out), cbIndexName (DWORD)
r1, _, err := procJetGetCurrentIndexA.Call(
	uintptr(sesid),
	uintptr(tableid),
	uintptr(szIndexName),
	uintptr(cbIndexName),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function JetGetCurrentIndexA(
  sesid: NativeUInt;   // JET_SESID
  tableid: NativeUInt;   // JET_TABLEID
  szIndexName: Pointer;   // CHAR* out
  cbIndexName: DWORD   // DWORD
): Integer; stdcall;
  external 'ESENT.dll' name 'JetGetCurrentIndexA';
result := DllCall("ESENT\JetGetCurrentIndexA"
    , "UPtr", sesid   ; JET_SESID
    , "UPtr", tableid   ; JET_TABLEID
    , "Ptr", szIndexName   ; CHAR* out
    , "UInt", cbIndexName   ; DWORD
    , "Int")   ; return: INT
●JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName) = DLL("ESENT.dll", "int JetGetCurrentIndexA(int, int, void*, dword)")
# 呼び出し: JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
# sesid : JET_SESID -> "int"
# tableid : JET_TABLEID -> "int"
# szIndexName : CHAR* out -> "void*"
# cbIndexName : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "esent" fn JetGetCurrentIndexA(
    sesid: usize, // JET_SESID
    tableid: usize, // JET_TABLEID
    szIndexName: [*c]i8, // CHAR* out
    cbIndexName: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc JetGetCurrentIndexA(
    sesid: uint,  # JET_SESID
    tableid: uint,  # JET_TABLEID
    szIndexName: ptr int8,  # CHAR* out
    cbIndexName: uint32  # DWORD
): int32 {.importc: "JetGetCurrentIndexA", stdcall, dynlib: "ESENT.dll".}
pragma(lib, "esent");
extern(Windows)
int JetGetCurrentIndexA(
    size_t sesid,   // JET_SESID
    size_t tableid,   // JET_TABLEID
    byte* szIndexName,   // CHAR* out
    uint cbIndexName   // DWORD
);
ccall((:JetGetCurrentIndexA, "ESENT.dll"), stdcall, Int32,
      (Csize_t, Csize_t, Ptr{Int8}, UInt32),
      sesid, tableid, szIndexName, cbIndexName)
# sesid : JET_SESID -> Csize_t
# tableid : JET_TABLEID -> Csize_t
# szIndexName : CHAR* out -> Ptr{Int8}
# cbIndexName : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t JetGetCurrentIndexA(
    uintptr_t sesid,
    uintptr_t tableid,
    int8_t* szIndexName,
    uint32_t cbIndexName);
]]
local esent = ffi.load("esent")
-- esent.JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
-- sesid : JET_SESID
-- tableid : JET_TABLEID
-- szIndexName : CHAR* out
-- cbIndexName : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ESENT.dll');
const JetGetCurrentIndexA = lib.func('__stdcall', 'JetGetCurrentIndexA', 'int32_t', ['uintptr_t', 'uintptr_t', 'int8_t *', 'uint32_t']);
// JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
// sesid : JET_SESID -> 'uintptr_t'
// tableid : JET_TABLEID -> 'uintptr_t'
// szIndexName : CHAR* out -> 'int8_t *'
// cbIndexName : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ESENT.dll", {
  JetGetCurrentIndexA: { parameters: ["usize", "usize", "pointer", "u32"], result: "i32" },
});
// lib.symbols.JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName)
// sesid : JET_SESID -> "usize"
// tableid : JET_TABLEID -> "usize"
// szIndexName : CHAR* out -> "pointer"
// cbIndexName : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t JetGetCurrentIndexA(
    size_t sesid,
    size_t tableid,
    int8_t* szIndexName,
    uint32_t cbIndexName);
C, "ESENT.dll");
// $ffi->JetGetCurrentIndexA(sesid, tableid, szIndexName, cbIndexName);
// sesid : JET_SESID
// tableid : JET_TABLEID
// szIndexName : CHAR* out
// cbIndexName : DWORD
// 構造体/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 Esent extends StdCallLibrary {
    Esent INSTANCE = Native.load("esent", Esent.class, W32APIOptions.ASCII_OPTIONS);
    int JetGetCurrentIndexA(
        long sesid,   // JET_SESID
        long tableid,   // JET_TABLEID
        byte[] szIndexName,   // CHAR* out
        int cbIndexName   // DWORD
    );
}
@[Link("esent")]
lib LibESENT
  fun JetGetCurrentIndexA = JetGetCurrentIndexA(
    sesid : LibC::SizeT,   # JET_SESID
    tableid : LibC::SizeT,   # JET_TABLEID
    szIndexName : Int8*,   # CHAR* out
    cbIndexName : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef JetGetCurrentIndexANative = Int32 Function(UintPtr, UintPtr, Pointer<Int8>, Uint32);
typedef JetGetCurrentIndexADart = int Function(int, int, Pointer<Int8>, int);
final JetGetCurrentIndexA = DynamicLibrary.open('ESENT.dll')
    .lookupFunction<JetGetCurrentIndexANative, JetGetCurrentIndexADart>('JetGetCurrentIndexA');
// sesid : JET_SESID -> UintPtr
// tableid : JET_TABLEID -> UintPtr
// szIndexName : CHAR* out -> Pointer<Int8>
// cbIndexName : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function JetGetCurrentIndexA(
  sesid: NativeUInt;   // JET_SESID
  tableid: NativeUInt;   // JET_TABLEID
  szIndexName: Pointer;   // CHAR* out
  cbIndexName: DWORD   // DWORD
): Integer; stdcall;
  external 'ESENT.dll' name 'JetGetCurrentIndexA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "JetGetCurrentIndexA"
  c_JetGetCurrentIndexA :: CUIntPtr -> CUIntPtr -> Ptr Int8 -> Word32 -> IO Int32
-- sesid : JET_SESID -> CUIntPtr
-- tableid : JET_TABLEID -> CUIntPtr
-- szIndexName : CHAR* out -> Ptr Int8
-- cbIndexName : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let jetgetcurrentindexa =
  foreign "JetGetCurrentIndexA"
    (size_t @-> size_t @-> (ptr int8_t) @-> uint32_t @-> returning int32_t)
(* sesid : JET_SESID -> size_t *)
(* tableid : JET_TABLEID -> size_t *)
(* szIndexName : CHAR* out -> (ptr int8_t) *)
(* cbIndexName : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library esent (t "ESENT.dll"))
(cffi:use-foreign-library esent)

(cffi:defcfun ("JetGetCurrentIndexA" jet-get-current-index-a :convention :stdcall) :int32
  (sesid :uint64)   ; JET_SESID
  (tableid :uint64)   ; JET_TABLEID
  (sz-index-name :pointer)   ; CHAR* out
  (cb-index-name :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $JetGetCurrentIndexA = Win32::API::More->new('ESENT',
    'int JetGetCurrentIndexA(WPARAM sesid, WPARAM tableid, LPVOID szIndexName, DWORD cbIndexName)');
# my $ret = $JetGetCurrentIndexA->Call($sesid, $tableid, $szIndexName, $cbIndexName);
# sesid : JET_SESID -> WPARAM
# tableid : JET_TABLEID -> WPARAM
# szIndexName : CHAR* out -> LPVOID
# cbIndexName : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い