Public Function UDB(DBC1 As ADODB.Connection, _
DBC2 As ADODB.Connection, dbname1 As String, dbname2 As String, _
DBT, DoEdits As Integer, suffix, prefix As String, Progress As ProgressBar, _
lbl1 As label) As Boolean
DoEvents
Dim DBrs As ADODB.Recordset, DBrs2 As ADODB.Recordset
Dim DBrs1 As ADODB.Recordset, DBrs3 As ADODB.Recordset
Dim strSQL, IsFound As Boolean, extracheck As Boolean
On Error GoTo UDerr
Set DBrs = New ADODB.Recordset
DBrs.ActiveConnection = DBC1
Set DBrs2 = New ADODB.Recordset
DBrs2.ActiveConnection = DBC2
Select Case DBT
Case "MySQL"
DBrs2.Open "SHOW TABLES WHERE Tables_in_" & dbname2 & _
" LIKE '" & prefix & "%'"
Do While Not DBrs2.EOF
DBrs.Open "SHOW TABLES WHERE Tables_in_" & dbname1 & _
"='" & DBrs2("Tables_in_" & dbname2) & suffix & "'"
If Not DBrs.EOF Then
DBrs.Close
Set DBrs1 = New ADODB.Recordset
DBrs1.ActiveConnection = DBC2
DBrs1.Open "DESCRIBE " & DBrs2("Tables_in_" & dbname2)
Do While Not DBrs1.EOF
Set DBrs3 = New ADODB.Recordset
DBrs3.ActiveConnection = DBC1
DBrs.Open "DESCRIBE " & DBrs2("Tables_in_" & dbname2) _
& suffix
IsFound = False
extracheck = False
Do While Not DBrs.EOF
If DBrs("Field") = DBrs1("Field") Then
IsFound = True
If DBrs("Type") = DBrs1("Type") And DBrs("Null") _
= DBrs1("Null") And DBrs("Default") = DBrs1("Default") And DBrs("Key") = _
DBrs1("Key") And DBrs("Extra") = DBrs1("Extra") Then extracheck = True
End If
DBrs.MoveNext
Loop
DBrs.Close
If IsFound Then
If DoEdits = 0 Then
If DBrs1("Key") <> "PRI" Then
If Not extracheck Then
lbl1.Caption = "Updating Current Column: " & _
DBrs2("Tables_in_" & dbname2) & suffix & "." & DBrs1("Field")
Progress.value = Progress.value + 1
strSQL = "ALTER TABLE " & DBrs2("Tables_in_" & _
dbname2) & suffix & " MODIFY " & DBrs1("Field") & " " & " " & _
DBrs1("Type") & " "
If DBrs1("Null") = "NO" Then strSQL = strSQL & _
"NOT NULL "
If DBrs1("Default") <> "" Then strSQL = _
strSQL & "DEFAULT '" & DBrs1("Default") & "'"
DBrs3.Open strSQL
End If
End If
End If
Else
lbl1.Caption = "Adding Column to Current Table: " & _
DBrs2("Tables_in_" & dbname2) & suffix & "." & DBrs1("Field")
Progress.value = Progress.value + 1
strSQL = "ALTER TABLE " & DBrs2("Tables_in_" & _
dbname2) & suffix & " ADD COLUMN " & DBrs1("Field") & " " & " " & _
DBrs1("Type") & " "
If DBrs1("Null") = "NO" Then strSQL = strSQL & _
"NOT NULL "
If DBrs1("Default") <> "" Then strSQL = strSQL _
& "DEFAULT '" & DBrs1("Default") & "' "
If DBrs1("Key") = "PRI" Then strSQL = strSQL _
& "PRIMARY KEY "
If DBrs1("Extra") = "auto_increment" Then strSQL = _
strSQL & "AUTO_INCREMENT"
DBrs3.Open strSQL
End If
DBrs1.MoveNext
Loop
Else
DBrs.Close
lbl1.Caption = "Adding Table: " & DBrs2("Tables_in_" & _
dbname2) & suffix
Progress.value = Progress.value + 1
strSQL = "CREATE TABLE " & DBrs2("Tables_in_" & dbname2) _
& suffix & " ("
Set DBrs1 = New ADODB.Recordset
DBrs1.ActiveConnection = DBC2
DBrs1.Open "DESCRIBE " & DBrs2("Tables_in_" & dbname2)
Do While Not DBrs1.EOF
strSQL = strSQL & DBrs1("Field") & " " & DBrs1("Type") & " "
If DBrs1("Null") = "NO" Then strSQL = strSQL & "NOT NULL "
If DBrs1("Default") <> "" Then strSQL = strSQL _
& "DEFAULT '" & DBrs1("Default") & "' "
If DBrs1("Key") = "PRI" Then strSQL = strSQL & _
"PRIMARY KEY "
If DBrs1("Extra") = "auto_increment" Then strSQL = _
strSQL & "AUTO_INCREMENT"
strSQL = strSQL & ","
DBrs1.MoveNext
Loop
strSQL = Mid(strSQL, 1, Len(strSQL) - 1) & ")"
DBrs.Open strSQL
End If
DBrs2.MoveNext
Loop
End Select
UDB = True
Progress.value = Progress.value + 1
lbl1.Caption = "Database Section Updated: - " & prefix
Exit Function
UDerr:
UDB = False
End Function