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

SQLNativeSqlA

関数
SQL文をドライバ固有のネイティブSQLに変換する。
DLLODBC32.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

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

SHORT SQLNativeSqlA(
    void* hdbc,
    BYTE* szSqlStrIn,
    INT cbSqlStrIn,
    BYTE* szSqlStr,   // optional
    INT cbSqlStrMax,
    INT* pcbSqlStr
);

パラメーター

名前方向説明
hdbcvoid*inoutODBCの接続ハンドル。SQL変換を行う対象。
szSqlStrInBYTE*inドライバ固有形式に変換する入力SQL文字列。
cbSqlStrInINTinszSqlStrInの文字数。SQL_NTSでNUL終端とみなす。
szSqlStrBYTE*outoptional変換後のネイティブSQL文字列を受け取るバッファ。出力用。
cbSqlStrMaxINTinszSqlStrバッファのバイト長。
pcbSqlStrINT*inout実際に返された変換後SQLのバイト長を受け取るポインタ。

戻り値の型: SHORT

各言語での呼び出し定義

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

SHORT SQLNativeSqlA(
    void* hdbc,
    BYTE* szSqlStrIn,
    INT cbSqlStrIn,
    BYTE* szSqlStr,   // optional
    INT cbSqlStrMax,
    INT* pcbSqlStr
);
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLNativeSqlA(
    IntPtr hdbc,   // void* in/out
    IntPtr szSqlStrIn,   // BYTE*
    int cbSqlStrIn,   // INT
    IntPtr szSqlStr,   // BYTE* optional, out
    int cbSqlStrMax,   // INT
    ref int pcbSqlStr   // INT* in/out
);
<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLNativeSqlA(
    hdbc As IntPtr,   ' void* in/out
    szSqlStrIn As IntPtr,   ' BYTE*
    cbSqlStrIn As Integer,   ' INT
    szSqlStr As IntPtr,   ' BYTE* optional, out
    cbSqlStrMax As Integer,   ' INT
    ByRef pcbSqlStr As Integer   ' INT* in/out
) As Short
End Function
' hdbc : void* in/out
' szSqlStrIn : BYTE*
' cbSqlStrIn : INT
' szSqlStr : BYTE* optional, out
' cbSqlStrMax : INT
' pcbSqlStr : INT* in/out
Declare PtrSafe Function SQLNativeSqlA Lib "odbc32" ( _
    ByVal hdbc As LongPtr, _
    ByVal szSqlStrIn As LongPtr, _
    ByVal cbSqlStrIn As Long, _
    ByVal szSqlStr As LongPtr, _
    ByVal cbSqlStrMax As Long, _
    ByRef pcbSqlStr As Long) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SQLNativeSqlA = ctypes.windll.odbc32.SQLNativeSqlA
SQLNativeSqlA.restype = ctypes.c_short
SQLNativeSqlA.argtypes = [
    ctypes.POINTER(None),  # hdbc : void* in/out
    ctypes.POINTER(ctypes.c_ubyte),  # szSqlStrIn : BYTE*
    ctypes.c_int,  # cbSqlStrIn : INT
    ctypes.POINTER(ctypes.c_ubyte),  # szSqlStr : BYTE* optional, out
    ctypes.c_int,  # cbSqlStrMax : INT
    ctypes.POINTER(ctypes.c_int),  # pcbSqlStr : INT* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
	procSQLNativeSqlA = odbc32.NewProc("SQLNativeSqlA")
)

