<% '============================================================== ' TableEditoR 0.81 Beta ' http://www.2enetworx.com/dev/projects/tableeditor.asp '-------------------------------------------------------------- ' File: te_addDB.asp ' Description: Adds new database definitions ' Initiated By Rami Kattan on April 22, 2002 '-------------------------------------------------------------- ' 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: '-------------------------------------------------------------- ' # Jun 3, 2002 by Rami Kattan ' Note about Brwose button if Popups is disabled ' Hide browse button for linux Konqueror '============================================================== %> <% if len(request.querystring("q"))>0 then bQuery = True else bQuery = False %>
<% if bPopUps then %> <% =arrDesc(Cint(request.querystring("cid"))) %> » Table [<% =request.querystring("tablename") %>] » <% if request.querystring("add") then response.write "Add" else response.write "Edit" %> Database <% else %> Home » Connections » "><%=arrDesc(Cint(request.querystring("cid")))%> » &tablename=<%=server.urlencode(request.querystring("tablename"))%>&ipage=<%response.write(request.querystring("ipage"))%><% if bQuery then response.write("&q=1") end if %>">Table [<%=request.querystring("tablename")%>] » <%if request.querystring("add") then response.write "Add" else response.write "Edit"%> Database <% if bProtected then response.write session("teFullName") response.write " (logout)" end if %> <% end if %>

