亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

一個普通的數據庫例子源源程序

2019-11-18 22:15:26
字體:
來源:轉載
供稿:網友

     To assist in interfacing with databases. This script can format variables and return SQL formats.
Such as double quoting apposterphies and surrounding strings with quotes, Returning NULL for invalid data
types, trimming strings so they do not exceed maximum lengths. This also has some functions so that you
can open and close databases more conveiently with just one line of code. You can query a database and get
an Array as well with some code.


  
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!



    '**************************************
    ' for :Common Database Routines
    '**************************************
    Copyright (c) 1999 by Lewis Moten, All rights reserved.


code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!



    '**************************************
    ' Name: Common Database Routines
    ' Description:To assist in interfacing w
    '     ith databases. This script can format va
    '     riables and return SQL formats. Such as
    '     double quoting apposterphies and surroun
    '     ding strings with quotes, Returning NULL
    '     for invalid data types, trimming strings
    '     so they do not exceed maximum lengths. T
    '     his also has some functions so that you
    '     can open and close databases more convei
    '     ently with just one line of code. You ca
    '     n query a database and get an Array as w
    '     ell with some code.
    ' By: Lewis Moten
    '
    '
    ' Inputs:None
    '
    ' Returns:None
    '
    'Assumes:This script assumes that you at
    '     least have Microsoft ActiveX Data Object
    '     s 2.0 or Higher (ADODB). This script may
    '     get some getting used to at first until
    '     you go through and study what each routi
    '     ne can do.
    '
    'Side Effects:None
    '
    'Warranty:
    'code PRovided by Planet Source Code(tm)
    '     (www.Planet-Source-Code.com) 'as is', wi
    '     thout warranties as to performance, fitn
    '     ess, merchantability,and any other warra
    '     nty (whether expressed or implied).
    'Terms of Agreement:
    'By using this source code, you agree to
    '     the following terms...
    ' 1) You may use this source code in per
    '     sonal projects and may compile it into a
    '     n .exe/.dll/.ocx and distribute it in bi
    '     nary format freely and with no charge.
    ' 2) You MAY NOT redistribute this sourc
    '     e code (for example to a web site) witho
    '     ut written permission from the original
    '     author.Failure to do so is a violation o
    '     f copyright laws.
    ' 3) You may link to this code from anot
    '     her website, provided it is not wrapped
    '     in a frame.
    ' 4) The author of this code may have re
    '     tained certain additional copyright righ
    '     ts.If so, this is indicated in the autho
    '     r's description.
    '**************************************
    
    <!--METADATA Type="TypeLib" NAME="Microsoft ActiveX Data Objects 2.0 Library" UUID="{00000200-0000-
0010-8000-00AA006D2EA4}" VERSION="2.0"-->
    <%
    ' Setup the ConnectionString
    Dim sCONNECTION_STRING
    sCONNECTION_STRING = "DRIVER=Microsoft access Driver
(*.mdb);DBQ=D:/inetpub/wwwroot/inc/data/database.mdb;"
    Dim oConn
    '---------------------------------------
    '     ----------------------------------------
    '     
    Function DBConnOpen(ByRef aoConnObj)
     ' This routine connects To a database and returns
     ' weather or Not it was successful
     ' Prepare For any errors that may occur While connecting To the database
     On Error Resume Next
     ' Create a connection object
     Set aoConnObj = Server.CreateObject("ADODB.Connection")
     ' Open a connection To the database
     Call aoConnObj.Open(sCONNECTION_STRING)
     ' If any errors have occured
     If Err Then
     ' Clear errors
     Err.Clear
     ' Release connection object
     Set aoConnObj = Nothing
     ' Return unsuccessful results
     DBConnOpen = False
     ' Else errors did Not occur
     Else
     ' Return successful results
     DBConnOpen = True
     End If ' Err
    End Function ' DBConnOpen
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function DBConnClose(ByRef aoConnObj)
     ' This routine closes the database connection and releases objects
     ' from memory
     ' If the connection variable has been defined as an object
     If IsObject(aoConnObj) Then
     ' If the connection is open
     If aoConnObj.State = adStateOpen Then
     ' Close the connection
     aoConnObj.Close
     ' Return positive Results
     DBConnClose = True
     End If ' aoConnObj.State = adStateOpen
     ' Release connection object
     Set aoConnObj = Nothing
     End If ' IsObject(aoConnObj)
    End Function ' DBConnClose
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SetData(ByRef asSQL, ByRef avDataAry)
     ' This routine acquires data from the database
     Dim loRS ' ADODB.Recordset Object
     ' Create Recordset Object
     Set loRS = Server.CreateObject("ADODB.Recordset")
     ' Prepare For errors when opening database connection
     On Error Resume Next
     ' If a connection object has been defined
     If IsObject(oConn) Then
     ' If the connection is open
     If oConn.State = adStateOpen Then
     ' Acquire data With connection object
     Call loRS.Open(asSQL, oConn, adOpenForwardOnly, adLockReadOnly)
     ' Else the connection is closed
     Else
     ' Set the ConnectionString
     Call SetConnectionString(csConnectionString)
     ' If atempt To open connection succeeded
     If DBConnOpen() Then
     ' Acquire data With connection object
     Call loRS.Open(asSQL, oConn, adOpenForwardOnly, adLockReadOnly)
     ' Return connection object To closed state
     Call DBConnClose()
     End If ' DBConnOpen()
     End If ' aoConn.State = adStateOpen
     ' Else active connection is the ConnectionString
     Else
     ' Acquire data With ConnectionString
     Call loRS.Open(asSQL, sCONNECTION_STRING, adOpenForwardOnly, adLockReadOnly)
     End If ' IsObject(oConn)
     ' If errors occured
     If Err Then
     response.write "<HR color=red>" & err.description & "<HR color=red>" & asSQL & "<HR
