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

SQLNativeSqlW

関数
ドライバが解釈するネイティブSQL文に変換する(Unicode)。
DLLODBC32.dll文字セットUnicode (-W)呼出規約winapi

シグネチャ

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLNativeSqlW(
    void* hdbc,
    WORD* szSqlStrIn,
    INT cchSqlStrIn,
    WORD* szSqlStr,   // optional
    INT cchSqlStrMax,
    INT* pcchSqlStr
);

パラメーター

名前方向
hdbcvoid*inout
szSqlStrInWORD*in
cchSqlStrInINTin
szSqlStrWORD*outoptional
cchSqlStrMaxINTin
pcchSqlStrINT*inout

戻り値の型: SHORT

各言語での呼び出し定義

// ODBC32.dll  (Unicode / -W)
#include <windows.h>

SHORT SQLNativeSqlW(
    void* hdbc,
    WORD* szSqlStrIn,
    INT cchSqlStrIn,
    WORD* szSqlStr,   // optional
    INT cchSqlStrMax,
    INT* pcchSqlStr
);
[DllImport("ODBC32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern short SQLNativeSqlW(
    IntPtr hdbc,   // void* in/out
    ref ushort szSqlStrIn,   // WORD*
    int cchSqlStrIn,   // INT
    IntPtr szSqlStr,   // WORD* optional, out
    int cchSqlStrMax,   // INT
    ref int pcchSqlStr   // INT* in/out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SQLNativeSqlW(
    hdbc As IntPtr,   ' void* in/out
    ByRef szSqlStrIn As UShort,   ' WORD*
    cchSqlStrIn As Integer,   ' INT
    szSqlStr As IntPtr,   ' WORD* optional, out
    cchSqlStrMax As Integer,   ' INT
    ByRef pcchSqlStr As Integer   ' INT* in/out
) As Short
End Function
' hdbc : void* in/out
' szSqlStrIn : WORD*
' cchSqlStrIn : INT
' szSqlStr : WORD* optional, out
' cchSqlStrMax : INT
' pcchSqlStr : INT* in/out
Declare PtrSafe Function SQLNativeSqlW Lib "odbc32" ( _
    ByVal hdbc As LongPtr, _
    ByRef szSqlStrIn As Integer, _
    ByVal cchSqlStrIn As Long, _
    ByVal szSqlStr As LongPtr, _
    ByVal cchSqlStrMax As Long, _
    ByRef pcchSqlStr As Long) As Integer
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLNativeSqlW = ctypes.windll.odbc32.SQLNativeSqlW
SQLNativeSqlW.restype = ctypes.c_short
SQLNativeSqlW.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.POINTER(ctypes.c_ushort),  # szSqlStrIn : WORD*
    ctypes.c_int,  # cchSqlStrIn : INT
    ctypes.POINTER(ctypes.c_ushort),  # szSqlStr : WORD* optional, out
    ctypes.c_int,  # cchSqlStrMax : INT
    ctypes.POINTER(ctypes.c_int),  # pcchSqlStr : INT* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLNativeSqlW = odbc32.NewProc("SQLNativeSqlW")
)

// hdbc (void* in/out), szSqlStrIn (WORD*), cchSqlStrIn (INT), szSqlStr (WORD* optional, out), cchSqlStrMax (INT), pcchSqlStr (INT* in/out)
r1, _, err := procSQLNativeSqlW.Call(
	uintptr(hdbc),
	uintptr(szSqlStrIn),
	uintptr(cchSqlStrIn),
	uintptr(szSqlStr),
	uintptr(cchSqlStrMax),
	uintptr(pcchSqlStr),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLNativeSqlW(
  hdbc: Pointer;   // void* in/out
  szSqlStrIn: Pointer;   // WORD*
  cchSqlStrIn: Integer;   // INT
  szSqlStr: Pointer;   // WORD* optional, out
  cchSqlStrMax: Integer;   // INT
  pcchSqlStr: Pointer   // INT* in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLNativeSqlW';
result := DllCall("ODBC32\SQLNativeSqlW"
    , "Ptr", hdbc   ; void* in/out
    , "Ptr", szSqlStrIn   ; WORD*
    , "Int", cchSqlStrIn   ; INT
    , "Ptr", szSqlStr   ; WORD* optional, out
    , "Int", cchSqlStrMax   ; INT
    , "Ptr", pcchSqlStr   ; INT* in/out
    , "Short")   ; return: SHORT
●SQLNativeSqlW(hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr) = DLL("ODBC32.dll", "int SQLNativeSqlW(void*, void*, int, void*, int, void*)")
# 呼び出し: SQLNativeSqlW(hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr)
# hdbc : void* in/out -> "void*"
# szSqlStrIn : WORD* -> "void*"
# cchSqlStrIn : INT -> "int"
# szSqlStr : WORD* optional, out -> "void*"
# cchSqlStrMax : INT -> "int"
# pcchSqlStr : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。