// hdbc (void* in/out), szSqlStrIn (BYTE*), cbSqlStrIn (INT), szSqlStr (BYTE* optional, out), cbSqlStrMax (INT), pcbSqlStr (INT* in/out)
r1, _, err := procSQLNativeSqlA.Call(
	uintptr(hdbc),
	uintptr(szSqlStrIn),
	uintptr(cbSqlStrIn),
	uintptr(szSqlStr),
	uintptr(cbSqlStrMax),
	uintptr(pcbSqlStr),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // SHORT
function SQLNativeSqlA(
  hdbc: Pointer;   // void* in/out
  szSqlStrIn: Pointer;   // BYTE*
  cbSqlStrIn: Integer;   // INT
  szSqlStr: Pointer;   // BYTE* optional, out
  cbSqlStrMax: Integer;   // INT
  pcbSqlStr: Pointer   // INT* in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLNativeSqlA';
result := DllCall("ODBC32\SQLNativeSqlA"
    , "Ptr", hdbc   ; void* in/out
    , "Ptr", szSqlStrIn   ; BYTE*
    , "Int", cbSqlStrIn   ; INT
    , "Ptr", szSqlStr   ; BYTE* optional, out
    , "Int", cbSqlStrMax   ; INT
    , "Ptr", pcbSqlStr   ; INT* in/out
    , "Short")   ; return: SHORT
●SQLNativeSqlA(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr) = DLL("ODBC32.dll", "int SQLNativeSqlA(void*, void*, int, void*, int, void*)")
# 呼び出し: SQLNativeSqlA(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr)
# hdbc : void* in/out -> "void*"
# szSqlStrIn : BYTE* -> "void*"
# cbSqlStrIn : INT -> "int"
# szSqlStr : BYTE* optional, out -> "void*"
# cbSqlStrMax : INT -> "int"
# pcbSqlStr : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "odbc32" fn SQLNativeSqlA(
    hdbc: ?*anyopaque, // void* in/out
    szSqlStrIn: [*c]u8, // BYTE*
    cbSqlStrIn: i32, // INT
    szSqlStr: [*c]u8, // BYTE* optional, out
    cbSqlStrMax: i32, // INT
    pcbSqlStr: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) i16;
proc SQLNativeSqlA(
    hdbc: pointer,  # void* in/out
    szSqlStrIn: ptr uint8,  # BYTE*
    cbSqlStrIn: int32,  # INT
    szSqlStr: ptr uint8,  # BYTE* optional, out
    cbSqlStrMax: int32,  # INT
    pcbSqlStr: ptr int32  # INT* in/out
): int16 {.importc: "SQLNativeSqlA", stdcall, dynlib: "ODBC32.dll".}
pragma(lib, "odbc32");
extern(Windows)
short SQLNativeSqlA(
    void* hdbc,   // void* in/out
    ubyte* szSqlStrIn,   // BYTE*
    int cbSqlStrIn,   // INT
    ubyte* szSqlStr,   // BYTE* optional, out
    int cbSqlStrMax,   // INT
    int* pcbSqlStr   // INT* in/out
);
ccall((:SQLNativeSqlA, "ODBC32.dll"), stdcall, Int16,
      (Ptr{Cvoid}, Ptr{UInt8}, Int32, Ptr{UInt8}, Int32, Ptr{Int32}),
      hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr)
# hdbc : void* in/out -> Ptr{Cvoid}
# szSqlStrIn : BYTE* -> Ptr{UInt8}
# cbSqlStrIn : INT -> Int32
# szSqlStr : BYTE* optional, out -> Ptr{UInt8}
# cbSqlStrMax : INT -> Int32
# pcbSqlStr : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int16_t SQLNativeSqlA(
    void* hdbc,
    uint8_t* szSqlStrIn,
    int32_t cbSqlStrIn,
    uint8_t* szSqlStr,
    int32_t cbSqlStrMax,
    int32_t* pcbSqlStr);
]]
local odbc32 = ffi.load("odbc32")
-- odbc32.SQLNativeSqlA(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr)
-- hdbc : void* in/out
-- szSqlStrIn : BYTE*
-- cbSqlStrIn : INT
-- szSqlStr : BYTE* optional, out
-- cbSqlStrMax : INT
-- pcbSqlStr : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ODBC32.dll');
const SQLNativeSqlA = lib.func('__stdcall', 'SQLNativeSqlA', 'int16_t', ['void *', 'uint8_t *', 'int32_t', 'uint8_t *', 'int32_t', 'int32_t *']);
// SQLNativeSqlA(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr)
// hdbc : void* in/out -> 'void *'
// szSqlStrIn : BYTE* -> 'uint8_t *'
// cbSqlStrIn : INT -> 'int32_t'
// szSqlStr : BYTE* optional, out -> 'uint8_t *'
// cbSqlStrMax : INT -> 'int32_t'
// pcbSqlStr : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ODBC32.dll", {
  SQLNativeSqlA: { parameters: ["pointer", "pointer", "i32", "pointer", "i32", "pointer"], result: "i16" },
});
// lib.symbols.SQLNativeSqlA(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr)
// hdbc : void* in/out -> "pointer"
// szSqlStrIn : BYTE* -> "pointer"
// cbSqlStrIn : INT -> "i32"
// szSqlStr : BYTE* optional, out -> "pointer"
// cbSqlStrMax : INT -> "i32"
// pcbSqlStr : INT* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int16_t SQLNativeSqlA(
    void* hdbc,
    uint8_t* szSqlStrIn,
    int32_t cbSqlStrIn,
    uint8_t* szSqlStr,
    int32_t cbSqlStrMax,
    int32_t* pcbSqlStr);
