CN103646047A - Method for VB to quickly access SQL database - Google Patents

Method for VB to quickly access SQL database Download PDF

Info

Publication number
CN103646047A
CN103646047A CN201310594905.1A CN201310594905A CN103646047A CN 103646047 A CN103646047 A CN 103646047A CN 201310594905 A CN201310594905 A CN 201310594905A CN 103646047 A CN103646047 A CN 103646047A
Authority
CN
China
Prior art keywords
dll
long
byval
function
sql
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201310594905.1A
Other languages
Chinese (zh)
Inventor
刘雨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
DALIAN HAILINK AUTOMATION Co Ltd
Original Assignee
DALIAN HAILINK AUTOMATION Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by DALIAN HAILINK AUTOMATION Co Ltd filed Critical DALIAN HAILINK AUTOMATION Co Ltd
Priority to CN201310594905.1A priority Critical patent/CN103646047A/en
Publication of CN103646047A publication Critical patent/CN103646047A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application

Abstract

The invention provides a method for VB to quickly access an SQL database. Aiming at using the VB to access the SQL database, an ODBC API function is called in a VB application program to carry out data grouping binding, so that system overhead and network transmission overhead caused by data conversion are reduced when the application program accesses the SQL database, and the application program can access the SQL database at a high speed.

Description

