ホーム › System.Search › SQLNativeSqlW
SQLNativeSqlW
関数ドライバが解釈するネイティブSQL文に変換する(Unicode)。
シグネチャ
// ODBC32.dll (Unicode / -W)
#include <windows.h>
SHORT SQLNativeSqlW(
void* hdbc,
WORD* szSqlStrIn,
INT cchSqlStrIn,
WORD* szSqlStr, // optional
INT cchSqlStrMax,
INT* pcchSqlStr
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdbc | void* | inout | 対象の接続ハンドル。ドライバ固有のSQLへ変換する。 |
| szSqlStrIn | WORD* | in | 入力するSQL文字列。Unicode文字列。 |
| cchSqlStrIn | INT | in | szSqlStrInの文字数。SQL_NTSでNUL終端を示す。 |
| szSqlStr | WORD* | outoptional | 変換後のネイティブSQLを受け取るバッファ。Unicode文字列。 |
| cchSqlStrMax | INT | in | szSqlStrバッファの文字数長。 |
| pcchSqlStr | INT* | inout | 変換後SQLの実際の文字数を受け取るポインタ。NULL可。 |
戻り値の型: 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 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLNativeSqlW "SQLNativeSqlW" sptr, sptr, int, sptr, int, sptr ; res = SQLNativeSqlW(hdbc, varptr(szSqlStrIn), cchSqlStrIn, varptr(szSqlStr), cchSqlStrMax, varptr(pcchSqlStr)) ; hdbc : void* in/out -> "sptr" ; szSqlStrIn : WORD* -> "sptr" ; cchSqlStrIn : INT -> "int" ; szSqlStr : WORD* optional, out -> "sptr" ; cchSqlStrMax : INT -> "int" ; pcchSqlStr : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; SHORT SQLNativeSqlW(void* hdbc, WORD* szSqlStrIn, INT cchSqlStrIn, WORD* szSqlStr, INT cchSqlStrMax, INT* pcchSqlStr) #uselib "ODBC32.dll" #cfunc global SQLNativeSqlW "SQLNativeSqlW" intptr, intptr, int, intptr, int, intptr ; res = SQLNativeSqlW(hdbc, varptr(szSqlStrIn), cchSqlStrIn, varptr(szSqlStr), cchSqlStrMax, varptr(pcchSqlStr)) ; hdbc : void* in/out -> "intptr" ; szSqlStrIn : WORD* -> "intptr" ; cchSqlStrIn : INT -> "int" ; szSqlStr : WORD* optional, out -> "intptr" ; cchSqlStrMax : INT -> "int" ; pcchSqlStr : INT* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // SHORTfunction 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 版の利用を推奨。const std = @import("std");
extern "odbc32" fn SQLNativeSqlW(
hdbc: ?*anyopaque, // void* in/out
szSqlStrIn: [*c]u16, // WORD*
cchSqlStrIn: i32, // INT
szSqlStr: [*c]u16, // WORD* optional, out
cchSqlStrMax: i32, // INT
pcchSqlStr: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) i16;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SQLNativeSqlW(
hdbc: pointer, # void* in/out
szSqlStrIn: ptr uint16, # WORD*
cchSqlStrIn: int32, # INT
szSqlStr: ptr uint16, # WORD* optional, out
cchSqlStrMax: int32, # INT
pcchSqlStr: ptr int32 # INT* in/out
): int16 {.importc: "SQLNativeSqlW", stdcall, dynlib: "ODBC32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "odbc32");
extern(Windows)
short SQLNativeSqlW(
void* hdbc, // void* in/out
ushort* szSqlStrIn, // WORD*
int cchSqlStrIn, // INT
ushort* szSqlStr, // WORD* optional, out
int cchSqlStrMax, // INT
int* pcchSqlStr // INT* in/out
);ccall((:SQLNativeSqlW, "ODBC32.dll"), stdcall, Int16,
(Ptr{Cvoid}, Ptr{UInt16}, Int32, Ptr{UInt16}, Int32, Ptr{Int32}),
hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr)
# hdbc : void* in/out -> Ptr{Cvoid}
# szSqlStrIn : WORD* -> Ptr{UInt16}
# cchSqlStrIn : INT -> Int32
# szSqlStr : WORD* optional, out -> Ptr{UInt16}
# cchSqlStrMax : INT -> Int32
# pcchSqlStr : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int16_t SQLNativeSqlW(
void* hdbc,
uint16_t* szSqlStrIn,
int32_t cchSqlStrIn,
uint16_t* szSqlStr,
int32_t cchSqlStrMax,
int32_t* pcchSqlStr);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLNativeSqlW(hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr)
-- hdbc : void* in/out
-- szSqlStrIn : WORD*
-- cchSqlStrIn : INT
-- szSqlStr : WORD* optional, out
-- cchSqlStrMax : INT
-- pcchSqlStr : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLNativeSqlW = lib.func('__stdcall', 'SQLNativeSqlW', 'int16_t', ['void *', 'uint16_t *', 'int32_t', 'uint16_t *', 'int32_t', 'int32_t *']);
// SQLNativeSqlW(hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr)
// hdbc : void* in/out -> 'void *'
// szSqlStrIn : WORD* -> 'uint16_t *'
// cchSqlStrIn : INT -> 'int32_t'
// szSqlStr : WORD* optional, out -> 'uint16_t *'
// cchSqlStrMax : INT -> 'int32_t'
// pcchSqlStr : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ODBC32.dll", {
SQLNativeSqlW: { parameters: ["pointer", "pointer", "i32", "pointer", "i32", "pointer"], result: "i16" },
});
// lib.symbols.SQLNativeSqlW(hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr)
// hdbc : void* in/out -> "pointer"
// szSqlStrIn : WORD* -> "pointer"
// cchSqlStrIn : INT -> "i32"
// szSqlStr : WORD* optional, out -> "pointer"
// cchSqlStrMax : INT -> "i32"
// pcchSqlStr : INT* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int16_t SQLNativeSqlW(
void* hdbc,
uint16_t* szSqlStrIn,
int32_t cchSqlStrIn,
uint16_t* szSqlStr,
int32_t cchSqlStrMax,
int32_t* pcchSqlStr);
C, "ODBC32.dll");
// $ffi->SQLNativeSqlW(hdbc, szSqlStrIn, cchSqlStrIn, szSqlStr, cchSqlStrMax, pcchSqlStr);
// hdbc : void* in/out
// szSqlStrIn : WORD*
// cchSqlStrIn : INT
// szSqlStr : WORD* optional, out
// cchSqlStrMax : INT
// pcchSqlStr : INT* in/out
// 構造体/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.UNICODE_OPTIONS);
short SQLNativeSqlW(
Pointer hdbc, // void* in/out
ShortByReference szSqlStrIn, // WORD*
int cchSqlStrIn, // INT
ShortByReference szSqlStr, // WORD* optional, out
int cchSqlStrMax, // INT
IntByReference pcchSqlStr // INT* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("odbc32")]
lib LibODBC32
fun SQLNativeSqlW = SQLNativeSqlW(
hdbc : Void*, # void* in/out
szSqlStrIn : UInt16*, # WORD*
cchSqlStrIn : Int32, # INT
szSqlStr : UInt16*, # WORD* optional, out
cchSqlStrMax : Int32, # INT
pcchSqlStr : Int32* # INT* in/out
) : Int16
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SQLNativeSqlWNative = Int16 Function(Pointer<Void>, Pointer<Uint16>, Int32, Pointer<Uint16>, Int32, Pointer<Int32>);
typedef SQLNativeSqlWDart = int Function(Pointer<Void>, Pointer<Uint16>, int, Pointer<Uint16>, int, Pointer<Int32>);
final SQLNativeSqlW = DynamicLibrary.open('ODBC32.dll')
.lookupFunction<SQLNativeSqlWNative, SQLNativeSqlWDart>('SQLNativeSqlW');
// hdbc : void* in/out -> Pointer<Void>
// szSqlStrIn : WORD* -> Pointer<Uint16>
// cchSqlStrIn : INT -> Int32
// szSqlStr : WORD* optional, out -> Pointer<Uint16>
// cchSqlStrMax : INT -> Int32
// pcchSqlStr : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SQLNativeSqlW"
c_SQLNativeSqlW :: Ptr () -> Ptr Word16 -> Int32 -> Ptr Word16 -> Int32 -> Ptr Int32 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- szSqlStrIn : WORD* -> Ptr Word16
-- cchSqlStrIn : INT -> Int32
-- szSqlStr : WORD* optional, out -> Ptr Word16
-- cchSqlStrMax : INT -> Int32
-- pcchSqlStr : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let sqlnativesqlw =
foreign "SQLNativeSqlW"
((ptr void) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> (ptr int32_t) @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* szSqlStrIn : WORD* -> (ptr uint16_t) *)
(* cchSqlStrIn : INT -> int32_t *)
(* szSqlStr : WORD* optional, out -> (ptr uint16_t) *)
(* cchSqlStrMax : INT -> int32_t *)
(* pcchSqlStr : INT* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library odbc32 (t "ODBC32.dll"))
(cffi:use-foreign-library odbc32)
(cffi:defcfun ("SQLNativeSqlW" sqlnative-sql-w :convention :stdcall) :int16
(hdbc :pointer) ; void* in/out
(sz-sql-str-in :pointer) ; WORD*
(cch-sql-str-in :int32) ; INT
(sz-sql-str :pointer) ; WORD* optional, out
(cch-sql-str-max :int32) ; INT
(pcch-sql-str :pointer)) ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SQLNativeSqlW = Win32::API::More->new('ODBC32',
'short SQLNativeSqlW(LPVOID hdbc, LPVOID szSqlStrIn, int cchSqlStrIn, LPVOID szSqlStr, int cchSqlStrMax, LPVOID pcchSqlStr)');
# my $ret = $SQLNativeSqlW->Call($hdbc, $szSqlStrIn, $cchSqlStrIn, $szSqlStr, $cchSqlStrMax, $pcchSqlStr);
# hdbc : void* in/out -> LPVOID
# szSqlStrIn : WORD* -> LPVOID
# cchSqlStrIn : INT -> int
# szSqlStr : WORD* optional, out -> LPVOID
# cchSqlStrMax : INT -> int
# pcchSqlStr : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SQLNativeSqlA (ANSI版) — SQL文をドライバ固有のネイティブSQLに変換する。