|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
因为现在数据库都使用标准的SQL语言对数据库进行管理,所以如果是标准SQL语言,两者基本上都可以通用的。SQLServer还有更多的扩展,可以用存储过程,数据库大小无极限限制。xml|导出xml|数据|数据库<!--#includefile=../conn.asp-->
<%
数据库导出纪录代码
作者海娃,haiwa#blueidea.com,http://www.51windows.Net
用法:
ExportDB.asp?sql=select语句&tablename=表名(可选)&filetype=导特别式(xml,htm,csv,sql)&pid=主动编号字段名(仅当导出sql范例时有效)
dimtablename,filetype,fieldPid
sql=request("sql")
tablename=request("tablename")
filetype=lcase(request("filetype"))
fieldPid=request("pid")
iffieldPid=""then
fieldPid="id"
endif
fieldPid=lcase(fieldPid)
iflcase(left(sql,6))"select"then
Response.write"sql语句必需为select*from[table]where......."
Response.end
endif
iftablename=""then
tablename="数据导出了局"
endif
functionHTMLEncode(fString)
ifnotisnull(fString)then
fString=Server.HTMLEncode(fString)
fString=Replace(fString,CHR(10)&CHR(10),"</P><P>")
fString=Replace(fString,CHR(10),"<BR>")
fString=Replace(fString,CHR(9),"")
HTMLEncode=fString
endif
endfunction
functionMyreplace(str)
ifnotisnull(str)then
fString=Replace(fString,"""","""""")
Myreplace=str
else
Myreplace=""
endif
endfunction
functionMyreplace2(str)
ifnotisnull(str)then
fString=Replace(fString,"","")
Myreplace2=str
else
Myreplace2=""
endif
endfunction
dimdef_export_sep,def_export_val
def_export_sep=","
def_export_val=""""
Setrs=Conn.Execute(sql)
导出XML文件
iffiletype="xml"then
Response.contenttype="text/xml"
Response.Charset="gb2312"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&".xml"
Response.write"<?xmlversion=""1.0""encoding=""gb2312""?>"&vbnewline
Response.write"<root>"
strLine=""
dimthefield(50)
i=0
Foreachxinrs.fields
thefield(i)=x.name
i=i+1
Next
Whilers.EOF=false
strLine=vbnewline&chr(9)&"<row>"
k=0
Foreachxinrs.fields
strLine=strLine&vbnewline&chr(9)&chr(9)&"<"&thefield(k)&">"
ifinstr(x.value,"<")>0orinstr(x.value,">")>0orinstr(x.value,"&")>0orlen(x.value)>255then
strLine=strLine&"<![CDATA["&x.value&"]]>"
else
strLine=strLine&x.value
endif
strLine=strLine&"</"&thefield(k)&">"
k=k+1
Next
rs.MoveNext
Response.writestrLine&vbnewline&chr(9)&"</row>"
Wend
Response.writevbnewline&"</root>"
导出sql文件
elseiffiletype="sql"then
Response.contenttype="text/sql"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&".sql"
strLine=""
dimsql_insert
Foreachxinrs.fields
iflcase(x.name)fieldPidthen假如是主动编号
strLine=strLine&def_export_val&x.name&def_export_val&def_export_sep
endif
Next
strLine=replace(left(strLine,len(strLine)-1),"""","")
strLine="insertinto["&tablename&"]("&strLine&")values"
sql_insert=strLine
Response.writestrLine&vbnewline
response.end
Whilers.EOF=false
strLine=""
def_export_val=""
Foreachxinrs.fields
iflcase(x.name)fieldPidthen
2004-8-11更新Null值时没法导出的bug。
x_value=x.value
ifisnull(x_value)orlen(x_value)=0then
x_value=""
else
x_value=replace(x_value,"","")
endif
strLine=strLine&def_export_val&x_value&def_export_val&def_export_sep
endif
Next
rs.MoveNext
strLine=left(strLine,len(strLine)-1)
Response.writesql_insert&"("&strLine&")*"&vbnewline
Wend
elseiffiletype="csv"then
Response.contenttype="text/csv"
Response.AddHeader"Content-Disposition","attachment;filename="&tablename&"
由于ASP还是一种Script语言所没除了大量使用组件外,没有办法提高其工作效率。它必须面对即时编绎的时间考验,同时我们还不知其背后的组件会是一个什么样的状况; |
|