<% 'disallow connections to admin table for nonadmin users 11/14/01 lConnID = request("cid") if (lConnID = 0) and bAdmin = False then response.write "Not authorized to view this connection." %><% response.end end if sTableName = request.querystring("tablename") sFieldNames = request.querystring("fld") sFieldValues = request.querystring("val") sFieldTypes = request.querystring("fldtype") iPage = request.querystring("ipage") sQuery = request.querystring("q") if request.querystring("add") then bAdd = True else bAdd = False if request.form("cmdSave") <> "" AND instr(request.form("DB_loc"), "teadmin.mdb") then response.write "This connection cannot be added." %><% response.end end if sParentName = server.urlencode(sTableName) OpenRS arrConn(lConnID) if not bAdd then 'Added by Hakan 'Support for multiple primary keys aFieldNames = split(sFieldNames, ";") aFieldTypes = split(sFieldTypes, ";") aFieldValues = split(sFieldValues, ";") select case arrType(lConnID) case tedbSQLServer sDateSeperator = "'" case else sDateSeperator = "#" end select for iFld = 0 to ubound(aFieldNames) sFieldName = aFieldNames(iFld) lFieldType = CLng(aFieldTypes(iFld)) sFieldValue = aFieldValues(iFld) select case lFieldType case adDate, adDBDate, adDBTime, adDBTimeStamp if isDate(sFieldValue) then sFieldValue = cDate(sFieldValue) sFieldValue = month(sFieldValue) & "/" & day(sFieldValue) & "/" & year(sFieldValue) end if if sWhereFields = "" then sWhereFields = "([" & sFieldName & "]=" & sDateSeperator & sFieldValue & sDateSeperator & ")" else sWhereFields = sWhereFields & " AND ([" & sFieldName & "]=" & sDateSeperator & sFieldValue & sDateSeperator & ")" end if case adTinyInt, adSmallInt, adInteger, adBigInt, adUnsignedTinyInt, adUnsignedSmallInt, adUnsignedInt, adUnsignedBigInt, adSingle, adDouble, adCurrency, adDecimal, adNumeric, adBoolean 'Added by Hakan 'Convert decimal point to dot if it's a comma sFieldValue = replace(sFieldValue, ",", ".") if sWhereFields = "" then sWhereFields = "([" & sFieldName & "]=" & sFieldValue & ")" else sWhereFields = sWhereFields & " AND ([" & sFieldName & "]=" & sFieldValue & ")" end if case else 'Added by Hakan 'Prepare SQL value by replacing single quote with two single quotes sFieldValue = replace(sFieldValue, "'", "''") if sWhereFields = "" then sWhereFields = "([" & sFieldName & "]='" & sFieldValue & "')" else sWhereFields = sWhereFields & " AND ([" & sFieldName & "]='" & sFieldValue & "')" end if end select next sWhere = " WHERE " & sWhereFields else sWhere = "" end if iPlace = instr(1, sTableName, " wHeRe ", 1) if iPlace then sTableName = left(sTableName, iPlace) end if 'Added by Danival if instr(1, ucase(sTableName),"SELECT") then sSQL = sTableName & sWhere else sSQL = "SELECT * FROM [" & sTableName & "]" & sWhere end if 'response.write sSQL rs.Open sSQL, , , adCmdTable 'Added By Brad Orgill 'Reads FK's and PK's into an array if arrType(lConnID) <> tedbDsn then Set rs3 = conn.OpenSchema(adSchemaForeignKeys) Dim fkeyary() Dim numRows numRows = 0 Do While NOT rs3.EOF numRows = numRows + 1 ReDim Preserve fkeyary(1, numRows) fkeyary(0, numRows - 1) = rs3("FK_COLUMN_NAME") 'reads FK names fkeyary(1, numRows - 1) = rs3("PK_Column_Name") 'reads PK names rs3.MoveNext Loop rs3.Close end if Dim h if request.form("cmdSave") <> "" and bRecEdit then if bAdd then rs.AddNew end if for each fld in rs.fields ifield = ifield + 1 'If field is AutoIncrement, just skip it. 'Added By Brad Orgill donada = false fldName = fld.name 'on error resume next 'modified By Brad Orgill if (fld.properties("IsAutoIncrement") = false) AND (not donada) then For h = 0 to numrows - 1 if (fldName = fkeyary(1, h)) then 'OR (fldName = fkeyary(0, h)) then remove the coment to disallow FK updates donada = true end if Next if true then ' By Rami, line was "if (not donada) then" select case fld.type case adBoolean if len(request.form(fld.name)) then rs(fld.name) = True else rs(fld.name) = False case adLongVarBinary 'noop case adDate if ( request.form(fld.name) = "" or request.form(fld.name) = "0" ) and (fld.attributes and adFldIsNullable) = adFldIsNullable and bConvertDateNull then rs(fld.name) = NULL else if isDate(request.form(fld.name)) then rs(fld.name) = request.form(fld.name) end if end if case adSmallInt, adInteger, adCurrency, adUnsignedTinyInt if ( request.form(fld.name) = "" or request.form(fld.name) = "0" ) and (fld.attributes and adFldIsNullable) = adFldIsNullable and bConvertNumericNull then rs(fld.name) = NULL else if isNumeric(request.form(fld.name)) then rs(fld.name) = request.form(fld.name) end if end if case else if request.form(fld.name) = "" and (fld.attributes and adFldIsNullable) = adFldIsNullable and bConvertNull then rs(fld.name) = NULL else rs(fld.name) = request.form(fld.name) end if end select if Err <> 0 then response.write "Error while updating field '" & fld.name & "'
" response.write "Description: " & err.description & "
" select case err case -2147352571 'Type mismatch response.write "If this is an auto increment field, you may ignore this error.

" case -2147217887 'Field cannot be updated response.write "If this is an auto increment field, you may ignore this error.

" case else response.write "
" bError = True end select err = 0 else 'Added to enable editing of first field. if iField = 1 then sFieldValue = request.form(fld.name) end if end if end if end if next rs.update if err <> 0 then response.write "Error while updating.
" response.write "Description: " & err.description & "
" bError = True err = 0 end if if not bError then if request.querystring("cmdsave") <> "" and not request.querystring("add") then response.write "Database updated" else response.write "Database added" end if end if end if on error goto 0 if not bAdd then DB_Desc = rs("DB_Desc") DB_type = rs("DB_type") DB_loc = rs("DB_loc") DB_priv = rs("DB_privileges") end if if not bPopUps then PopUpAsterisk = "*" bBrowseButton = bJSEnable and not isKo %>
" method="post" name="frm"> <% if bBrowseButton and not bPopUps then response.write "" %>
Description
Type
Location <% if bBrowseButton then %> <% end if %>
Required Privileges
<% if bPopUps then %>       <% end if %>
* Your browser must allow popup windows for the Browse function to work.