<%
Dim conn, db
Dim ConnStr
db = "/data/JumbotCMS.mdb"
Call OpenConn

Dim adoRS, strSQL

'=====================================================================================
'Update V2.3
'=====================================================================================
If Not IsExistsTable("Jbsite_ForbidIP") Then
        strSQL = "CREATE TABLE [Jbsite_ForbidIP] (" & vbCrLf
        strSQL = strSQL & "ID AutoIncrement primary key , " & vbCrLf
        strSQL = strSQL & "StartIP double, " & vbCrLf
        strSQL = strSQL & "EndIP double, " & vbCrLf
        strSQL = strSQL & "ExpireDate datetime" & vbCrLf
        strSQL = strSQL & ")" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_ForbidIP]===============>创建成功!<br />")
End If
'=====================================================================================
'Update V2.4
'=====================================================================================
If Not IsExistsField("Jbsite_Article", "Correlation") Then
        strSQL = "alter TABLE Jbsite_Article Add Correlation varchar(100)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Article]===============>字段[Correlation]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Article]===============>字段[Correlation]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Article", "UserId") Then
        strSQL = "alter TABLE Jbsite_Article Add UserId int" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        strSQL = "Update Jbsite_Article Set UserId=0" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Article]===============>字段[UserId]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Article]===============>字段[UserId]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Photo", "Editor") Then
        strSQL = "alter TABLE Jbsite_Photo Add Editor varchar(20)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Photo]===============>字段[Editor]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Photo]===============>字段[Editor]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Photo", "Tags") Then
        strSQL = "alter TABLE Jbsite_Photo Add Tags varchar(60)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Photo]===============>字段[Tags]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Photo]===============>字段[Tags]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Photo", "Correlation") Then
        strSQL = "alter TABLE Jbsite_Photo Add Correlation varchar(100)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Photo]===============>字段[Correlation]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Photo]===============>字段[Correlation]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Photo", "UserId") Then
        strSQL = "alter TABLE Jbsite_Photo Add UserId int" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        strSQL = "Update Jbsite_Photo Set UserId=0" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Photo]===============>字段[UserId]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Photo]===============>字段[UserId]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Soft", "Editor") Then
        strSQL = "alter TABLE Jbsite_Soft Add Editor varchar(20)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Soft]===============>字段[Editor]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Soft]===============>字段[Editor]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Soft", "Tags") Then
        strSQL = "alter TABLE Jbsite_Soft Add Tags varchar(60)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Soft]===============>字段[Tags]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Soft]===============>字段[Tags]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Soft", "Correlation") Then
        strSQL = "alter TABLE Jbsite_Soft Add Correlation varchar(100)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Soft]===============>字段[Correlation]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Soft]===============>字段[Correlation]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Soft", "UserId") Then
        strSQL = "alter TABLE Jbsite_Soft Add UserId int" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        strSQL = "Update Jbsite_Soft Set UserId=0" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_Soft]===============>字段[UserId]创建成功!<br />")
Else
        Response.Write("表[Jbsite_Soft]===============>字段[UserId]已存在!<br />")
End If
If Not IsExistsField("Jbsite_Master", "LastTime") Then
        Call ChangeFieldName("Jbsite_Master", "Lastime", "LastTime")
End If
If Not IsExistsField("Jbsite_User", "LastTime") Then
        Call ChangeFieldName("Jbsite_User", "Lastime", "LastTime")
End If
If Not IsExistsField("Jbsite_User", "TrueName") Then
        Call ChangeFieldName("Jbsite_User", "Username", "TrueName")
End If
If Not IsExistsField("Jbsite_User", "Group") Then
        Call ChangeFieldName("Jbsite_User", "User_Group", "Group")
End If
If Not IsExistsField("Jbsite_User", "UserPass") Then
        Call ChangeFieldName("Jbsite_User", "Reg_Pass", "UserPass")
End If
If Not IsExistsField("Jbsite_User", "UserName") Then
        Call ChangeFieldName("Jbsite_User", "Reg_Name", "UserName")
End If
'=====================================================================================
'Update V2.5
'=====================================================================================
If Not IsExistsField("Jbsite_CollItem", "ListWebEncode") Then
        strSQL = "alter TABLE Jbsite_CollItem Add ListWebEncode varchar(50)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        strSQL = "Update Jbsite_CollItem Set ListWebEncode=WebEncode" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_CollItem]===============>字段[ListWebEncode]创建成功!<br />")
End If
If Not IsExistsField("Jbsite_CollItem", "ContentWebEncode") Then
        strSQL = "alter TABLE Jbsite_CollItem Add ContentWebEncode varchar(50)" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        strSQL = "Update Jbsite_CollItem Set ContentWebEncode=WebEncode" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_CollItem]===============>字段[ContentWebEncode]创建成功!<br />")
End If
If IsExistsField("Jbsite_CollItem", "WebEncode") Then
        strSQL = "alter TABLE Jbsite_CollItem drop WebEncode" & vbCrLf
        Set adoRS = Conn.Execute(strSQL)
        Response.Write("表[Jbsite_CollItem]===============>字段[WebEncode]删除成功!<br />")
End If
'=====================================================================================
Call CloseConn
'=====================================================================================

Sub OpenConn()
        On Error Resume Next
        ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
        Set conn = Server.CreateObject("ADODB.Connection")
        conn.Open ConnStr
        If Err Then
                Err.Clear
                Set conn = Nothing
                Response.Write "数据库连接出错。"
                Response.End
        End If
End Sub

Sub CloseConn()
        On Error Resume Next
        If IsObject(conn) Then
                conn.Close
                Set conn = Nothing
        End If
End Sub

''===========================================
''功能：是否存在字段名
''===========================================

Public Function IsExistsField(tableName, fieldName)
        On Error Resume Next
        IsExistsField = True
        Conn.Execute ("SELECT [" & fieldName & "] FROM [" & tableName & "]")
        If Err Then
                IsExistsField = False
                Err.Clear
        End If
End Function

''===========================================
''功能：是否存在数据表
''===========================================

Public Function IsExistsTable(tableName)
        On Error Resume Next
        IsExistsTable = True
        Conn.Execute ("SELECT * FROM [" & tableName & "]")
        If Err Then
                IsExistsTable = False
                Err.Clear
        End If
End Function

''===========================================
''功能：修改表名
''===========================================

Public Function RenameTableName(OldName, NewName)
        If (IsExistsTable(OldName) And (OldName<>NewName)) Then
                Dim oCat, oTbl
                Set oCat = Server.CreateObject("ADOX.Catalog")
                oCat.ActiveConnection = ConnStr
                Set oTbl = Server.CreateObject("ADOX.Table")
                Set oTbl = oCat.Tables(OldName)
                oTbl.Name = NewName
                Set oTbl = Nothing
                Set oCat = Nothing
        End If
End Function

''===========================================
''功能：修改字段名
''===========================================

Public Function ChangeFieldName(MyTableName, MyFieldName, strNewName)
        Dim oCat, oTbl
        Set oCat = Server.CreateObject("ADOX.Catalog")
        oCat.ActiveConnection = ConnStr
        Set oTbl = Server.CreateObject("ADOX.Table")
        Set oTbl = oCat.Tables(MyTableName)
        oTbl.Columns(MyFieldName).Name = strNewName
        Set oTbl = Nothing
        Set oCat = Nothing
End Function
%>
