⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createtable.asp

📁 asp与MYSQL的源码
💻 ASP
字号:
<%
response.buffer = true
%>
<!--#include file="top.asp"-->
<TABLE WIDTH=750 bgcolor=#E7F1EC cellspacing=1 cellpadding=0 border=0>
	<TR>
		<TD width=200 valign=top><!--#include file="left.asp"--></TD>
		<TD width=550 valign=top>
			<TABLE WIDTH=100% cellpadding=5 cellspacing=0>
				<TR>
					<TD bgcolor="#339999" align=center width=550 class=celltitle><%=Request("db")%></TD>
				</TR>
				<TR>
					<TD>
					<%
					if len(request("go")) = 0 then
					%>	
						<FORM ACTION=createtable.asp?db=<%=request("db")%> method=post>
						<INPUT TYPE=HIDDEN NAME=TableName Value=<%=request("TableName")%>>
						<input type=hidden name=Fields value=<%=request("fields")%>>
						<input type=hidden name=Go Value=Y>
						<table border="0" cellpadding=2 cellspacing=1 style="border:solid black 1pt;">
							<TR>
								<TD colspan=10 bgcolor=#339999 class=cellsmalltitle>Create table "<%=request("tablename")%>"</TD>
							</TR>
							<tr>
							    <td class=cellsmalltitle bgcolor=#339999>Field</td>
							    <td class=cellsmalltitle bgcolor=#339999>Type</td>
							    <td class=cellsmalltitle bgcolor=#339999>Length/Values*</td>
							    <td class=cellsmalltitle bgcolor=#339999>Attributes</td>
							    <td class=cellsmalltitle bgcolor=#339999>Null</td>
							    <td class=cellsmalltitle bgcolor=#339999>Default</td>
							    <td class=cellsmalltitle bgcolor=#339999>Extra</td>
							    <td class=cellsmalltitle bgcolor=#339999>Primary</td>
							    <td class=cellsmalltitle bgcolor=#339999>Index</td>
							    <td class=cellsmalltitle bgcolor=#339999>Unique</td>
							</tr>
							<%
							for i = 1 to cint(request("fields"))
							%>
							<tr>
							    <td>
							        <input type="text" name="field_name[<%=i%>]" size="10" value="">
							    </td>
							    <td>
							        <select name="field_type[<%=i%>]">
							            <option value="TINYINT">TINYINT</option>
							            <option value="SMALLINT">SMALLINT</option>
							            <option value="MEDIUMINT">MEDIUMINT</option>
							            <option value="INT">INT</option>
							            <option value="BIGINT">BIGINT</option>
							            <option value="FLOAT">FLOAT</option>
							            <option value="DOUBLE">DOUBLE</option>
							            <option value="DECIMAL">DECIMAL</option>
							            <option value="DATE">DATE</option>
							            <option value="DATETIME">DATETIME</option>
							            <option value="TIMESTAMP">TIMESTAMP</option>
							            <option value="TIME">TIME</option>
							            <option value="YEAR">YEAR</option>
							            <option value="CHAR">CHAR</option>
							            <option value="VARCHAR">VARCHAR</option>
							            <option value="TINYBLOB">TINYBLOB</option>
							            <option value="TINYTEXT">TINYTEXT</option>
							            <option value="TEXT">TEXT</option>
							            <option value="BLOB">BLOB</option>
							            <option value="MEDIUMBLOB">MEDIUMBLOB</option>
							            <option value="MEDIUMTEXT">MEDIUMTEXT</option>
							            <option value="LONGBLOB">LONGBLOB</option>
							            <option value="LONGTEXT">LONGTEXT</option>
							            <option value="ENUM">ENUM</option>
							            <option value="SET">SET</option>
							        </select>
							    </td>
							    <td>
							        <input type="text" name="field_length[<%=i%>]" size="8" value="">
							    </td>
							    <td>
							        <select name="field_attribute[<%=i%>]">
							            <option value="" selected="selected"></option>
							            <option value="BINARY">BINARY</option>
							            <option value="UNSIGNED">UNSIGNED</option>
							            <option value="UNSIGNED ZEROFILL">UNSIGNED ZEROFILL</option>
							        </select>
							    </td>
							    <td>
							        <select name="field_null[<%=i%>]">
							            <option value="NOT NULL">not null</option>
							            <option value="">null</option>							    
							        </select>
							    </td>
    
							    <td>
    						        <input type="text" name="field_default[<%=i%>]" size="8" value="">
							    </td>
							    <td>
							        <select name="field_extra[<%=i%>]">
							            <option value=""></option>
							            <option value="AUTO_INCREMENT">auto_increment</option>
									</select>
							    </td>
							    <td align="center">
							        <input type="checkbox" name="field_primary[<%=i%>]" value="0">
							    </td>
							    <td align="center">
							        <input type="checkbox" name="field_index[<%=i%>]" value="0">
							    </td>
							    <td align="center">
							        <input type="checkbox" name="field_unique[<%=i%>]" value="0">
							    </td>
							</tr>
							<%
							next
							%>
							<TR>
								<TD colspan=10><INPUT TYPE=SUBMIT VALUE="Create Table"></TD>
							</TR>
						</TABLE>
						</FORM>
					<%
					else
						'We Go Through the process of creating the table...
						 
						SQL = "CREATE TABLE " & request("tablename") & " ("
						for i = 1 to cint(request("fields"))
							
							sql = sql & "`" & request("field_name[" & i & "]") & "` " 
							sql = sql & request("field_type[" & i & "]")
							select case request("field_type[" & i & "]")
								case "TINYINT", "SMALLINT", "MEDIUMINT", "INT", "INTEGER", "BIGINT"
									sql = sql & "(" & request("field_length[" & i & "]") & ") " 
									sql = sql & request("field_attribute[" & i & "]") & " " 
									sql = sql & request("field_null[" & i & "]") & " "
									if len(request("field_extra[" & i & "]")) = 0 then
										if len(request("field_default[" & i & "]")) > 0 then
											sql = sql & "default " & request("field_default[" & i & "]") & " " 
										end if
									end if
									sql = sql & request("field_extra[" & i & "]")
								CASE "REAL", "DOUBLE", "FLOAT", "DECIMAL", "NUMERIC"
									sql = sql & "(" & request("field_length[" & i & "]") & ") " 
									sql = sql & request("field_attribute[" & i & "]") & " " 
									sql = sql & request("field_null[" & i & "]") 
									if len(request("field_default[" & i & "]")) > 0 then
										sql = sql & " default " & request("field_default[" & i & "]")
									end if
								CASE "CHAR", "VARCHAR"
									sql = sql & "(" & request("field_length[" & i & "]") & ") " 
									sql = sql & request("field_attribute[" & i & "]") & " " 
									sql = sql & request("field_null[" & i & "]") 
									if len(request("field_default[" & i & "]")) > 0 then
										sql = sql & " default " & request("field_default[" & i & "]")
									end if
									
								CASE "DATE", "TIME", "TIMESTAMP", "DATETIME", "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT"									
									sql = sql & " " & request("field_null[" & i & "]")& " " 
									'if len(request("field_default[" & i & "]")) = 0 and (request("field_type[" & i & "]") = "DATE" or request("field_type[" & i & "]") = "DATETIME") then
									'	sql = sql & " default '0000-00-00'"
									'elseif len(request("field_default[" & i & "]")) = 0 and (request("field_type[" & i & "]") = "TIME" or request("field_type[" & i & "]") = "TIMESTAMP") then
									'	sql = sql & " default '00:00:00'"
									'else
									'	sql = sql & "default " & Request("field_default[" & i & "]") 
									'end if
								CASE "ENUM", "SET"
									sql = sql & "(" & request("field_length[" & i & "]") & ") " & request("field_null[" & i & "]") & " " & request("field_default[" & i & "]")
							END SELECT
							
							sql = sql & ", "
							
						next	
						
						for i = 1 to cint(request("fields"))
						
							if request("field_primary[" & i & "]") = "0" then
								field_primary = field_primary & "`" & request("field_name[" & i & "]") & "`, " 
								if len(keyname) = 0 then
									keyname = replace(field_primary, ", ", "")
								end if
							end if
							
							if request("field_index[" & i & "]") = "0" then
								field_index = field_index & "`" & request("field_name[" & i & "]") & "`, " 
							end if
						
							'if request("field_unique[" & i & "]") = "0" then
							'	field_unique = field_unique & "`" & request("field_name[" & i & "]") & "_" & i & "`, " 
							'end if
								
						next
						if len(field_primary) > 0 or len(field_index) > 0 or len(field_unique) > 0 then
							if len(field_primary) > 0 then
								sql = sql & " PRIMARY KEY (" & left(field_primary, len(field_primary) - 2) & ")"
								'Response.Write "Step 1: " & sql & "<BR>"
							end if
							if len(field_index) > 0 then
								if len(field_primary) > 0 then
									sql = sql & ", "
								end if
								sql = sql & " INDEX (" & left(field_index, len(field_index) - 2) & ")"
								'Response.Write "Step 2: " & sql & "<BR>"
							end if
							'if len(field_unique) > 0 then
							'	if len(field_index) > 0 then
							'		sql = sql & ", " 
							'	end if
							'	sql = sql & " UNIQUE KEY " & keyname & " (" & left(field_unique, len(field_unique) - 2) & ")"
							'	'Response.Write "Step 3: " & sql & "<BR>"
							'end if
						else
							'Response.Write "Hi"
							sql = left(sql, len(sql) - 2)
							'Response.Write "Step 4: " & sql & "<BR>"
						end if
						sql = sql & ")"
						'Response.Write sql 
						set cn = server.CreateObject("ADODB.Connection")
						cn.open dsn
						cn.Execute "use " & request("db")
						
						Response.Write sql
						cn.Execute replace(sql, "<BR>", "")
						
						set cn = nothing
						Response.Clear 
						Response.Redirect "showdb.asp?db=" & request("db")
					end if
					%>
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
</TABLE>
<!--#include file="bottom.asp"-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -