%
'==============================================================
' TableEditoR 0.81 Beta
' http://www.2enetworx.com/dev/projects/tableeditor.asp
'--------------------------------------------------------------
' File: te_showtable2.asp
' Description: Displays the selected table contents (Generic)
' Initiated By Hakan Eskici on Nov 07, 2000
'--------------------------------------------------------------
' Copyright (c) 2002, 2eNetWorX/dev.
'
' TableEditoR is distributed with General Public License.
' Any derivatives of this software must remain OpenSource and
' must be distributed at no charge.
' (See license.txt for additional information)
'
' See Credits.txt for the list of contributors.
'
' Change Log:
'--------------------------------------------------------------
' # Mar 26, 2001 by Hakan Eskici
' Added support for automatic primary key detection
' Added support for multiple primary keys
' # Mar 28, 2001 by Hakan Eskici
' Modified the recordset paging control
' # Mar 29, 2001 by Hakan Eskici
' Added support for SQL Server boolean values
' Modified request's to .form or .querystring
' Added support for deleting multiple records
' # May 11, 2002 by Hakan Eskici
' Added page selector max check
' Added button for exporting the whole table
' # May 20, 2002 by Rami Kattan
' More backward browser compatibility
' Support for non-javascript browsers
' Fixed export from Stored Procedures
' Options for working with no-popups
' # Jun 3, 2002 by Rami Kattan
' Fixes for Konqueror for linux
'==============================================================
%>
<%
' Get the requested number of records per page
cPerPage = request.querystring("cPerPage")
if cPerPage = "" then cPerPage = iDefaultPerPage
lConnID = request("cid")
sTableName = request("tablename")
sQuery = request("q")
'------------------------------
'added 8/10/01 by j.wilkinson, jwilkinson@mail.com
'added a check for nonAdmin users trying to view the admin table
'This is just checking that the connection ID = 0, assumes that
'non-admin users have no legitimate reason to get to that db at all.
' note that this may not protect against using queries to view
' this db and table
if lConnID=0 and not bAdmin then
response.redirect "te_admin.asp"
end if
'------------------------------
%>
<%
lConnID = request.querystring("cid")
sTableName = request.querystring("tablename")
sQuery = request.querystring("q")
if sQuery <> "" and sQuery <> "0" then
bQuery = True
sTableName = replace(sTableName, """", "'")
end if
if request.querystring("cid") = "0" AND request.querystring("tablename") = "Databases" then
EditScriptName = "te_addDB"
else
EditScriptName = "te_showrecord"
end if
if bJSEnable then
%>
<% end if %>
|
Home » Connections » <% allTablesCombo() %> » <% if bQuery then
response.write "Query"
else
response.write "Table: ["
allTablesCombo2(lConnID)
response.write "]"
end if%>
|
<%
function isPrimaryKey(sFieldName)
bPrimaryKey = False
for iPK = 0 to ubound(aPrimaryKeys)
if LCase(sFieldName) = LCase(aPrimaryKeys(iPK)) then
bPrimaryKey = True
exit for
end if
next
isPrimaryKey = bPrimaryKey
end function
OpenRS arrConn(lConnID)
'Added by Hakan
'Find the primary key of the given table
dim aPrimaryKeys
if arrType(lConnID) <> tedbDsn then
set rsX = conn.openSchema(adSchemaPrimaryKeys)
do while not rsX.eof
if (rsX("table_name") = sTableName) then
if sPrimaryKeyFieldName = "" then
sPrimaryKeyFieldName = rsX("column_name")
else
sPrimaryKeyFieldName = sPrimaryKeyFieldName & "," & rsX("column_name")
end if
end if
rsX.movenext
loop
rsX.close
end if
if (sPrimaryKeyFieldName = "") and (bQuery = False) then
sSoWhat = "(So What?)"
if arrType(lConnID) = tedbDsn then
response.write "Automatic primary key detection is not possible for DSN Connections. " & sSoWhat & "
"
else
response.write "This table does not have any primary keys. " & sSoWhat & "
"
end if
else
'response.write "Primary key(s): " & sPrimaryKeyFieldName & "
"
end if
'Set the primary key field to first field in the list by default
if sPrimaryKeyFieldName = "" then sPrimaryKeyFieldName = 0
'Search Support Added by Kevin
if request.form("cmdSearch") <> "" then
bQuery = True
'Renamed cmdSubstring to chkSubstring
if request.form("chkSubstring") <> "" then
bSubstring = True
end if
'For different data types, added enuming fields
'rather than form fields as Kevin did
sSQL = "SELECT * FROM [" & sTableName & "] "
on error resume next
rs.Open sSQL,,,adCmdTable
for each fld in rs.fields
if request.form(fld.name) <> "" then
sOP = " = "
select case fld.type
case adBoolean
'BUG: What if the user dont want to perform a distinction on the boolean field?
'Added by Hakan
select case arrType(lConnID)
case tedbSqlServer
bTrue = "1"
bFalse = "0"
case else
bTrue = "True"
bFalse = "False"
end select
if len(request.form(fld.name))>0 then sFieldVal = bTrue else sFieldVal = bFalse
case adLongVarBinary
'no search on OLE fields
case adDate
if isDate(request.form(fld.name)) then sFieldVal = "#" & request.form(fld.name) & "#"
case adSmallInt, adInteger, adCurrency, adUnsignedTinyInt
if isNumeric(request.form(fld.name)) then sFieldVal = request.form(fld.name)
case else
sFieldVal = "'" & replace(request.form(fld.name),"'", "") & "'"
if bSubstring then
sOp = " LIKE "
sFieldVal = "'%" & request.form(fld.name) & "%'"
else
sFieldVal = "'" & request.form(fld.name) & "'"
end if
end select
iSearchFieldCount = iSearchFieldCount + 1
if iSearchFieldCount = 1 then
sWhere = " WHERE " & fld.name & " " & sOp & sFieldVal
else
sWhere = sWhere & " AND " & fld.name & " " & sOp & sFieldVal
end if
end if
next
sTableName = "SELECT * FROM [" & sTableName & "] " & sWhere
rs.close
end if
if request.querystring("orderby") <> "" then
sOrderBy = " ORDER BY [" & request.querystring("orderby") & "] "
sOrderByLink = "&orderby=" & request.querystring("orderby")
select case request.querystring("dir")
case "desc"
sOrderBy = sOrderBy & " DESC"
sOrderByLink = sOrderByLink & "&dir=desc"
case "asc"
sOrderBy = sOrderBy & " ASC"
sOrderByLink = sOrderByLink & "&dir=asc"
case else
sOrderBy = sOrderBy & " ASC"
sOrderByLink = sOrderByLink & "&dir=asc"
end select
end if
if instr(lcase(sTableName), "order by") <> 0 then
sOrderBy = ""
end if
'Added by Danival
'Modified by Hakan
bProc = request.querystring("proc")
if instr(1, ucase(sTableName), "SELECT") then
sSQL = sTableName & sOrderBy
else
if bProc <> "" then
bRecAdd = False
bRecEdit = False
bRecDel = False
sParamString = request.querystring("paramstring")
sProcURL = "&proc=1¶mstring=" & sParamString
sSQL = "EXEC [" & sTableName & "] " & sParamString
else
sSQL = "SELECT * FROM [" & sTableName & "]" & sWhere & sOrderBy
end if
end if
on error resume next
rs.CursorLocation = adUseServer
rs.Open sSQL, conn, adOpenStatic
if err <> 0 then
response.write "Error: " & err.description & "
"
if bQuery then
response.write "SQL : " & sSQL & "
"
end if
response.write "Click here to go back.
"
CloseRS
%><%
response.end
end if
on error goto 0
'Performance Issue:
'Getting the recordset properties may take long time for tables with many records
lRecs = rs.RecordCount
lFields = rs.Fields.Count
if cPerPage = 0 then
RSPagesize = lRecs
else
RSPagesize = cPerPage
end if
if isNumeric(request("ipage")) then iPage = CLng(request("ipage"))
rs.PageSize = RSPagesize
rs.CacheSize = RSPagesize
iPageCount = rs.PageCount
if iPage < 1 then iPage = 1
if lRecs > 0 then rs.AbsolutePage = iPage
if bQuery or te_debug then
response.write sSQL & "
"
end if
if bPopUps then AddRecURL = "javascript:openWindow('"
AddRecURL = AddRecURL & EditScriptName & ".asp?cid=" & lConnID & "&tablename=" & server.UrlEncode(sTableName) & "&add=1&ipage=" & iPage & "&recs=" & RSPagesize
if bPopUps then AddRecURL = AddRecURL & "')"
FormAction = "#"
if not bJSEnable then FormAction = "te_formaction.asp"
if bJSEnable then
%>
<% end if %>