color=red>"
     ' Clear the Error
     Err.Clear
     ' If the recorset is open
     If loRS.State = adStateOpen Then
     ' Close the recorset
     loRS.Close
     End If ' loRS.State = adStateOpen
     ' Release Recordset from memory
     Set loRS = Nothing
     ' Return negative results
     SetData = False
     ' Exit Routine
     Exit Function
     End If ' Err
     ' Return positve results
     SetData = True
     ' If data was found
     If Not loRS.EOF Then
     ' Pull data into an array
     avDataAry = loRS.GetRows
     End If ' Not loRS.EOF
     ' Close Recordset
     loRS.Close
     ' Release object from memory
     Set loRS = Nothing
    End Function ' SetData
    '---------------------------------------
    '     ----------------------------------------
    '     
    ' SQL Preperations are used to prepare v
    '     ariables for SQL Queries. If
    ' invalid data is passed to these routin
    '     es, NULL values or Default Data
    ' is returned to keep your SQL Queries f
    '     rom breaking from users breaking
    ' datatype rules.
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_s(ByVal asExpression, ByRef anMaxLength)
     ' If maximum length is defined
     If anMaxLength > 0 Then
     ' Trim expression To maximum length
     asExpression = Left(asExpression, anMaxLength)
     End If ' anMaxLength > 0
     ' Double quote SQL quote characters
     asExpression = Replace(asExpression, "'", "''")
     ' If Expression is Empty
     If asExpression = "" Then
     ' Return a NULL value
     SQLPrep_s = "NULL"
     ' Else expression is Not empty
     Else
     ' Return quoted expression
     SQLPrep_s = "'" & asExpression & "'"
     End If ' asExpression
    End Function ' SQLPrep_s
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_n(ByVal anExpression)
     ' If expression numeric
     If IsNumeric(anExpression) And Not anExpression = "" Then
     ' Return number
     SQLPrep_n = anExpression
     ' Else expression Not numeric
     Else
     ' Return NULL
     SQLPrep_n = "NULL"
     End If ' IsNumeric(anExpression) And Not anExpression = ""
    End Function ' SQLPrep_n
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_b(ByVal abExpression, ByRef abDefault)
     ' Declare Database Constants
     Const lbTRUE = -1 '1 = SQL, -1 = Access
     Const lbFALSE = 0
     Dim lbResult ' Result To be passed back
     ' Prepare For any errors that may occur
     On Error Resume Next
     ' If expression Not provided
     If abExpression = "" Then
     ' Set expression To default value
     abExpression = abDefault
     End If ' abExpression = ""
     ' Attempt To convert expression
     lbResult = CBool(abExpression)
     ' If Err Occured
     If Err Then
     ' Clear the Error
     Err.Clear
     ' Determine action based on Expression
     Select Case LCase(abExpression)
     ' True expressions
     Case "yes", "on", "true", "-1", "1"
     lbResult = True
     ' False expressions
     Case "no", "off", "false", "0"
     lbResult = False
     ' Unknown expression
     Case Else
     lbResult = abDefault
     End Select ' LCase(abExpression)
     End If ' Err
     ' If result is True
     If lbResult Then
     ' Return True
     SQLPrep_b = lbTRUE
     ' Else Result is False
     Else
     ' Return False
     SQLPrep_b = lbFALSE
     End If ' lbResult
    End Function ' SQLPrep_b
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_d(ByRef adExpression)
     ' If Expression valid Date
     If IsDate(adExpression) Then
     ' Return Date
     'SQLPrep_d = "'" & adExpression & "'" ' SQL Database
     SQLPrep_d = "#" & adExpression & "#" ' Access Database
     ' Else Expression Not valid Date
     Else
     ' Return NULL
     SQLPrep_d = "NULL"
     End If ' IsDate(adExpression)
    End Function ' SQLPrep_d
    '---------------------------------------
    '     ----------------------------------------
    '     
    Public Function SQLPrep_c(ByVal acExpression)
     ' If Empty Expression
     If acExpression = "" Then
     ' Return Null
     SQLPrep_c = "NULL"
     ' Else expression has content
     Else
     ' Prepare For Errors
     On Error Resume Next
     ' Attempt To convert expression to Currency
     SQLPRep_c = CCur(acExpression)
     ' If Error occured
     If Err Then
     ' Clear Error
     Err.Clear
     SQLPrep_c = "NULL"
     End If ' Err
     End If ' acExpression = ""
    End Function ' SQLPrep_c
    '---------------------------------------
    '     ----------------------------------------
    '     
    Function buildJoinStatment(sTable,sFldLstAry,rs,conn)
    Dim i,sSql,sTablesAry,sJnFldsAry,bJoinAry,sJoinDisplay
    ReDim sTablesAry(UBound(sFldLstAry))
    ReDim sJnFldsAry(UBound(sFldLstAry))
    ReDim bJoinAry(UBound(sFldLstAry))
    For i = 0 To UBound(sFldLstAry)
    sSql = "SELECT OBJECT_NAME(rkeyid),COL_NAME(rkeyid,rkey1)"
    sSql = sSql &" FROM sysreferences"
    sSql = sSql &" WHERE fkeyid = OBJECT_ID('"& sTable &"') "
    sSql = sSql &" AND col_name(fkeyid,fkey1) = '"& Trim(sFldLstAry(i)) &"'"
    rs.open sSql,conn
    If Not rs.eof Then
    sTablesAry(i) = rs(0)
    sJnFldsAry(i) = rs(1)
    End If
    rs.close
    Next
    If UBound(sFldLstAry) >= 0 Then
    For i = 0 To UBound(sFldLstAry)
    If sTablesAry(i) <> "" Then
    bJoinAry(i) = True
    Else
    bJoinAry(i) = False
    End If
    If i <> UBound(sFldLstAry) Then sSql = sSql &" +' - '+ "
    Next
    sSql = "FROM "& sTable
    For i = 0 To UBound(sFldLstAry)
    If bJoinAry(i) Then sSql = sSql &" LEFT JOIN "& sTablesAry(i) &" ON "& sTable &"."& sFldLstAry(i) &"