The method of VB fast access SQL database
A kind of method of VB fast access SQL database
The present invention is directed to and use this particular problem of VB access SQL database, in VB application program, call ODBCAPI function, carry out data and become group binding, when minimizing application program is visited vexed SQL database, system overhead and the Internet Transmission expense of data-switching, make application program high speed access SQL database.
For solving the problems of the technologies described above, technical scheme of the present invention is:
Because some parameter in the suction parameter table of ODBC api function need to be transmitted pointer, and VB supporting pointer not, therefore in VB, calling ODBC api function is subject to certain limitation.The string memory storage format of VB is different from C language, and ODBC api function C language development, this has also limited the exchanges data between VB and ODBC api function.Author analyzes ODBC api function, and the feature of comprehensive VB, writes a dynamic link library, can directly in VB, call ODBC api function, and can carry out exchanges data under the support of dynamic link library.
1, VC++6.0 exploitation dynamic link library
VC++6.0 can develop the dynamic link library of three types: Win32 DLL, conventional MFC DLL, expansion MFC DLL.Expansion MFC DLL supports C++ interface.In other words, DLL can derive whole class, and client can set up these classes or by the object of the class of its derivation.Win32DLL, conventional MFC DLL can be by Win32 programmed environment (comprising Visual Basic 6.0 editions) loading uses arbitrarily.Conventional MFC DLL must attach MFC42.DLL storehouse when distribution, and Win32DLL can issue separately.If only offer VB programmed environment, use, can set up Win32 DLL.
2, set up Win32 DLL
Utilize the AppWizard of VC++6.0 programmed environment to create a simple Win32 DLL engineering, engineering is called VBSQL, adds on this basis the code of oneself.Code is as follows:
#include“stdafx.h”
#include<string.h>
#define DLLEXPORT extern " C " _ declspec (dllexport) // definition is derived grand
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,
LPVOID lpReserved)
{ switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TURE;
}
DLLEXPORT long_stdcall GetAddress (void*Address) // transmit by address
{ return (long) Address}; // long shaping is forced to be converted in address
DLLEXPORT long_stdcall strCopyToByte(char*BytesAddress, char*strAddress)
{
return(long)strcpy(BytesAddress, strAddress)
; // character string is sent to assigned address
Through compiling link, generate VBSQLDLL dynamic link library, copied to C: WINDOWS under system directory, so just can in VB, call.Utilize Microsoft Visual Studio 6.0 tool software Depends to check the function name deriving in VBSQLDLL.
3, in VB, state external function
In module file, do following statement:
VBSQL.DLL function declaration:
Public Declare GetAddress Lib“VBSQL.DLL” Alias “_GetAddress@4” (ByRefAddress as Any) as Long
Public Declare strCopyToByte Lib“VBSQL.DLL” Alias “_strCopyToByte@8” (ByRefByte ArrayAdd ress as Any) as Long
With reference to sql.h, constant and function declaration in sqltypes.h header file, transfer its content to VB assertion format.Due to ODBCAPI function and constant more, at this, can not enumerate.
Type identification constant:
Public Const SQL_IS_POINTER=(-4)
Public Const SQL_IS_UINTEGER=(-5)
SQL data type constant
Public Const SQL_CHAR=1
Public Const SQL_FLOAT=6
SQL C type constant
Public Const SQL_C_CHAR=SQL_CHAR
Public Const SQL_C_FLOAT=SQL_REAL
Function declaration
Public Declare Function SQLSetStrntAttr Lib“odbe32.dll”
(ByVal StatementHandle As Long, ByVal Attributes As Long, ByVal ValuePtr As Long. ByVal StringLength As Long)As Integer
Public Declare Function SQLBindParame Lib“odbe32.dll”
(ByVal StatementHandle As Long, ByVal ParameterNumber As Integer, ByVal Inputoutput Type As Integer, ByVal ValueType As Integer, ByVal ParameterNumber As Integer, ByVal ColumnSize As Long, ByVal DecimalDigits As Integer, ByRef Parameter ValuePtr As Any, ByVal BufferLength As Long, ByRef StrLen_or_IndPtr As Any)As Intrger
Public Declare Function SQLExecDirect Lib “odbc32.dll”(ByVal StatementHandle As Long, ByVal StatementText As String, ByVal TextLength As long)As Long
Public Declare Function SQLEXecute Lib “odbc32.dll”(ByVal StatementHandle As long)As Long
The wherein variable pass by value after ByVal keyword, the variable after ByRef keyword transmits by address.
4, VB calls external function
After statement, in VB, can as calling other VB functions, call these functions.In the parameter list of attention ODBC api function, some variable is a VOID type pointer, by sign constant, identifies.As:
The 3rd parameter (SQLPOINTER Value) of SQLSetStmtAttr function he can transmit numerical value and also can transmit address, by the 4th parameter (SQLINTEGER StringLength), identify, be (ValuePtr As Long) in VB.
Transmit numerical value: Call SQLSetStmtAttr (statement handles, attribute, property value, SQL_IS_UINTEGER)
Transmit address: Call SQLSetStmtAttr (statement handles, attribute, GetAddress (variable), 0) GetAddress gets address by as above regular, directly calls ODBC api function in VB.
Compared with prior art, the invention has the beneficial effects as follows:
1), in the actual debugging of native system, with about time that needs 1 second of 720 data of ADO renewal.Utilize method herein, in VB, call ODBC api function, and carry out burst data binding, upgrade same data and be about 0.1 second, greatly accelerate the speed of access SQL.
2), " Subsystem in Marine Engine Simulator based on virtual reality " is the distributing emulation system centered by SQL database.By l platform sql database server, 14 estrade system emulation computing machines, (client computer, switchboard industrial computer, machine control platform industrial computer, trainer's computing machine (monitoring equipment) and 15 student's computing machines form Fast Ethernet by the 100M network switch to native system.Subsystem need be uploaded real-time simulation data high-speed to database, and other subsystem and machine for student also need the required emulated data of high-speed downloads.Therefore how to accelerate accessing database, reduce network traffics, each subsystem real time high-speed exchange emulated data is that this distributing emulation system is successfully crucial.This invention is achieved the fast access between each system of simulator.

Claims (1)

1. because some parameter in the suction parameter table of ODBC api function need to be transmitted pointer, and VB supporting pointer not, therefore in VB, calling ODBC api function is subject to certain limitation; The string memory storage format of VB is different from C language, and ODBC api function C language development, this has also limited the exchanges data between VB and ODBC api function; Author analyzes ODBC api function, and the feature of comprehensive VB, writes a dynamic link library, can directly in VB, call ODBC api function, and can carry out exchanges data under the support of dynamic link library;
VC++6.0 develops dynamic link library
VC++6.0 can develop the dynamic link library of three types: Win32 DLL, conventional MFC DLL, expansion MFC DLL;
Expansion MFC DLL supports C++ interface;
In other words, DLL can derive whole class, and client can set up these classes or by the object of the class of its derivation; Win32DLL, conventional MFC DLL can be by Win32 programmed environment (comprising Visual Basic 6.0 editions) loading uses arbitrarily; Conventional MFC DLL must attach MFC42.DLL storehouse when distribution, and Win32DLL can issue separately; If only offer VB programmed environment, use, can set up Win32 DLL;
Set up Win32 DLL
Utilize the AppWizard of VC++6.0 programmed environment to create a simple Win32 DLL engineering, engineering is called VBSQL, adds on this basis the code of oneself; Code is as follows:
#include“stdafx.h”
#include<string.h>
#define DLLEXPORT extern " C " _ declspec (dllexport) // definition is derived grand
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,
LPVOID lpReserved)
{ switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TURE;
}
DLLEXPORT long_stdcall GetAddress (void*Address) // transmit by address
{ return (long) Address}; // long shaping is forced to be converted in address
DLLEXPORT long_stdcall strCopyToByte(char*BytesAddress, char*strAddress)
{
return(long)strcpy(BytesAddress, strAddress)
; // character string is sent to assigned address
Through compiling link, generate VBSQLDLL dynamic link library, copied to C: WINDOWS under system directory, so just can in VB, call; Utilize Microsoft Visual Studio 6.0 tool software Depends to check the function name deriving in VBSQLDLL;
In VB, state external function
In module file, do following statement:
VBSQL.DLL function declaration:
Public Declare GetAddress Lib“VBSQL.DLL” Alias “_GetAddress@4” (ByRefAddress as Any) as Long
Public Declare strCopyToByte Lib“VBSQL.DLL” Alias “_strCopyToByte@8” (ByRefByte ArrayAdd ress as Any) as Long
With reference to sql.h, constant and function declaration in sqltypes.h header file, transfer its content to VB assertion format;
Due to ODBCAPI function and constant more, at this, can not enumerate;
Type identification constant:
Public Const SQL_IS_POINTER=(-4)
Public Const SQL_IS_UINTEGER=(-5)
SQL data type constant
Public Const SQL_CHAR=1
Public Const SQL_FLOAT=6
SQL C type constant
Public Const SQL_C_CHAR=SQL_CHAR
Public Const SQL_C_FLOAT=SQL_REAL
Function declaration
Public Declare Function SQLSetStrntAttr Lib“odbe32.dll”
(ByVal StatementHandle As Long, ByVal Attributes As Long, ByVal ValuePtr As Long. ByVal StringLength As Long)As Integer
Public Declare Function SQLBindParame Lib“odbe32.dll”
(ByVal StatementHandle As Long, ByVal ParameterNumber As Integer, ByVal Inputoutput Type As Integer, ByVal ValueType As Integer, ByVal ParameterNumber As Integer, ByVal ColumnSize As Long, ByVal DecimalDigits As Integer, ByRef Parameter ValuePtr As Any, ByVal BufferLength As Long, ByRef StrLen_or_IndPtr As Any)As Intrger
Public Declare Function SQLExecDirect Lib “odbc32.dll”(ByVal StatementHandle As Long, ByVal StatementText As String, ByVal TextLength As long)As Long
Public Declare Function SQLEXecute Lib “odbc32.dll”(ByVal StatementHandle As long)As Long
The wherein variable pass by value after ByVal keyword, the variable after ByRef keyword transmits by address;
VB calls external function
After statement, in VB, can as calling other VB functions, call these functions; In the parameter list of attention ODBC api function, some variable is a VOID type pointer, by sign constant, identifies; As:
The 3rd parameter (SQLPOINTER Value) of SQLSetStmtAttr function he can transmit numerical value and also can transmit address, by the 4th parameter (SQLINTEGER StringLength), identify, be (ValuePtr As Long) in VB;
Transmit numerical value: Call SQLSetStmtAttr (statement handles, attribute, property value, SQL_IS_UINTEGER)
Transmit address: Call SQLSetStmtAttr (statement handles, attribute, GetAddress (variable), 0) GetAddress gets address by as above regular, directly calls ODBC api function in VB.
CN201310594905.1A 2013-11-25 2013-11-25 Method for VB to quickly access SQL database Pending CN103646047A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310594905.1A CN103646047A (en) 2013-11-25 2013-11-25 Method for VB to quickly access SQL database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310594905.1A CN103646047A (en) 2013-11-25 2013-11-25 Method for VB to quickly access SQL database

Publications (1)

Publication Number Publication Date
CN103646047A true CN103646047A (en) 2014-03-19

Family

ID=50251261

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310594905.1A Pending CN103646047A (en) 2013-11-25 2013-11-25 Method for VB to quickly access SQL database

Country Status (1)

Country Link
CN (1) CN103646047A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106055363A (en) * 2016-05-31 2016-10-26 广东欧珀移动通信有限公司 Method for identifying file and mobile terminal

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106055363A (en) * 2016-05-31 2016-10-26 广东欧珀移动通信有限公司 Method for identifying file and mobile terminal
US10452376B2 (en) 2016-05-31 2019-10-22 Guangdong Oppo Mobile Telecommunications Corp., Ltd. Method for identifying file and mobile terminal
US10599413B2 (en) 2016-05-31 2020-03-24 Guangdong Oppo Mobile Telecommunications Corp., Ltd. Method and device for identifying file

Similar Documents

Publication Publication Date Title
CN107291444B (en) PLC instruction generation method and device and PLC programming method
US8726298B1 (en) Cloud-based instrument driver system
US20030226110A1 (en) Method for dynamically generating structured documents
WO2007032912A1 (en) Initial server-side content rendering for client-script web pages
CN110377283B (en) Method for realizing and synchronizing front-end effective data during Web front-end and back-end separation development
CN103927193B (en) Loading method, service end virtual machine during the migration operation of java application function
CN103631578B (en) Method for exhibiting data in a kind of distribution automation system
CN105653268A (en) Rule engine debugging method and rule engine debugging system
CN107505851A (en) Ovation control analogue systems and emulation mode based on Rinsim platforms
CN104991810B (en) Method and processing system in automatic addition APK to Android system
CN103051711B (en) Based on the construction method of the embedded cloud terminal system of SPICE agreement
CN105871961B (en) A kind of method and device of gray scale publication routing
CN110851123A (en) WebGIS power grid visualization framework construction method, system and device based on SpringMVC
CN103646047A (en) Method for VB to quickly access SQL database
CN102231164A (en) Extensible makeup language (XML) incremental transmission and interaction method for multidisciplinary virtual experiment platform
CN114050909B (en) Exercise method, system and electronic equipment for simulating mail
CN102750183B (en) Numerical simulation open-type application program interface of electric power system
CN115168358A (en) Database access method and device, electronic equipment and storage medium
CN109408577A (en) ORACLE database JSON analytic method, system, device and can storage medium
CN105491104A (en) Remote measurement and control method based on Web Service
CN104408085A (en) Method for quickly viewing report
CN110853327B (en) Ship cabin equipment data field debugging and collecting method and device based on single chip microcomputer
CN103049615A (en) Graph-based real-time simulation modeling method for control logics of engineering machine
CN103955424A (en) Virtualized embedded type binary software defect detection system
CN105488147A (en) Persistence method based on SQL (Structured Query Language) template

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20140319