Custom variables and functions commonly used in several modules

xiaoxiao2021-04-10  426

Const module:

'Database Access Constant

Public const SQL_C_CHAR AS long = 1

Public const SQL_COLUMN_LABEL AS long = 18

Public const SQL_DROP AS long = 1

Public const SQL_ERROR As long = -1

Public const SQL_NO_DATA_FOUND As long = 100

Public const SQL_SUCCESS AS long = 0

Public const SQL_ATTR_MAX_LENGTH AS long = 100

Public const SQL_SUCCESS_WITH_INFO AS long = 1

Public const vernum as string = "Version 1.0.01"

Public const gendate as string = "Date 2006-6-25"

'Data source information constant

Public const data as string = "newdb"

Public const dsn as string = "newdb"

Public const db_user_name as string = "sa"

Public const db_password as string = "123"

Public const connect_loop_max = 10

DBFunction module:

Public Declare Function SQLAllocenv LIB "ODBC32.DLL" (Phenv &) AS INTEGER

Public Declare Function SQLACCONNECT LIB "odbc32.dll" (Byval Henv &, PhDBC &) AS INTEGER

Public Declare Function SQLAllocStmt LIB "ODBC32.DLL" (Byval HDBC &, PhStmt &) AS Integer

Public Declare Function Sqlconnect lib "odbc32.dll" (Byval HDBC &, BYVAL SZDSN $, BYVAL CBDSN%, BYVAL SZUID $, BYVAL CBUID%, Byval Szauthstr $, BYVAL CBAUTHSTR%) AS INTEGER

Public Declare Function SQLColAttributesString Lib "odbc32.dll" Alias ​​"SQLColAttributes" (ByVal Hstmt &, ByVal icol%, ByVal fDescType%, ByVal rgbDesc As String, ByVal cbDescMax%, pcbDesc%, pfDesc &) As Integer

Public Declare Function SqldisConnect lib "odbc32.dll" (Byval HDBC &) AS Integer

Public Declare Function SQLExecDirect Lib "odbc32.dll" (ByVal Hstmt &, ByVal szSqlStr $, ByVal cbSqlStr &) As IntegerPublic Declare Function SQLFetch Lib "odbc32.dll" (ByVal Hstmt &) As Integer

Public Declare Function SQLFreeConnect lib "odbc32.dll" (Byval HDBC &) AS INTEGER

Public Declare Function SQLFreeEnv lib "odbc32.dll" (Byval Henv &) AS Integer

Public Declare Function SQLFreeStmt LIB "ODBC32.DLL" (Byval Hstmt &, Byval FOPTION%) AS Integer

Public Declare Function Sqlgetdata lib "odbc32.dll" (Byval Hstmt &, Byval Icol%, Byval FcType%, Byval RGBValue As String, Byval Cbvaluemax &, PCBVALUE &) AS INTEGER

Public Declare Function SqlnumResultcols lib "odbc32.dll" (Byval Hstmt &, Pccol%) AS Integer

'Database Access Constant

Public const SQL_C_CHAR AS long = 1

Public const SQL_COLUMN_LABEL AS long = 18

Public const SQL_DROP AS long = 1

Public const SQL_ERROR As long = -1

Public const SQL_NO_DATA_FOUND As long = 100

Public const SQL_SUCCESS AS long = 0

Public const SQL_ATTR_MAX_LENGTH AS long = 100

'Declared Variables Private Isconnect As Booleanprivate Connect_num As INTEGERPRIVATE HENV AS Longprivate HDBC As LongPrivate RC As Longprivate HSTMT As Long

'Custom Database Operation Function Private Sub Connect () DIM TMPSTAT AS STRING' SQLCONNECT () Return Value 'If the connection tag is true, then return, otherwise it will be error ISCONNECT = True Thenexit subend if' assigns environment handles, save In the variable henv, if Sqlallocenv (HENV), "ODBC API Execute Error", "ODBC API Execute Error" end ', according to the connection handle, data source, username, and password connection, the specified database TmpStat = SqlConnect (HDBC, DSN, LEN (DSN), DB_USER_NAME, lench (DB_USER_NAME), DB_PASSWORD, Len (DB_PASSWORD)) 'if the connection is not successful then exit the program If TmpStat <> SQL_SUCCESS And TmpStat <> SQL_SUCCESS_WITH_INFO ThenMsgBox "can not get a handle!",, "ODBC API execution errors "ISconnect = truedisconnectendendendenect = trueDisnectendendendendendnect = trueDisnectendendendenect = trueend sub 'Disconnects to the database private () DIM RC As long' If the connection is marked as a fake, then the connection has been disconnected, then return if isconnect = false the thenexit subend if 'disconnected Connection RC = Sqldisconnect (HDBC) 'Release Connection Handle RC = SQLFreeConnect (HDBC)' Release Environment Handle RC = SQLFreeEnv (HENV) Isconnect = Falseend Sub

'Use connection_num Control Database Connection Public Sub DB_CONNECT () Connect_Num = Connect_Num 1connectend Sub

'Disconnect Database Connection Function DB_Disconnect () Public Sub DB_Disconnect () if connect_num> = connect_loop_max thenconnect_num = 0disconnectend iFend Sub

'Forced off the database API access counter resets Public Sub DBapi_Disconnect () Connect_Num = 0disconnectEnd Sub' execution of ODBC database manipulation statements Public Sub ODBCExt (ByVal TmpSQLstmt As String) 'according to the connection handle assigned statement handles If SQLAllocStmt (Hdbc, Hstmt) ThenMSGBOX "Handle Assignment Fail", "ODBC API Execute Error" DBAPI_DISCONNECTENDEND IF 'Executes SQL statement, Lench is a user-defined function, calculates a string length if SQLEXECDirect (HSTMT, TMPSQLSTMT, LENCH (TMPSQLSTMT)) "" Database Access Statement Failure "," ODBC API Execution Error "MSGBOX TMPSQLSTMTDBAPI_DISCONNECTENDEND IF

End Sub

GeneralFunc module (user-defined function):

转载请注明原文地址:https://www.9cbs.com/read-133230.html

New Post(0)