ホーム › System.Search › SQLConnect
SQLConnect
関数DSN名とユーザー認証でデータソースに接続する。
シグネチャ
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLConnect(
void* ConnectionHandle,
BYTE* ServerName,
SHORT NameLength1,
BYTE* UserName,
SHORT NameLength2,
BYTE* Authentication,
SHORT NameLength3
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ConnectionHandle | void* | inout |
| ServerName | BYTE* | in |
| NameLength1 | SHORT | in |
| UserName | BYTE* | in |
| NameLength2 | SHORT | in |
| Authentication | BYTE* | in |
| NameLength3 | SHORT | in |
戻り値の型: SHORT
各言語での呼び出し定義
// ODBC32.dll (ANSI / -A)
#include <windows.h>
SHORT SQLConnect(
void* ConnectionHandle,
BYTE* ServerName,
SHORT NameLength1,
BYTE* UserName,
SHORT NameLength2,
BYTE* Authentication,
SHORT NameLength3
);[DllImport("ODBC32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern short SQLConnect(
IntPtr ConnectionHandle, // void* in/out
IntPtr ServerName, // BYTE*
short NameLength1, // SHORT
IntPtr UserName, // BYTE*
short NameLength2, // SHORT
IntPtr Authentication, // BYTE*
short NameLength3 // SHORT
);<DllImport("ODBC32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SQLConnect(
ConnectionHandle As IntPtr, ' void* in/out
ServerName As IntPtr, ' BYTE*
NameLength1 As Short, ' SHORT
UserName As IntPtr, ' BYTE*
NameLength2 As Short, ' SHORT
Authentication As IntPtr, ' BYTE*
NameLength3 As Short ' SHORT
) As Short
End Function' ConnectionHandle : void* in/out
' ServerName : BYTE*
' NameLength1 : SHORT
' UserName : BYTE*
' NameLength2 : SHORT
' Authentication : BYTE*
' NameLength3 : SHORT
Declare PtrSafe Function SQLConnect Lib "odbc32" ( _
ByVal ConnectionHandle As LongPtr, _
ByVal ServerName As LongPtr, _
ByVal NameLength1 As Integer, _
ByVal UserName As LongPtr, _
ByVal NameLength2 As Integer, _
ByVal Authentication As LongPtr, _
ByVal NameLength3 As Integer) As Integer
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SQLConnect = ctypes.windll.odbc32.SQLConnect
SQLConnect.restype = ctypes.c_short
SQLConnect.argtypes = [
ctypes.POINTER(None), # ConnectionHandle : void* in/out
ctypes.POINTER(ctypes.c_ubyte), # ServerName : BYTE*
ctypes.c_short, # NameLength1 : SHORT
ctypes.POINTER(ctypes.c_ubyte), # UserName : BYTE*
ctypes.c_short, # NameLength2 : SHORT
ctypes.POINTER(ctypes.c_ubyte), # Authentication : BYTE*
ctypes.c_short, # NameLength3 : SHORT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ODBC32.dll')
SQLConnect = Fiddle::Function.new(
lib['SQLConnect'],
[
Fiddle::TYPE_VOIDP, # ConnectionHandle : void* in/out
Fiddle::TYPE_VOIDP, # ServerName : BYTE*
Fiddle::TYPE_SHORT, # NameLength1 : SHORT
Fiddle::TYPE_VOIDP, # UserName : BYTE*
Fiddle::TYPE_SHORT, # NameLength2 : SHORT
Fiddle::TYPE_VOIDP, # Authentication : BYTE*
Fiddle::TYPE_SHORT, # NameLength3 : SHORT
],
Fiddle::TYPE_SHORT)#[link(name = "odbc32")]
extern "system" {
fn SQLConnect(
ConnectionHandle: *mut (), // void* in/out
ServerName: *mut u8, // BYTE*
NameLength1: i16, // SHORT
UserName: *mut u8, // BYTE*
NameLength2: i16, // SHORT
Authentication: *mut u8, // BYTE*
NameLength3: i16 // SHORT
) -> i16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ODBC32.dll", CharSet = CharSet.Ansi)]
public static extern short SQLConnect(IntPtr ConnectionHandle, IntPtr ServerName, short NameLength1, IntPtr UserName, short NameLength2, IntPtr Authentication, short NameLength3);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ODBC32_SQLConnect' -Namespace Win32 -PassThru
# $api::SQLConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3)#uselib "ODBC32.dll"
#func global SQLConnect "SQLConnect" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SQLConnect ConnectionHandle, varptr(ServerName), NameLength1, varptr(UserName), NameLength2, varptr(Authentication), NameLength3 ; 戻り値は stat
; ConnectionHandle : void* in/out -> "sptr"
; ServerName : BYTE* -> "sptr"
; NameLength1 : SHORT -> "sptr"
; UserName : BYTE* -> "sptr"
; NameLength2 : SHORT -> "sptr"
; Authentication : BYTE* -> "sptr"
; NameLength3 : SHORT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ODBC32.dll" #cfunc global SQLConnect "SQLConnect" sptr, var, int, var, int, var, int ; res = SQLConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3) ; ConnectionHandle : void* in/out -> "sptr" ; ServerName : BYTE* -> "var" ; NameLength1 : SHORT -> "int" ; UserName : BYTE* -> "var" ; NameLength2 : SHORT -> "int" ; Authentication : BYTE* -> "var" ; NameLength3 : SHORT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ODBC32.dll" #cfunc global SQLConnect "SQLConnect" sptr, sptr, int, sptr, int, sptr, int ; res = SQLConnect(ConnectionHandle, varptr(ServerName), NameLength1, varptr(UserName), NameLength2, varptr(Authentication), NameLength3) ; ConnectionHandle : void* in/out -> "sptr" ; ServerName : BYTE* -> "sptr" ; NameLength1 : SHORT -> "int" ; UserName : BYTE* -> "sptr" ; NameLength2 : SHORT -> "int" ; Authentication : BYTE* -> "sptr" ; NameLength3 : SHORT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; SHORT SQLConnect(void* ConnectionHandle, BYTE* ServerName, SHORT NameLength1, BYTE* UserName, SHORT NameLength2, BYTE* Authentication, SHORT NameLength3) #uselib "ODBC32.dll" #cfunc global SQLConnect "SQLConnect" intptr, var, int, var, int, var, int ; res = SQLConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3) ; ConnectionHandle : void* in/out -> "intptr" ; ServerName : BYTE* -> "var" ; NameLength1 : SHORT -> "int" ; UserName : BYTE* -> "var" ; NameLength2 : SHORT -> "int" ; Authentication : BYTE* -> "var" ; NameLength3 : SHORT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; SHORT SQLConnect(void* ConnectionHandle, BYTE* ServerName, SHORT NameLength1, BYTE* UserName, SHORT NameLength2, BYTE* Authentication, SHORT NameLength3) #uselib "ODBC32.dll" #cfunc global SQLConnect "SQLConnect" intptr, intptr, int, intptr, int, intptr, int ; res = SQLConnect(ConnectionHandle, varptr(ServerName), NameLength1, varptr(UserName), NameLength2, varptr(Authentication), NameLength3) ; ConnectionHandle : void* in/out -> "intptr" ; ServerName : BYTE* -> "intptr" ; NameLength1 : SHORT -> "int" ; UserName : BYTE* -> "intptr" ; NameLength2 : SHORT -> "int" ; Authentication : BYTE* -> "intptr" ; NameLength3 : SHORT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
odbc32 = windows.NewLazySystemDLL("ODBC32.dll")
procSQLConnect = odbc32.NewProc("SQLConnect")
)
// ConnectionHandle (void* in/out), ServerName (BYTE*), NameLength1 (SHORT), UserName (BYTE*), NameLength2 (SHORT), Authentication (BYTE*), NameLength3 (SHORT)
r1, _, err := procSQLConnect.Call(
uintptr(ConnectionHandle),
uintptr(ServerName),
uintptr(NameLength1),
uintptr(UserName),
uintptr(NameLength2),
uintptr(Authentication),
uintptr(NameLength3),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // SHORTfunction SQLConnect(
ConnectionHandle: Pointer; // void* in/out
ServerName: Pointer; // BYTE*
NameLength1: Smallint; // SHORT
UserName: Pointer; // BYTE*
NameLength2: Smallint; // SHORT
Authentication: Pointer; // BYTE*
NameLength3: Smallint // SHORT
): Smallint; stdcall;
external 'ODBC32.dll' name 'SQLConnect';result := DllCall("ODBC32\SQLConnect"
, "Ptr", ConnectionHandle ; void* in/out
, "Ptr", ServerName ; BYTE*
, "Short", NameLength1 ; SHORT
, "Ptr", UserName ; BYTE*
, "Short", NameLength2 ; SHORT
, "Ptr", Authentication ; BYTE*
, "Short", NameLength3 ; SHORT
, "Short") ; return: SHORT●SQLConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3) = DLL("ODBC32.dll", "int SQLConnect(void*, void*, int, void*, int, void*, int)")
# 呼び出し: SQLConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3)
# ConnectionHandle : void* in/out -> "void*"
# ServerName : BYTE* -> "void*"
# NameLength1 : SHORT -> "int"
# UserName : BYTE* -> "void*"
# NameLength2 : SHORT -> "int"
# Authentication : BYTE* -> "void*"
# NameLength3 : SHORT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。