= "& sTablesAry(i) &"."& sJnFldsAry(i)
    Next
    End If
    buildJoinStatment = sSql
    End Function
    '---------------------------------------
    '     ----------------------------------------
    '     
    Function buildQuery(ByRef asFieldAry, ByVal asKeyWords)
     ' To find fields that may have a word in them
     ' OR roger
     ' | roger
     ' roger
     ' To find fields that must match a word
     ' AND roger
     ' + roger
     ' & roger
     ' To find fields that must Not match a word
     ' Not roger
     ' - roger
     ' Also use phrases
     ' +"rogers dog" -cat
     ' +(rogers dog)
     Dim loRegExp
     Dim loRequiredWords
     Dim loUnwantedWords
     Dim loOptionalWords
     Dim lsSQL
     Dim lnIndex
     Dim lsKeyword
     Set loRegExp = New RegExp
     loRegExp.Global = True
     loRegExp.IgnoreCase = True
     loRegExp.Pattern = "((AND|[+&])/s*[/(/[/{""].*[/)/]/}""])|((AND/s|[+&])/s*/b[-/w']+/b)"
     Set loRequiredWords = loRegExp.Execute(asKeywords)
     asKeywords = loRegExp.Replace(asKeywords, "")
     loRegExp.Pattern = "(((NOT|[-])/s*)?[/(/[/{""].*[/)/]/}""])|(((NOT/s+|[-])/s*)/b[-/w']+/b)"
     Set loUnwantedWords = loRegExp.Execute(asKeywords)
     asKeywords = loRegExp.Replace(asKeywords, "")
     loRegExp.Pattern = "(((OR|[|])/s*)?[/(/[/{""].*[/)/]/}""])|(((OR/s+|[|])/s*)?/b[-/w']+/b)"
     Set loOptionalWords = loRegExp.Execute(asKeywords)
     asKeywords = loRegExp.Replace(asKeywords, "")
     If Not loRequiredWords.Count = 0 Then
     ' REQUIRED
     lsSQL = lsSQL & "("
     For lnIndex = 0 To loRequiredWords.Count - 1
     lsKeyword = loRequiredWords.Item(lnIndex).Value
     loRegExp.Pattern = "^(AND|[+&])/s*"
     lsKeyword = loRegExp.Replace(lsKeyword, "")
     loRegExp.Pattern = "[()""/[/]{}]"
     lsKeyword = loRegExp.Replace(lsKeyword, "")
     lsKeyword = Replace(lsKeyword, "'", "''")
     If Not lnIndex = 0 Then
     lsSQL = lsSQL & " AND "
       End If
     lsSQL = lsSQL & "(" & Join(asFieldAry, " LIKE '%" & lsKeyword & "%' OR ")
