'd_odbc - схема
'd_login - логин
'd_pwd - пароль
Dim odbc As New ODBCClass
If odbc.Connect(d_odbc, d_login, d_pwd) Then
End If
Option Public
Option Declare
Uselsx "*LSXODBC"
Class ODBCClass
Public CON As ODBCConnection
Public QRY As ODBCQuery
Public RS As ODBCResultSet
Private fmtDate As String
Public ROW List As String 'список значений в строке
Sub InitQry
Set RS = Nothing
Set QRY = Nothing
End Sub
Sub New
fmtDate = "dd-mm-yyyy"
Call InitQry
End Sub
Sub Delete
Call Disconnect
End Sub
Function Connect(dsn As String, userid As String, pwd As String) As Boolean
Set CON = New ODBCConnection
CON.SilentMode = True
If CON.ConnectTo(dsn, userid, pwd) Then
Connect = True
Else
Connect=False
Messagebox |Неможливо під'єднатися до бази "| & dsn & |".|
End If
End Function
Sub Disconnect
If Not (CON Is Nothing) Then
If CON.IsConnected Then CON.Disconnect
End If
End Sub
Function FieldValue(FieldName As String) As Variant
On Error Goto err1
FieldValue = ROW("<"+Ucase(FieldName)+">")
Exit Function
err1:
Msgbox("Помилка виконання запиту або дані не існують.")
Resume Next
End Function
Function GetDataType(typeConst As Integer) As String
Select Case typeConst
Case SQL_CHAR : GetDataType = "CHAR"
Case SQL_NUMERIC : GetDataType = "NUMERIC"
Case SQL_DECIMAL : GetDataType = "DECIMAL"
Case SQL_INTEGER : GetDataType = "INTEGER"
Case SQL_SMALLINT : GetDataType = "SMALLINT"
Case SQL_FLOAT : GetDataType = "FLOAT"
Case SQL_REAL : GetDataType = "REAL"
Case SQL_DOUBLE : GetDataType = "DOUBLE"
Case SQL_DATE : GetDataType = "DATE"
Case SQL_TIME : GetDataType = "TIME"
Case SQL_TIMESTAMP : GetDataType = "TIMESTAMP"
Case SQL_VARCHAR : GetDataType = "VARCHAR"
Case SQL_BINARY : GetDataType = "BINARY"
Case SQL_VARBINARY : GetDataType = "VARBINARY"
Case SQL_LONGVARCHAR : GetDataType = "LONGVARCHAR"
Case SQL_LONGVARBINARY : GetDataType = "LONGVARBINARY"
Case SQL_BIGINT : GetDataType = "BIGINT"
Case SQL_TINYINT : GetDataType = "TINYINT"
Case SQL_BIT : GetDataType = "BIT"
End Select
End Function
Function RunQry(qry_text As String) As Integer
Dim i As Integer
Set QRY = New ODBCQuery
Set QRY.Connection = CON
QRY.SQL = qry_text
Set RS = New ODBCResultSet
Set RS.Query = QRY
RS.Execute
' Msgbox "rows = " & Cstr(odbc_rs.NumRows)
Erase ROW
If RS.NumRows <> 0 Then
For i = 1 To RS.NumColumns
'For i = 1 To RS.NumRows
Select Case RS.FieldNativeDataType(i)
Case SQL_DATE:
ROW("<"+Ucase(RS.FieldName(i))+">") = Format(RS.GetValue(i), fmtDate)
Case SQL_NUMERIC,_
SQL_DECIMAL,_
DB_DOUBLE,_
SQL_INTEGER,_
SQL_SMALLINT,_
SQL_FLOAT,_
SQL_REAL,_
SQL_DOUBLE:
Case Else: ROW("<"+Ucase(RS.FieldName(i))+">") = RS.GetValue(i)
End Select
Next
End If
RunQry = RS.NumRows
RS.Close(DB_CLOSE)
End Function
End Class