ホーム › System.Search › SQLExecDirect
SQLExecDirect
関数SQL文を準備せず直接実行する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLExecDirect(
void* StatementHandle,
BYTE* StatementText, // optional
INT TextLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| StatementHandle | void* | inout | 対象のステートメントハンドル(HSTMT)。 |
| StatementText | BYTE* | inoptional | 直接実行するSQL文の文字列へのポインタ。 |
| TextLength | INT | in | StatementTextの長さ。SQL_NTSで終端まで。 |
戻り値の型: 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 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLExecDirect "SQLExecDirect" sptr, sptr, int ; res = SQLExecDirect(StatementHandle, varptr(StatementText), TextLength) ; StatementHandle : void* in/out -> "sptr" ; StatementText : BYTE* optional -> "sptr" ; TextLength : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; SHORT SQLExecDirect(void* StatementHandle, BYTE* StatementText, INT TextLength) #uselib "ODBC32.dll" #cfunc global SQLExecDirect "SQLExecDirect" intptr, intptr, int ; res = SQLExecDirect(StatementHandle, varptr(StatementText), TextLength) ; StatementHandle : void* in/out -> "intptr" ; StatementText : BYTE* optional -> "intptr" ; TextLength : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // SHORTfunction 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)。const std = @import("std");
extern "odbc32" fn SQLExecDirect(
StatementHandle: ?*anyopaque, // void* in/out
StatementText: [*c]u8, // BYTE* optional
TextLength: i32 // INT
) callconv(std.os.windows.WINAPI) i16;proc SQLExecDirect(
StatementHandle: pointer, # void* in/out
StatementText: ptr uint8, # BYTE* optional
TextLength: int32 # INT
): int16 {.importc: "SQLExecDirect", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLExecDirect(
void* StatementHandle, // void* in/out
ubyte* StatementText, // BYTE* optional
int TextLength // INT
);ccall((:SQLExecDirect, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Ptr{UInt8}, Int32),
StatementHandle, StatementText, TextLength)
# StatementHandle : void* in/out -> Ptr{Cvoid}
# StatementText : BYTE* optional -> Ptr{UInt8}
# TextLength : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLExecDirect(
void* StatementHandle,
uint8_t* StatementText,
int32_t TextLength);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLExecDirect(StatementHandle, StatementText, TextLength)
-- StatementHandle : void* in/out
-- StatementText : BYTE* optional
-- TextLength : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLExecDirect = lib.func('__stdcall', 'SQLExecDirect', 'int16_t', ['void *', 'uint8_t *', 'int32_t']);
// SQLExecDirect(StatementHandle, StatementText, TextLength)
// StatementHandle : void* in/out -> 'void *'
// StatementText : BYTE* optional -> 'uint8_t *'
// TextLength : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLExecDirect: { parameters: ["pointer", "pointer", "i32"], result: "i16" },
});
// lib.symbols.SQLExecDirect(StatementHandle, StatementText, TextLength)
// StatementHandle : void* in/out -> "pointer"
// StatementText : BYTE* optional -> "pointer"
// TextLength : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLExecDirect(
void* StatementHandle,
uint8_t* StatementText,
int32_t TextLength);
C, "ODBC32.dll");
// $ffi->SQLExecDirect(StatementHandle, StatementText, TextLength);
// StatementHandle : void* in/out
// StatementText : BYTE* optional
// TextLength : INT
// 構造体/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 SQLExecDirect(
Pointer StatementHandle, // void* in/out
byte[] StatementText, // BYTE* optional
int TextLength // INT
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLExecDirect = SQLExecDirect(
StatementHandle : Void*, # void* in/out
StatementText : UInt8*, # BYTE* optional
TextLength : Int32 # INT
) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SQLExecDirectNative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int32);
typedef SQLExecDirectDart = int Function(Pointer<Void>, Pointer<Uint8>, int);
final SQLExecDirect = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLExecDirectNative, SQLExecDirectDart>('SQLExecDirect');
// StatementHandle : void* in/out -> Pointer<Void>
// StatementText : BYTE* optional -> Pointer<Uint8>
// TextLength : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLExecDirect(
StatementHandle: Pointer; // void* in/out
StatementText: Pointer; // BYTE* optional
TextLength: Integer // INT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLExecDirect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLExecDirect"
c_SQLExecDirect :: Ptr () -> Ptr Word8 -> Int32 -> IO Int16
-- StatementHandle : void* in/out -> Ptr ()
-- StatementText : BYTE* optional -> Ptr Word8
-- TextLength : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlexecdirect =
foreign "SQLExecDirect"
((ptr void) @-> (ptr uint8_t) @-> int32_t @-> returning int16_t)
(* StatementHandle : void* in/out -> (ptr void) *)
(* StatementText : BYTE* optional -> (ptr uint8_t) *)
(* TextLength : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)
(cffi:defcfun ("SQLExecDirect" sqlexec-direct :convention :stdcall) :int16
(statement-handle :pointer) ; void* in/out
(statement-text :pointer) ; BYTE* optional
(text-length :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLExecDirect = Win32::API::More->new('ODBC32',
'short SQLExecDirect(LPVOID StatementHandle, LPVOID StatementText, int TextLength)');
# my $ret = $SQLExecDirect->Call($StatementHandle, $StatementText, $TextLength);
# StatementHandle : void* in/out -> LPVOID
# StatementText : BYTE* optional -> LPVOID
# TextLength : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLExecDirectA (ANSI版) — SQL文を準備せず直接実行する(ANSI)。
- f SQLExecDirectW (Unicode版) — SQL文を準備せず直接実行する(Unicode)。