& " LIKE '%" & lsKeyword & "%')"
     Next
     lsSQL = lsSQL & ")"
     End If
     If Not loOptionalWords.Count = 0 Then
     ' OPTIONAL
     If lsSQL = "" Then
     lsSQL = lsSQL & "("
     Else
     lsSQL = lsSQL & " AND ("
     End If
     For lnIndex = 0 To loOptionalWords.Count - 1
     lsKeyword = loOptionalWords.Item(lnIndex).Value
     loRegExp.Pattern = "^(OR|[|])/s*"
     lsKeyword = loRegExp.Replace(lsKeyword, "")
     loRegExp.Pattern = "[()""/[/]{}]"
     lsKeyword = loRegExp.Replace(lsKeyword, "")
     lsKeyword = Replace(lsKeyword, "'", "''")
     If Not lnIndex = 0 Then
     lsSQL = lsSQL & " OR "
     End If
     lsSQL = lsSQL & "(" & Join(asFieldAry, " LIKE '%" & lsKeyword & "%' OR ")
& " LIKE '%" & lsKeyword & "%')"
     Next
     lsSQL = lsSQL & ")"
     End If
     If Not loUnwantedWords.Count = 0 Then
     ' UNWANTED
     If lsSQL = "" Then
     lsSQL = lsSQL & "NOT ("
     Else
     lsSQL = lsSQL & " AND Not ("
     End If
     For lnIndex = 0 To loUnwantedWords.Count - 1
     lsKeyword = loUnWantedWords.Item(lnIndex).Value
     loRegExp.Pattern = "^(NOT|[-])/s*"
     lsKeyword = loRegExp.Replace(lsKeyword, "")
     loRegExp.Pattern = "[()""/[/]{}]"
     lsKeyword = loRegExp.Replace(lsKeyword, "")
     lsKeyword = Replace(lsKeyword, "'", "''")
     If Not lnIndex = 0 Then
     lsSQL = lsSQL & " OR "
     End If
     lsSQL = lsSQL & "(" & Join(asFieldAry, " LIKE '%" & lsKeyword & "%' OR ")
