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

SQLExecDirect

関数
SQL文を準備せず直接実行する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLExecDirect(
    void* StatementHandle,
    BYTE* StatementText,   // optional
    INT TextLength
);

パラメーター

名前方向
StatementHandlevoid*inout
StatementTextBYTE*inoptional
TextLengthINTin

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLExecDirect = ctypes.windll.odbc32.SQLExecDirect
SQLExecDirect.restype = ctypes.c_short
SQLExecDirect.argtypes = [
    ctypes.POINTER(None),  # StatementHandle : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # StatementText : BYTE* optional
    ctypes.c_int,  # TextLength : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLExecDirect = odbc32.NewProc("SQLExecDirect")
)

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