VBS version SQL Query Analyzer LCX Works _vbs

Source: Internet
Author: User
Tags table name
Spent a little time to the previous Haiyang top 2006 of the SQL module to the VBS version, and its function is the same, but may not be used to use the ASP version of the comfortable, but can be used, can be used in the DOS, infiltrate the intranet when estimated you need.

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 < pages =default:1>"
echo "Exp:cscript sql.vbs showtables" &AMP;CHR (&) Sql:provider=sqloledb.1; Server=localhost; User Id=sa; Password=haiyangtop;database=bbs "&AMP;CHR (34)
echo "exp:cscript sql.vbs Query" &AMP;CHR (&) Sql:provider=sqloledb.1; Server=localhost; User Id=sa; Password=haiyangtop;database=bbs "&AMP;CHR &space (1) &chr (a) &chr (a) &space (1) &Chr (34) & "SELECT * from Name" &AMP;CHR (&space) (1) & 1
echo "exp:cscript sql.vbs Query" &AMP;CHR (&) Sql:provider=sqloledb.1; Server=localhost; User Id=sa; Password=haiyangtop;database=bbs "&AMP;CHR &space (1) &chr (a) &chr (a) &space (1) &Chr (34) & "Update ..." &AMP;CHR (&space) (1) & 1
echo "exp:cscript sql.vbs Query" &AMP;CHR (&) Sql:provider=sqloledb.1; Server=localhost; User Id=sa; Password=haiyangtop;database=bbs "&AMP;CHR &space (1) &chr (a) &chr (a) &space (1) &Chr (34) & "EXEC master.dbo.xp_cmdshell ' net user ice Hacker/add '--" &AMP;CHR &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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Rem below is the Program Module selection section
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") &AMP;VBCRLF

Do Until rscolumn.eof

echo "Field name:" & Rscolumn ("column_name") &AMP;VBCLRF
echo "type:" & Getdatatype (Rscolumn ("Data_type")) & VBCLRF
echo "Size:" & Rscolumn ("Character_maximum_length") & VBCLRF
echo "Precision:" & Rscolumn ("Numeric_precision") & VBCLRF
echo "Allow null:" & Rscolumn ("Is_nullable") & VBCLRF
echo "Default value:" & Rscolumn ("Column_default") & VBCLRF&AMP;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 database table structure view: "
echo Tablesstr & "========================================================"
echo ">sql command execution and view:" &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 operations-execution Results" &vbcrlf
The 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 for
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 & "Pages"
Rs. Close
Else
If SQL <> "" Then
Conn. Execute (SQL)
Chkerr (ERR)
echo "Done!" &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 130
Getdatatype = "Text"
Case 2
Getdatatype = "Integral type"
Case 3
Getdatatype = "Long Integral type"
Case 7
Getdatatype = "Date/Time"
Case 5
Getdatatype = "Double-precision"
Case 11
Getdatatype = "Yes/No"
Case 128
Getdatatype = "OLE Object"
Case Else
Getdatatype = typeID
End Select
End Function


Function gettablelist (conn, sqlstr, rstable)
Set rstable = conn. OpenSchema (Empty, Empty, Empty, "table")
echo "has the following table name:"
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.