<!--#include file="conn.asp"-->
<!--#include file="inc/class_blog.asp"-->
<html>
<body style="font-size:14px">
oBlog3.0 ==> oBlog3.1 Access数据库升级程序
<BR/>
<BR/>
最后更新时间：2005年11月1日 1:11
<BR/>
<BR/>
============================================
<BR/>
<BR/>
<%
'On error Resume Next
Dim strSql,strErrMsg,strNow
If is_sqldata=1 Then 
	strNow="getdate()"
Else
	strNow="now()"
End If
Call Link_Database

'删除旧表
Call Execute("Drop Table oblog_photo_save")
Call Execute("Drop Table oblog_subject_save")
Call Execute("Drop Table oblog_message_save")
'恢复归档文件
Call Execute("Update oblog_message Set issave=0")
Call Execute("Update oblog_log Set issave=0")
Call Execute("Update oblog_upfile Set issave=0")
If strErrMsg<>"" Then
	Echo  "<font color=red>归档表删除失败</font>:<BR/>" & strErrMsg &"<BR/><BR/>" 
Else
	Echo  "<font color=green>归档表删除成功</font><BR/><BR/>" 
End If
strErrMsg=""

'建立新表
strSql="Create Table oblog_tags("& _
		"TagId  int IDENTITY (1, 1) NOT NULL CONSTRAINT PK_oblog_tags PRIMARY KEY," & _
		"Name varchar (255) Not NULL ," & _
		"iClass int NOT NULL default 0 ," & _
		"iNum int NOT NULL default 0 ," & _
		"iType int NOT NULL default 0 ," & _
		"iState int NOT NULL default 1 ," & _
		"LastUpdate smalldatetime NOT NULL default "&strNow&" )" 
Call Execute(strSql)
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_tags 创建失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_tags 创建成功</font><BR/><BR/>" 
End If
strErrMsg=""

strSql="Create Table oblog_usertags("	& _
		"UserTagId  int IDENTITY (1, 1) NOT NULL CONSTRAINT PK_oblog_usertags PRIMARY KEY," & _
		"TagId int NOT NULL default 0 ," & _
		"UserId int NOT NULL default 0 ," & _
		"logId int NOT NULL default 0 ," & _
		"iNum int NOT NULL default 1 )" 
Call Execute(strSql)
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_usertags 创建失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_usertags 创建成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("CREATE INDEX Index_tags_tagid ON oblog_tags (TagId)")				
Call Execute("CREATE INDEX Index_usertags_tagid ON oblog_usertags (TagId)")
Call Execute("CREATE INDEX Index_usertags_UserId ON oblog_usertags (UserId)")
Call Execute("CREATE INDEX Index_usertags_logId ON oblog_usertags (logId)")
If strErrMsg<>"" Then
	Echo  "<font color=red>索引创建失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>索引创建成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_user Add user_folder varchar (255)  NULL")
Call Execute("Alter Table oblog_user Add user_icon1 varchar (255)  NULL")
Call Execute("Alter Table oblog_user Add user_icon2 varchar (255)  NULL")
Call Execute("Alter Table oblog_user Add user_info text NULL")
Call Execute("Alter Table oblog_user Add user_css text NULL")
Call Execute("Alter Table oblog_user Add user_cookie varchar (50) NULL")
Call Execute("Alter Table oblog_user Add user_photorow_num int NOT NULL default 0")
Call Execute("Update oblog_user Set user_photorow_num=4,user_folder=userid")
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_user 修改失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_user 修改成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_log Add logTags varchar (255)  NULL")
Call Execute("Alter Table oblog_log Add logTagsId varchar (255)  NULL")
Call Execute("Alter Table oblog_log Add logType int NOT NULL default 0")
Call Execute("Alter Table oblog_log Add Abstract Text  NULL")
Call Execute("Alter Table oblog_log Add Abstract_Auto int NOT NULL default 1")
Call Execute("Alter Table oblog_log Add EditorType int NOT NULL default 0")
Call Execute("Alter Table oblog_log Add filename varchar (30)  NULL")
Call Execute("Alter Table oblog_log Add logpics TEXT  NULL")
Call Execute("Alter Table oblog_log Alter Column tbUrl Text NULL")
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_log 修改失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_log 修改成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Update oblog_log Set logType=0,EditorType=0")
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_log 数据更新失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_log 数据更新成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_setup Add tag_badstr TEXT  NULL")
Call Execute("Alter Table oblog_setup Add index_to_file int NOT NULL default 0")
Call Execute("Alter Table oblog_setup Add loadingstr varchar (50)  NULL")
Call Execute("Alter Table oblog_setup Add df_filename int NOT NULL default 0")
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_log 数据更新失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_log 数据更新成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_userdir Add dirdomain varchar (255)  NULL")
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_userdir 修改失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_userdir 修改成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_trackback Add Excerpt varchar (255)  NULL")
Call Execute("Alter Table oblog_trackback Add VisitorUrl varchar (255)  NULL")
Call Execute("Alter Table oblog_trackback Add Ip varchar (255)  NULL")
Call Execute("Alter Table oblog_trackback Add tb_url varchar (255)  NULL")
Call Execute("Alter Table oblog_trackback Add blog_name varchar (255)  NULL")
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_trackback 修改失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_trackback 修改成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_logclass Add idType int NOT NULL default 0")
Call Execute("Update oblog_logclass Set idType=0")
Call Execute("Alter Table oblog_userclass Add idType int NOT NULL default 0")
Call Execute("Update oblog_userclass Set idType=0")
Call Execute("Alter Table oblog_subject Add subjectType int NOT NULL default 0")
Call Execute("Update oblog_subject Set subjectType=0")

