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

SQLExecDirectA

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

シグネチャ

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

SHORT SQLExecDirectA(
    void* hstmt,
    BYTE* szSqlStr,   // optional
    INT cbSqlStr
);

パラメーター

名前方向
hstmtvoid*inout
szSqlStrBYTE*inoptional
cbSqlStrINTin

戻り値の型: SHORT

各言語での呼び出し定義

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

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

SQLExecDirectA = ctypes.windll.odbc32.SQLExecDirectA
SQLExecDirectA.restype = ctypes.c_short
SQLExecDirectA.argtypes = [
    ctypes.POINTER(None),  # hstmt : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # szSqlStr : BYTE* optional
    ctypes.c_int,  # cbSqlStr : INT
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLExecDirectA = odbc32.NewProc("SQLExecDirectA")
)

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