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

SQLPrepareA

関数
実行に備えてSQL文字列を解析しステートメントに準備する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLPrepareA(
    void* hstmt,
    BYTE* szSqlStr,
    INT cbSqlStr
);

パラメーター

名前方向
hstmtvoid*inout
szSqlStrBYTE*in
cbSqlStrINTin

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // SHORT
function 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)。