& " LIKE '%" & lsKeyword & "%')"
     Next
     lsSQL = lsSQL & ")"
     End If
     If Not lsSQL = "" Then lsSQL = "(" & lsSQL & ")"
     buildQuery = lsSQL
    End Function
    '---------------------------------------
    '     ----------------------------------------
    '     
    %>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲国产成人精品一区二区| 日韩小视频在线观看| 91精品久久久久久久久久久久久| 国产亚洲欧美一区| 亚洲国产婷婷香蕉久久久久久| 久久久久国产精品一区| 亚洲国产天堂久久国产91| 久久国内精品一国内精品| 国a精品视频大全| 综合激情国产一区| 精品国产依人香蕉在线精品| 亚洲欧洲免费视频| 久久天天躁狠狠躁夜夜躁| 亚洲伊人成综合成人网| 日韩一区二区三区在线播放| 久久亚洲国产精品成人av秋霞| 永久免费毛片在线播放不卡| 欧美高清在线观看| 国产午夜精品美女视频明星a级| 国产成人精品在线播放| 深夜成人在线观看| 国产精品第8页| 成人精品aaaa网站| 欧美高清视频在线观看| 欧美精品一区在线播放| 亚洲精品成人久久电影| 精品美女永久免费视频| 国产一区二区欧美日韩| 日韩在线播放一区| 国产精品自产拍在线观看| 欧美中文字幕视频在线观看| 国产网站欧美日韩免费精品在线观看| 北条麻妃一区二区在线观看| 日韩精品在线视频美女| 国产精品久久久久一区二区| 久久全球大尺度高清视频| 国产97在线视频| 日韩av免费在线观看| 日日骚av一区| 久久久久五月天| 中文字幕亚洲精品| 神马国产精品影院av| 亚洲精品国产品国语在线| 欧美华人在线视频| 国产一区二区三区日韩欧美| 国产情人节一区| 国产精品一区二区三区成人| 日韩影视在线观看| 亚洲精品免费网站| 亚洲精品国产拍免费91在线| 一区二区三区精品99久久| 国产精品久久久久久亚洲影视| 日韩精品视频在线观看免费| 91九色国产视频| 久久亚洲精品毛片| 久久理论片午夜琪琪电影网| 中文欧美在线视频| 日本欧美国产在线| 国产午夜精品一区理论片飘花| 97精品在线观看| 少妇久久久久久| 欧洲亚洲女同hd| 国产精品啪视频| 91精品国产自产在线| 欧美成人精品影院| 最近2019年好看中文字幕视频| 亚洲自拍偷拍福利| 黄色成人av网| 中文字幕精品网| 国产亚洲成精品久久| 久久中文字幕视频| 欧美在线播放视频| 日韩69视频在线观看| 萌白酱国产一区二区| 亚洲国产精彩中文乱码av在线播放| 日韩视频欧美视频| 精品爽片免费看久久| 欧美成人精品一区| 国产精品专区h在线观看| 国产精品视频一| 91探花福利精品国产自产在线| 国产精品亚洲视频在线观看| 97超级碰碰碰| 国产欧美日韩中文| 亚洲国产婷婷香蕉久久久久久| 欧美自拍视频在线观看| 久久久久久尹人网香蕉| 国产精品丝袜一区二区三区| 91免费版网站入口| 亚洲永久在线观看| 色老头一区二区三区在线观看| 欧美日韩国产91| 精品视频—区二区三区免费| 日韩小视频在线| 成人免费激情视频| 日韩理论片久久| 亚洲视频电影图片偷拍一区| 国产亚洲激情在线| 国产成人综合一区二区三区| 欧美激情一区二区三级高清视频| 91免费国产网站| 91精品在线影院| 国产精品稀缺呦系列在线| 精品欧美激情精品一区| 精品成人国产在线观看男人呻吟| 欧美日韩爱爱视频| 久久91精品国产| 疯狂做受xxxx高潮欧美日本| 2019日本中文字幕| 亚洲二区中文字幕| 欧美裸体xxxx| 成人黄色免费看| 国产盗摄xxxx视频xxx69| 91久久精品久久国产性色也91| 国产免费一区视频观看免费| 欧美中文字幕视频在线观看| 三级精品视频久久久久| 久久国产精品偷| 欧美日韩在线视频首页| 欧美电影《睫毛膏》| 88xx成人精品| 国产在线精品成人一区二区三区| 亚洲一区二区三区在线免费观看| 亚洲一区国产精品| 欧美老女人www| 亚洲最大的网站| 欧美性xxxxx| 亚洲色图18p| 亚洲精品久久久一区二区三区| 日韩av中文字幕在线| 色综合久久久888| 日韩av在线免费看| 国产精品青草久久久久福利99| 成人网页在线免费观看| 欧美日韩激情美女| 欧美裸身视频免费观看| 欧美老女人xx| 欧美激情va永久在线播放| 久久久久久亚洲| 人体精品一二三区| 中文字幕亚洲无线码在线一区| 最近中文字幕2019免费| 日韩国产高清视频在线| 91在线视频一区| 成人中文字幕+乱码+中文字幕| 中文字幕精品一区二区精品| 久久国产精品久久久久久久久久| 亚洲一区中文字幕在线观看| 成人久久一区二区| 亚洲xxx视频| 欧美壮男野外gaytube| 亚洲最大的成人网| 成人亚洲综合色就1024| 精品久久久久久久久久| 色婷婷av一区二区三区在线观看| 亚洲一区二区三区sesese| 久久久久久久久久国产精品| 国产精品成人v| 久久亚洲春色中文字幕| 精品国产一区久久久| 日韩av成人在线观看| 2019中文字幕全在线观看| 国产成人精品a视频一区www| 日本不卡高字幕在线2019|