If strErrMsg<>"" Then
	Echo  "<font color=red>类别表修改失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>类别表修改成功</font><BR/><BR/>" 
End If
strErrMsg=""

Call Execute("Alter Table oblog_upfile Add logid int NOT NULL default 0")
Call Execute("Alter Table oblog_upfile Add isPower int NOT NULL default 0")
Call Execute("Alter Table oblog_upfile Add photoExif TEXT  NULL")
Call Execute("Alter Table oblog_upfile Add sysClassId int NOT NULL default 0")
Call Execute("Alter Table oblog_upfile Add UserClassId int NOT NULL default 0")
Call Execute("Alter Table oblog_upfile Add photo_width int NOT NULL default 0")
Call Execute("Alter Table oblog_upfile Add photo_height int NOT NULL default 0")
Call Execute("Alter Table oblog_upfile Add viewNum int NOT NULL default 0")
strSql="Update oblog_upfile Set logid=0,isPower=0,sysClassId=0,UserClassId=0,photo_width=0,photo_height=0,viewNum=0"
Call Execute(strSql)
If strErrMsg<>"" Then
	Echo  "<font color=red>oblog_upfile 修改失败</font>:<BR/>" & strErrMsg  &"<BR/><BR/>" 
Else
	Echo  "<font color=green>oblog_upfile 修改成功</font><BR/><BR/>" 
End If
strErrMsg=""
'******************************************************************************
'更新相册数据
On error Resume Next
Dim rst,rst1,rst2,strContent,strPics,lngSysId,strUserName,strUserId,lngId,blog,i,strAbstract
Set rst=Server.CreateObject("Adodb.RecordSet")
Set rst1=Server.CreateObject("Adodb.RecordSet")
Set rst2=Server.CreateObject("Adodb.RecordSet")
'取第一个相册分类，如果没有的话，则创建一个
rst.Open "Select top 1 * From oblog_logclass Where idType=1",conn,1,3
If rst.EOf Then	
	rst.AddNew
	rst("classname")="日志图片"
	rst("idType")=1
	rst.Update
	rst.Close
	rst.Open "Select Max(classid) From oblog_logclass Where idType=1" ,conn,1,3
	
	lngSysId=rst(0)
ELse
	lngSysId=rst(0)