C, "ODBC32.dll");
// $ffi->SQLNativeSqlA(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr);
// hdbc : void* in/out
// szSqlStrIn : BYTE*
// cbSqlStrIn : INT
// szSqlStr : BYTE* optional, out
// cbSqlStrMax : INT
// pcbSqlStr : 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.ASCII_OPTIONS);
    short SQLNativeSqlA(
        Pointer hdbc,   // void* in/out
        byte[] szSqlStrIn,   // BYTE*
        int cbSqlStrIn,   // INT
        byte[] szSqlStr,   // BYTE* optional, out
        int cbSqlStrMax,   // INT
        IntByReference pcbSqlStr   // INT* in/out
    );
}
@[Link("odbc32")]
lib LibODBC32
  fun SQLNativeSqlA = SQLNativeSqlA(
    hdbc : Void*,   # void* in/out
    szSqlStrIn : UInt8*,   # BYTE*
    cbSqlStrIn : Int32,   # INT
    szSqlStr : UInt8*,   # BYTE* optional, out
    cbSqlStrMax : Int32,   # INT
    pcbSqlStr : 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 SQLNativeSqlANative = Int16 Function(Pointer<Void>, Pointer<Uint8>, Int32, Pointer<Uint8>, Int32, Pointer<Int32>);
typedef SQLNativeSqlADart = int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Int32>);
final SQLNativeSqlA = DynamicLibrary.open('ODBC32.dll')
    .lookupFunction<SQLNativeSqlANative, SQLNativeSqlADart>('SQLNativeSqlA');
// hdbc : void* in/out -> Pointer<Void>
// szSqlStrIn : BYTE* -> Pointer<Uint8>
// cbSqlStrIn : INT -> Int32
// szSqlStr : BYTE* optional, out -> Pointer<Uint8>
// cbSqlStrMax : INT -> Int32
// pcbSqlStr : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SQLNativeSqlA(
  hdbc: Pointer;   // void* in/out
  szSqlStrIn: Pointer;   // BYTE*
  cbSqlStrIn: Integer;   // INT
  szSqlStr: Pointer;   // BYTE* optional, out
  cbSqlStrMax: Integer;   // INT
  pcbSqlStr: Pointer   // INT* in/out
): Smallint; stdcall;
  external 'ODBC32.dll' name 'SQLNativeSqlA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SQLNativeSqlA"
  c_SQLNativeSqlA :: Ptr () -> Ptr Word8 -> Int32 -> Ptr Word8 -> Int32 -> Ptr Int32 -> IO Int16
-- hdbc : void* in/out -> Ptr ()
-- szSqlStrIn : BYTE* -> Ptr Word8
-- cbSqlStrIn : INT -> Int32
-- szSqlStr : BYTE* optional, out -> Ptr Word8
-- cbSqlStrMax : INT -> Int32
-- pcbSqlStr : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sqlnativesqla =
  foreign "SQLNativeSqlA"
    ((ptr void) @-> (ptr uint8_t) @-> int32_t @-> (ptr uint8_t) @-> int32_t @-> (ptr int32_t) @-> returning int16_t)
(* hdbc : void* in/out -> (ptr void) *)
(* szSqlStrIn : BYTE* -> (ptr uint8_t) *)
(* cbSqlStrIn : INT -> int32_t *)
(* szSqlStr : BYTE* optional, out -> (ptr uint8_t) *)
(* cbSqlStrMax : INT -> int32_t *)
(* pcbSqlStr : 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 ("SQLNativeSqlA" sqlnative-sql-a :convention :stdcall) :int16
  (hdbc :pointer)   ; void* in/out
  (sz-sql-str-in :pointer)   ; BYTE*
  (cb-sql-str-in :int32)   ; INT
  (sz-sql-str :pointer)   ; BYTE* optional, out
  (cb-sql-str-max :int32)   ; INT
  (pcb-sql-str :pointer))   ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SQLNativeSqlA = Win32::API::More->new('ODBC32',
    'short SQLNativeSqlA(LPVOID hdbc, LPVOID szSqlStrIn, int cbSqlStrIn, LPVOID szSqlStr, int cbSqlStrMax, LPVOID pcbSqlStr)');
# my $ret = $SQLNativeSqlA->Call($hdbc, $szSqlStrIn, $cbSqlStrIn, $szSqlStr, $cbSqlStrMax, $pcbSqlStr);
# hdbc : void* in/out -> LPVOID
# szSqlStrIn : BYTE* -> LPVOID
# cbSqlStrIn : INT -> int
# szSqlStr : BYTE* optional, out -> LPVOID
# cbSqlStrMax : INT -> int
# pcbSqlStr : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い