<!-- #include file="../include.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<meta name="robots" content="all">
<title><% = AppTitle %></title>
</head>


<%

main()

Sub main()
	Dim Query, Content, Rs
	Query = "SELECT name FROM sysobjects WHERE (xtype = 'U') AND (status >= 0) ORDER BY name"

	Query = "SELECT name FROM sysobjects"
	Query = Query & " WHERE (xtype = 'U') AND (status >= 0) AND ((name LIKE N'TC[1-9]%') OR (name LIKE N'TD[A-Z]%') OR (name LIKE N'TG[A-Z]%') OR (name LIKE N'TS[A-Z]%') OR (name LIKE N'TT[A-Z]%'))"
	Query = Query & " ORDER BY name"

	Set db = Server.CreateObject("ADODB.Connection")
	db.Open SQLConn	
	Dim ii
	Set Content = OpenQuery(Query)


	Dim fso, fw, fr
	Set fso = CreateObject("Scripting.FileSystemObject")

	Set fr = fso.OpenTextFile(Request.ServerVariables("APPL_PHYSICAL_PATH") & "system\fieldlist.txt", 1, True)
	
Response.Write("<!--" & Request.ServerVariables("APPL_PHYSICAL_PATH") & "system\fieldlist.txt" & "-->")



	Dim HtmlAll, HtmlRow, bFalse, HtmlFalse, WriteRow
	Dim ScriptFalse1, ScriptFalse2, ScriptFalse3, ScriptFalse4
	Dim bTableFalseFlg
	bTableFalseFlg = 0
	

	Do While Not(Content.BOF Or Content.EOF)
		Dim name 
		name = Content.Fields("name")
		bTableFalseFlg = 0

			Query = "SELECT * FROM " & name & " WHERE 1 = 0 "	

			Set Rs = Server.CreateObject("ADODB.Recordset") 
			Rs.open Query,db,3,1 

			For ii = 0 To Rs.Fields.Count - 1
				bFalse = 0
				HtmlRow = ""
			
				Dim tani
				Dim tmp2,tmp2s, jj
				tmp2s = Array("")
				Dim tmp1s
				tmp1s = Array("","","","","","","")
				Dim tmp

				If fr.AtEndOfStream = false Then
					tmp2 = fr.ReadLine
					tmp2s = split(tmp2, ":")
				End If

				tmp1s(0) = name
				tmp1s(1) = Rs.Fields(ii).Name
				tmp1s(2) = Rs.Fields(ii).Type
				tmp1s(3) = Rs.Fields(ii).Precision
				tmp1s(4) = Rs.Fields(ii).NumericScale
				tmp1s(5) = Rs.Fields(ii).DefinedSize
				tmp1s(6) = Rs.Fields(ii).Attributes

				Select Case Rs.Fields(ii).Type
				case   0
					tmp1s(2) = "adEmpty"
				case  16
					tmp1s(2) = "adTinyInt"
				case   2
					tmp1s(2) = "smallint"
				case   3
					tmp1s(2) = "int"
				case  20
					tmp1s(2) = "adBigInt"
				case  17
					tmp1s(2) = "adUnsignedTinyInt"
				case  18
					tmp1s(2) = "adUnsignedSmallInt"
				case  19
					tmp1s(2) = "adUnsignedInt"
				case  21
					tmp1s(2) = "adUnsignedBigInt"
				case   4
					tmp1s(2) = "adSingle"
				case   5
					tmp1s(2) = "adDouble"
				case   6
					tmp1s(2) = "money"
				case  14
					tmp1s(2) = "adDecimal"
				case 131
					tmp1s(2) = "adNumeric"
				case  11
					tmp1s(2) = "adBoolean"
				case  10
					tmp1s(2) = "adError"
				case 132
					tmp1s(2) = "adUserDefined"
				case  12
					tmp1s(2) = "adVariant"
				case   9
					tmp1s(2) = "adIDispatch"
				case  13
					tmp1s(2) = "adIUnknown"
				case  72
					tmp1s(2) = "adGUID"
				case   7
					tmp1s(2) = "adDate"
				case 133
					tmp1s(2) = "adDBDate"
				case 134
					tmp1s(2) = "adDBTime"
				case 135
					tmp1s(2) = "datetime"
				case   8
					tmp1s(2) = "adBSTR"
				case 129
					tmp1s(2) = "adChar"
				case 200
					tmp1s(2) = "varchar"
				case 201
					tmp1s(2) = "adLongVarChar"
				case 130
					tmp1s(2) = "adWChar"
				case 202
					tmp1s(2) = "adVarWChar"
				case 203
					tmp1s(2) = "adLongVarWChar"
				case 128
					tmp1s(2) = "adBinary"
				case 204
					tmp1s(2) = "adVarBinary"
				case 205
					tmp1s(2) = "adLongVarBinary"
				case 136
					tmp1s(2) = "adChapter"
				case  64
					tmp1s(2) = "adFileTime"
				case 137
					tmp1s(2) = "adDBFileTime"
				case 138
					tmp1s(2) = "adPropVariant"
				case 139
					tmp1s(2) = "adVarNumeric"
				End Select
	

				If UBound(tmp2s) >= 1 Then
					HtmlRow = HtmlRow & "<tr>"
					For jj = 0 To UBound(tmp2s) - 1
						HtmlRow = HtmlRow & "<td>"
						HtmlRow = HtmlRow & tmp2s(jj)
						HtmlRow = HtmlRow & "</td>"
					Next
				End If


				For jj = 0 To 5
					If UBound(tmp2s) >= jj Then
						HtmlRow = HtmlRow & "<td>"
						If CStr(tmp2s(jj)) <> CStr(tmp1s(jj)) Then
							HtmlRow = HtmlRow & "<font color=""#FF0000"">"
							bFalse = 1
							bTableFalseFlg = 1
						End If
						HtmlRow = HtmlRow & tmp1s(jj)
						If tmp2s(jj) <> tmp1s(jj) Then
							HtmlRow = HtmlRow & "</font>"
						End If
						HtmlRow = HtmlRow & "</td>"
					End if
				
					WriteRow = WriteRow & tmp1s(jj)
					WriteRow = WriteRow & ":"
				Next


				WriteRow = WriteRow & vbCrLf
				HtmlRow = HtmlRow & "</tr>"
				HtmlRow = HtmlRow & vbCrLf

				If bTableFalseFlg = 1 Then
					If tmp2s(0) = tmp1s(0) Then
						ScriptFalse1 = ScriptFalse1 & "EXEC sp_rename '" & tmp1s(0) & "." & tmp1s(1) & "', 'tmp_" & tmp1s(1) & "', 'COLUMN'<br>" & vbCrLf
						ScriptFalse2 = ScriptFalse2 & "ALTER TABLE " & tmp2s(0) & " ADD " & tmp2s(1) & " " & tmp2s(2)
						if tmp2s(2) = "varchar" then
							ScriptFalse2 = ScriptFalse2 & " (" & tmp2s(5) & ") "
						End If
						ScriptFalse2 = ScriptFalse2 & " NULL<br>" & vbCrLf
						ScriptFalse3 = ScriptFalse3 & "UPDATE " & tmp2s(0) & " SET " & tmp2s(1) & " = tmp_" & tmp2s(1) & "<br>" & vbCrLf
						ScriptFalse4 = ScriptFalse4 & "ALTER TABLE " & tmp1s(0) & " DROP COLUMN tmp_" & tmp1s(1) & "<br>" & vbCrLf


					End If
				End If
				If bFalse = 1 Then
					HtmlFalse = HtmlFalse & HtmlRow
				End If
				HtmlAll = HtmlAll & HtmlRow
			Next

		Content.MoveNext
	Loop

	If Request("w") = "1" Then
		Set fw = fso.OpenTextFile(Request.ServerVariables("APPL_PHYSICAL_PATH") & "system\fieldlist.txt", 2, True)
		fw.Write WriteRow
	End If


