ホーム › System.Search › SQLPrepareA
SQLPrepareA
関数実行に備えてSQL文字列を解析しステートメントに準備する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLPrepareA(
void* hstmt,
BYTE* szSqlStr,
INT cbSqlStr
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hstmt | void* | inout | ODBCのステートメントハンドル。SQL文を準備する対象。 |
| szSqlStr | BYTE* | in | 準備するSQL文字列。パラメータマーカー(?)を含められる。 |
| cbSqlStr | INT | in | szSqlStrの文字数。SQL_NTSでNUL終端とみなす。 |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLPrepareA(
void* hstmt,
BYTE* szSqlStr,
INT cbSqlStr
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLPrepareA(
IntPtr hstmt, // void* in/out
IntPtr szSqlStr, // BYTE*
int cbSqlStr // INT
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLPrepareA(
hstmt As IntPtr, ' void* in/out
szSqlStr As IntPtr, ' BYTE*
cbSqlStr As Integer ' INT
) As Short
End Function' hstmt : void* in/out
' szSqlStr : BYTE*
' cbSqlStr : INT
Declare PtrSafe Function SQLPrepareA 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
SQLPrepareA = ctypes.windll.odbc32.SQLPrepareA
SQLPrepareA.restype = ctypes.c_short
SQLPrepareA.argtypes = [
ctypes.POINTER(None), # hstmt : void* in/out
ctypes.POINTER(ctypes.c_ubyte), # szSqlStr : BYTE*
ctypes.c_int, # cbSqlStr : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLPrepareA = Fiddle::Function.new(
lib['SQLPrepareA'],
[
Fiddle::TYPE_VOIDP, # hstmt : void* in/out
Fiddle::TYPE_VOIDP, # szSqlStr : BYTE*
Fiddle::TYPE_INT, # cbSqlStr : INT
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLPrepareA(
hstmt: *mut (), // void* in/out
szSqlStr: *mut u8, // BYTE*
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 SQLPrepareA(IntPtr hstmt, IntPtr szSqlStr, int cbSqlStr);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLPrepareA' -Namespace Win32 -PassThru
# $api::SQLPrepareA(hstmt, szSqlStr, cbSqlStr)#uselib "ODBC32.dll"
#func global SQLPrepareA "SQLPrepareA" sptr, sptr, sptr
; SQLPrepareA hstmt, varptr(szSqlStr), cbSqlStr ; 戻り値は stat
; hstmt : void* in/out -> "sptr"
; szSqlStr : BYTE* -> "sptr"
; cbSqlStr : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLPrepareA "SQLPrepareA" sptr, var, int ; res = SQLPrepareA(hstmt, szSqlStr, cbSqlStr) ; hstmt : void* in/out -> "sptr" ; szSqlStr : BYTE* -> "var" ; cbSqlStr : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLPrepareA "SQLPrepareA" sptr, sptr, int ; res = SQLPrepareA(hstmt, varptr(szSqlStr), cbSqlStr) ; hstmt : void* in/out -> "sptr" ; szSqlStr : BYTE* -> "sptr" ; cbSqlStr : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLPrepareA(void* hstmt, BYTE* szSqlStr, INT cbSqlStr) #uselib "ODBC32.dll" #cfunc global SQLPrepareA "SQLPrepareA" intptr, var, int ; res = SQLPrepareA(hstmt, szSqlStr, cbSqlStr) ; hstmt : void* in/out -> "intptr" ; szSqlStr : BYTE* -> "var" ; cbSqlStr : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLPrepareA(void* hstmt, BYTE* szSqlStr, INT cbSqlStr) #uselib "ODBC32.dll" #cfunc global SQLPrepareA "SQLPrepareA" intptr, intptr, int ; res = SQLPrepareA(hstmt, varptr(szSqlStr), cbSqlStr) ; hstmt : void* in/out -> "intptr" ; szSqlStr : BYTE* -> "intptr" ; cbSqlStr : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLPrepareA = odbc32.NewProc("SQLPrepareA")
)
// hstmt (void* in/out), szSqlStr (BYTE*), cbSqlStr (INT)
r1, _, err := procSQLPrepareA.Call(
uintptr(hstmt),
uintptr(szSqlStr),
uintptr(cbSqlStr),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLPrepareA(
hstmt: Pointer; // void* in/out
szSqlStr: Pointer; // BYTE*
cbSqlStr: Integer // INT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLPrepareA';result := DllCall("ODBC32\SQLPrepareA"
, "Ptr", hstmt ; void* in/out
, "Ptr", szSqlStr ; BYTE*
, "Int", cbSqlStr ; INT
, "Short") ; return: SHORT●SQLPrepareA(hstmt, szSqlStr, cbSqlStr) = DLL("ODBC32.dll", "int SQLPrepareA(void*, void*, int)")
# 呼び出し: SQLPrepareA(hstmt, szSqlStr, cbSqlStr)
# hstmt : void* in/out -> "void*"
# szSqlStr : BYTE* -> "void*"
# cbSqlStr : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "odbc32" fn SQLPrepareA(
hstmt: ?*anyopaque, // void* in/out
szSqlStr: [*c]u8, // BYTE*
cbSqlStr: i32 // INT
) callconv(std.os.windows.WINAPI) i16;proc SQLPrepareA(
hstmt: pointer, # void* in/out
szSqlStr: ptr uint8, # BYTE*
cbSqlStr: int32 # INT
): int16 {.importc: "SQLPrepareA", stdcall, dynlib: "ODBC32.dll".}pragma(lib, "odbc32");
extern(Windows)
short SQLPrepareA(
void* hstmt, // void* in/out
ubyte* szSqlStr, // BYTE*
int cbSqlStr // INT
);ccall((:SQLPrepareA, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Ptr{UInt8}, Int32),
hstmt, szSqlStr, cbSqlStr)
# hstmt : void* in/out -> Ptr{Cvoid}
# szSqlStr : BYTE* -> Ptr{UInt8}
# cbSqlStr : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLPrepareA(
void* hstmt,
uint8_t* szSqlStr,
int32_t cbSqlStr);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLPrepareA(hstmt, szSqlStr, cbSqlStr)
-- hstmt : void* in/out
-- szSqlStr : BYTE*
-- cbSqlStr : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLPrepareA = lib.func('__stdcall', 'SQLPrepareA', 'int16_t', ['void *', 'uint8_t *', 'int32_t']);
// SQLPrepareA(hstmt, szSqlStr, cbSqlStr)
// hstmt : void* in/out -> 'void *'
// szSqlStr : BYTE* -> 'uint8_t *'
// cbSqlStr : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLPrepareA: { parameters: ["pointer", "pointer", "i32"], result: "i16" },
});
// lib.symbols.SQLPrepareA(hstmt, szSqlStr, cbSqlStr)
// hstmt : void* in/out -> "pointer"
// szSqlStr : BYTE* -> "pointer"
// cbSqlStr : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLPrepareA(
void* hstmt,
uint8_t* szSqlStr,
int32_t cbSqlStr);
C, "ODBC32.dll");
// $ffi->SQLPrepareA(hstmt, szSqlStr, cbSqlStr);
// hstmt : void* in/out
// szSqlStr : BYTE*
// cbSqlStr : 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 SQLPrepareA(
Pointer hstmt, // void* in/out
byte[] szSqlStr, // BYTE*
int cbSqlStr // INT
);
}@[Link("odbc32")]
lib LibODBC32
fun SQLPrepareA = SQLPrepareA(
hstmt : Void*, # void* in/out
szSqlStr : UInt8*, # BYTE*
cbSqlStr : 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 SQLPrepareANative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int32);
typedef SQLPrepareADart = int Function(Pointer<Void>, Pointer<Uint8>, int);
final SQLPrepareA = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLPrepareANative, SQLPrepareADart>('SQLPrepareA');
// hstmt : void* in/out -> Pointer<Void>
// szSqlStr : BYTE* -> Pointer<Uint8>
// cbSqlStr : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SQLPrepareA(
hstmt: Pointer; // void* in/out
szSqlStr: Pointer; // BYTE*
cbSqlStr: Integer // INT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLPrepareA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLPrepareA"
c_SQLPrepareA :: Ptr () -> Ptr Word8 -> Int32 -> IO Int16
-- hstmt : void* in/out -> Ptr ()
-- szSqlStr : BYTE* -> Ptr Word8
-- cbSqlStr : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlpreparea =
foreign "SQLPrepareA"
((ptr void) @-> (ptr uint8_t) @-> int32_t @-> returning int16_t)
(* hstmt : void* in/out -> (ptr void) *)
(* szSqlStr : BYTE* -> (ptr uint8_t) *)
(* cbSqlStr : 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 ("SQLPrepareA" sqlprepare-a :convention :stdcall) :int16
(hstmt :pointer) ; void* in/out
(sz-sql-str :pointer) ; BYTE*
(cb-sql-str :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLPrepareA = Win32::API::More->new('ODBC32',
'short SQLPrepareA(LPVOID hstmt, LPVOID szSqlStr, int cbSqlStr)');
# my $ret = $SQLPrepareA->Call($hstmt, $szSqlStr, $cbSqlStr);
# hstmt : void* in/out -> LPVOID
# szSqlStr : BYTE* -> LPVOID
# cbSqlStr : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SQLPrepareW (Unicode版) — 実行に備えてSQL文を準備する(Unicode)。