End If
rst.Close
Dim strReadMe
rst.Open "Select a.Userid,b.UserName From (Select Userid From oblog_upfile Where Userid>0 And IsPhoto=1 Group By UserId) a,oblog_user b Where a.userid=b.userid",conn,1,3
'Response.Write rst.RecordCount
If not rst.eof Then
	Do While not rst.Eof
		strUserName=rst(1)
		strUserId=rst(0)
		strContent=""	
		strPics=""
		i=0
		rst1.Open "Select * From oblog_upfile Where IsPhoto=1 And logid=0 And Userid=" & strUserId,conn,1,1
		If Not rst1.Eof Then
			i=0
			Do While not rst1.Eof
				If IsNull(rst1("file_readme")) Then
					strReadMe=""
				Else
					strReadMe=rst1("file_readme")
				End If
				strContent= strContent & "<p>&nbsp;</p>"  &Vbcrlf & "<img src=" & rst1("file_path")&" /><br/>" & strReadMe & Vbcrlf
				strPics= strPics & rst1("file_path") & Vbcrlf
				i=i+1
				If i=1 Then strAbstract="<img src=" & rst1("file_path")&" /><br/>" & rst1("file_readme")
				rst1.Movenext
			Loop
			'创建一篇新的相册日志,其摘要为第一副图片
			rst2.open "select top 1 * from oblog_log",conn,1,3
			rst2.Addnew
			rst2("topic")=Date & "之前发布的图片"
			rst2("EditorType")=0
			rst2("logtext")=strContent
			rst2("face")=0
			rst2("addtime")=Now
			rst2("classid")=lngSysId
			rst2("subjectid")=0
			rst2("showword")=500
			rst2("authorid")=strUserId
			rst2("author")=EncodeJP(strUserName)
			rst2("userid")=strUserId
			rst2("ishide")=0
			rst2("istop")=0
			rst2("tburl")=""
			rst2("logpics")=strPics
			rst2("logtype")=1
			rst2("isencomment")=0
			rst2("ispassword")=""
			rst2("passcheck")=1
			rst2("isdraft")=0
			rst2("Abstract")=strAbstract
			rst2("Abstract_auto")=1
			rst2("filename")="mypics"
			rst2.update
			rst2.close
			'获取日志ID
			rst2.Open "select max(logid) from oblog_log where userid="&strUserId,conn,1,1
			lngId=rst2(0)
			rst2.Close
			'更新图片关联
			Call UpdatePicLinks(strPics,lngId,strUserId,lngSysId,0)	
		End If
		rst1.Close
		rst.MoveNext
	Loop
End If
rst.Close
Set rst=Nothing
Set rst1=Nothing
Set rst2=Nothing

Echo "<font color=red>相册数据生成完毕,必须在系统后台重新生成用户静态页,您可以在所有其他设置全部完成后再进行生成操作</font>"			
'*****************************
conn.Close
Set conn=Nothing

If is_sqldata=0 Then  CompactData

%>
<BR/>
<BR/>
<b><font color=blue>操作完成，请删除本升级文件，然后使用新版本的程序进行测试</font></b>
<BR/>
<BR/>
============================================
<BR/>
<BR/>
oBlog3.1(http://www.oblog.cn)
<BR/>
<BR/>
</body>
</html>
<%
'---------------------------------------------
Sub CompactData()
	Dim FSO, Engine,strDBPath,strDBPath2
	strDBPath = Server.Mappath(db)
	strDBPath2= Left(strDBPath,Len(strDBPath)-4) & "0000" & Right(strDBPath,4)
	Set Fso = Server.CreateObject("Scripting.FileSystemObject")
	If Fso.FileExists(strDBPath) Then
		Set Engine = Server.CreateObject("JRO.JetEngine")
		Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath2
		If strErrMsg<>"" Then Echo  Err.Description
		FSO.CopyFile strDBPath2,strDBPath
		FSO.DeleteFile(strDBPath2)		
		Set Engine = nothing
		Echo  "<font color=green>数据库压缩成功!</font>"
	Else
		Echo  "<font color=red>数据库文件没有找到!!</font>"
	End If
	Set FSO = nothing
End Sub

'更新图片连接与日志的关联
Function UpdatePicLinks(byval sPics,byval sLogid,byval sUserId,byval SysClassId,byval UserClassId)
	Dim aPics,i,sPic
	sPics=Trim(sPics)
	aPics=Split(sPics,VBCRLF)
	For i=0 To UBound(aPics)
		sPic = Trim(aPics(i))
		If sPic<>"" Then		
			Select Case LCase(Right(sPic,3))
				Case "jpg","gif","png","bmp","tif"
					Call conn.Execute("Update oblog_upfile Set logid=" & sLogid & ",sysClassId=" &SysClassId &", UserClassId='" & UserClassId &"',isphoto=1 Where file_path='" & sPic & "' And userid=" & sUserId)
				Case Else
			End Select
		End If			
	Next
End Function


Sub  Execute(sSql)
On Error Resume Next
	Call conn.Execute(sSql)
	If Err.Number<>0 Then
		strErrMsg = strErrMsg & "<font color=red>" & Err.Description & "</font><BR>"
	End If
	Err.Clear
	On Error Goto 0
End Sub

Sub Echo(sStr)
	Response.Write sStr
	Response.Flush
End Sub
%>