%>

<SCRIPT LANGUAGE="JavaScript">
var busy=false
function forceclose3(){
	if(!busy){
		busy=true
		var w=window.window.open("","_top")
		w.opener=window
		w.close()
	}
}
</SCRIPT>

<% 	If Request("w") = "1" Then %>
<body onkeydown="if(ExitFlg==2)ExitFlg=3;" onLoad="forceclose3()">
<% Else %>
<body onkeydown="if(ExitFlg==2)ExitFlg=3;" topmargin="0" leftmargin="0" >
<% End If %>

<%

	Response.Write("現在のデータベースとインストールされているシステムが求めているデータベースの違い")
	Response.Write("<table border=""1"" style=""font-size: 12px;"">")
	Response.Write("<tr>")
	Response.Write("<td colspan=""6"" align=""center"">正しいテーブルデザイン</td>")
	Response.Write("<td colspan=""6"" align=""center"">現在のテーブルデザイン</td>")
	Response.Write("</tr>")
	Response.Write(HtmlFalse)
	Response.write("</table>")

	Response.write("<br>")
	Response.write("<br>")

	Response.Write("すべて")
	Response.Write("<table border=""1"" style=""font-size: 12px;color: #888888"">")
	Response.Write("<tr>")
	Response.Write("<td colspan=""6"" align=""center"">正しいテーブルデザイン</td>")
	Response.Write("<td colspan=""6"" align=""center"">現在のテーブルデザイン</td>")
	Response.Write("</tr>")
	Response.Write(HtmlAll)
	Response.write("</table>")


Response.Write("<font size=""1"">")
	Response.write(ScriptFalse1)
	Response.write("GO<br>")
	Response.write(ScriptFalse2)
	Response.write("GO<br>")
	Response.write(ScriptFalse3)
	Response.write("GO<br>")
	Response.write(ScriptFalse4)
	Response.write("GO<br>")
Response.Write("</font>")
%>
</body>
<%
End Sub
%>

</html>