Debug SQL Easily by Charles Carroll
来源:互联网 发布:cf审判无影腿编程 编辑:程序博客网 时间:2024/04/29 20:20
This page demonstrates how you can format a SQL statement to help pinpoint common errors. Common errors are discussed @
Common SQL Errors
http://www.learnasp.com/learn/dbtroubleshoot2.asp
Syntax Error in SQL Statement
http://www.learnasp.com/learn/FAQdbSQLSyntax.asp
by encapsulating ADO error trapping and display the SQL in an attractive form that separates components onto separate lines and makes debugging simpler (missing commas, single-quotes and like).
<Test Script Below>
<html><head>
<title>debug2.asp</title>
</head><body bgcolor="#FFFFFF">
<%
on error resume next
myDSN = "DSN=Student;uid=student;pwd=magic"
Set Conn = Server.CreateObject("ADODB.Connection")
conn.open myDSN
SQL="update test set fname='Ted',lname='Wilson',city='Rockville',state='MD',zip='20849',rank=7,datehire='1/15/92', SSN='219-92-2677' WHERE personid=7"
Conn.Execute SQL,howmany
IF howmany="" THEN
howmany=0
END IF
response.write "Affected <b>" & howmany & "</b> records<br>"
Call SQLerrorreport(SQL,conn)
SQL="Insert Into junk (fname,lname,city,state,zip,rank,datehire,ssn) VALUES ('ted','wilson','rockville', 'md', '20849',7,'1/15/92','219-92-2677')"
Conn.Execute SQL,howmany
IF howmany="" THEN
howmany=0
END IF
response.write "Affected <b>" & howmany & "</b> records</b><br>"
Call SQLerrorreport(SQL,conn)
Conn.Close
set conn=nothing
%>
</body></html>
<!--#include file="lib_debug2.asp"-->
The library that does the work:
<%
SUB SQLErrorReport(parmSQL,parm_conn)
HowManyErrs=parm_conn.errors.count
IF HowManyErrs=0 then
exit sub
END IF
pad=" "
lb="<br>" & vbcrlf
comma="<font color=red>"
squote="<font color=blue>"
response.write "ADO Error(s) executing:<br>"
for counter= 0 to HowManyErrs-1
errornum=parm_conn.errors(counter).number
errordesc=parm_conn.errors(counter).description
response.write pad & "Error#=<b>" & errornum & "</b><br>"
response.write pad & "Error description=<b>"
response.write errordesc & "</b><p>"
next
SQLstmt=parmSQL
SQLstmt=replace(SQLstmt,",", "<b>" & comma & ",</b></font>" & lb)
SQLstmt=replace(SQLstmt,"'","<b>" & squote & "'</b></font>")
SQLstmt=replace(SQLstmt,"(",lb & "(")
SQLstmt=replace(SQLstmt,"set",lb & "set" & lb)
SQLstmt=replace(SQLstmt,"SET",lb & "SET" & lb )
SQLstmt=replace(SQLstmt," where ",lb & " where " & lb)
SQLstmt=replace(SQLstmt," WHERE ",lb & " WHERE " & lb )
SQLstmt=replace(SQLstmt,")",")" & lb)
response.write "SQL statement attempted:<br>"
response.write SQLstmt & "<br>"
END SUB
%>
- Debug SQL Easily by Charles Carroll
- How to disable optimization when building WRK for easily debug?
- Programming Windows by Charles Petzold (bigtoog翻译)
- Object Pascal Style Guide - by Charles Calvert
- Object Pascal Style Guide - By Charles Calvert
- How to create DB2 user function easily by DB Query Analyzer 6.03
- TextView easily
- charles
- Charles
- Charles
- charles
- Charles
- Charles
- Charles
- Programming Self-generating Code for Windows Applications by Jim Charles
- PL/SQL Debug
- PL/SQL debug
- sql group by order by
- 研究装潢Blog
- java多线程,什么时候让我跨过你高高的门槛
- 浅析本机API[zt]
- 使用PHP+FreeTDS在Linux下连接MS SQLServer数据库
- 移动光标到input最后
- Debug SQL Easily by Charles Carroll
- ASP中怎么获得被更新或新增的记录数?
- J2ME中使用随机数
- 使用梅花雨
- 通过WebRequest获取远程网页图片
- repeater里添加序号的两种方法(前台,后台)
- 变态级JAVA程序员面试32问(转)
- JavaScript写的Cookie类
- Cookie的概述及应用。