<% Option Explicit Response.Buffer = True Session.LCID = 1030 ' This script can be used freely as long as all copyright messages are intact ' Morten Neesgaard, www.opfinderen.dk (c) 2004 Response.Expires = -1 Response.AddHeader "pragma", "no-cache" Response.CacheControl="no-cache" Response.AddHeader "cache-control", "no-store" Dim Opt, Table, Column, Conn, rs, rs2, Datatyper, Indekser, Tabeltyper, Noegletyper, NoegletypeFork, Tabelnavn, Tabeltype, SQL, i, Datatype, Nul, Standard Dim UkendtKolonne, Vaerdi, Unsigned, Auto, SQL2, Kolonnenavn, Indeksnavn, Indekstype, Arr_Constraints, Fremmednoegle, TabelogFelt, Primaernoegle Dim Noegletype, Arr_Keys, j, NoegletypeTemp, Count, BlobKolonner, Field, Bytes, NyTabel Dim NytKolonnenavn, NyDatatype, NyVaerdi, NyNul, NyStandard, NyAuto, NyUnsigned, SQLFejl Dim Start, No, ResIalt, FSO Opt = Request.Querystring("opt") Table = Request.Querystring("table") Column = Request.Querystring("column") Function Post() If Request.ServerVariables("Request_Method") = "POST" Then Post = True End Function Function Redirect(URL) Set rs = Nothing Set Conn = Nothing Response.Redirect URL End Function Function UkendtTabel(Navn) On Error Resume Next Conn.Execute("Select * From `" & Navn & "`") If Err Then UkendtTabel = True On Error GoTo 0 End Function Function RunQuery(SQL) On Error Resume Next Conn.Execute(SQL) If Err Then RunQuery = "Forespørgslen " & SQL & " returnerede følgende fejlmeddelelse:
" RunQuery = RunQuery & "" & Err.Description & "

" SQLFejl = True End If On Error GoTo 0 End Function Datatyper = Array("char", "varchar", "tinytext", "text", "mediumtext", "longtext", "tinyint", "smallint", "mediumint", "int", "bigint", "float", "double", "decimal", "date", "datetime", "timestamp", "time", "enum", "set", "tinyblob", "mediumblob", "blob", "longblob") Indekser = Array("index", "unique", "primary key", "fulltext") Tabeltyper = Array("myisam", "innodb") Noegletyper = Array("", "on update cascade", "on delete cascade", "on delete cascade on update cascade") NoegletypeFork = Array("ODR / OUR", "ODR / OUC", "ODC / OUR", "ODC / OUC") %> Opfinderen.dk | MySqlManager <% If Request.Form("database") <> "" Then Session("Database") = Request.Form("database") Session("server") = Request.Form("server") Session("UID") = Request.Form("uid") Session("PWD") = Request.Form("pwd") End If Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "
" Response.Write "
" Response.Write "Database:      " Response.Write "Server:      " Response.Write "ID:      " Response.Write "P/W:      " Response.Write "" Response.Write "
" Response.Write "
" Response.Write "MySqlManager 2.0
Opfinderen © 2004" Response.Write "
" Response.Write "


" On Error Resume Next Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open ("DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & Session("Server") & "; DATABASE=" & Session("Database") & "; UID=" & Session("UID") & "; PWD=" & Session("PWD") & ";") If Err Or Session("Database") = "" Then Response.Write "Der kan ikke oprettes forbindelse til databasen " & Session("Database") & " med de angivne oplysninger!" Response.Write "" Response.Write "" Set Conn = Nothing Response.End End If On Error GoTo 0 If Opt = "table" Then If UkendtTabel(Table) And Table <> "" Then Response.Write "Tabellen " & Table & " findes ikke i databasen!
Gå til oversigten" Else If Table = "" Then Response.Write "" & Session("Database") & " -> Ny tabel" Else Response.Write "" & Session("Database") & " -> " & Table & "" Set rs = Conn.Execute("Show Table Status Like '" & Table & "'") Tabelnavn = Table Tabeltype = rs("Type") End If Response.Write "


" If Post() Then Tabelnavn = Request.Form("tabelnavn") Tabeltype = Request.Form("tabeltype") NytKolonnenavn = Request.Form("nytkolonnenavn") NyDatatype = Request.Form("nydatatype") NyVaerdi = Request.Form("nyvaerdi") NyStandard = Request.Form("nystandard") NyNul = Request.Form("nynul") NyUnsigned = Request.Form("nyunsigned") NyAuto = Request.Form("nyauto") If Table = "" Then SQL = "Create Table `" & Tabelnavn & "` (`" & NytKolonnenavn & "` " & NyDatatype If Trim(NyVaerdi) <> "" Then SQL = SQL & "(" & NyVaerdi & ")" If NyUnsigned = "ja" Then SQL = SQL & " Unsigned" If NyAuto = "ja" Then SQL = SQL & " Auto_Increment Primary Key" If NyNul = "" Then SQL = SQL & " Not Null" If Trim(NyStandard) <> "" Then SQL = SQL & " Default '" & NyStandard & "'" SQL = SQL & ")" If Tabeltype <> "" Then SQL = SQL & " Type=" & Tabeltype Response.Write RunQuery(SQL) If Not SQLFejl Then Redirect("default.asp?opt=table&table=" & Server.URLencode(Tabelnavn)) Else If Table <> Tabelnavn Then SQL = "Alter Table `" & Table & "` Rename As `" & Tabelnavn & "`" Response.Write RunQuery(SQL) If Not SQLFejl Then Table = Tabelnavn End If SQL = "Alter Table `" & Table & "` Type = " & Tabeltype Response.Write RunQuery(SQL) Set rs = Conn.Execute("Show Columns From `" & Table & "`") Count = 0 While Not rs.EOF Count = Count + 1 If Request.Form("opdater" & Count) = "ja" Then SQL = "Alter Table `" & Table & "` Change Column `" & rs("Field") & "` `" & Request.Form("kolonnenavn" & Count) & "` " & Request.Form("datatype" & Count) If Trim(Request.Form("vaerdi" & Count)) <> "" Then SQL = SQL & "(" & Request.Form("vaerdi" & Count) & ")" If Request.Form("unsigned" & Count) = "ja" Then SQL = SQL & " Unsigned" If Request.Form("auto" & Count) = "ja" Then SQL = SQL & " Auto_Increment" If Request.Form("nul" & Count) = "" Then SQL = SQL & " Not Null" If Trim(Request.Form("standard" & Count)) <> "" Then SQL = SQL & " Default '" & Request.Form("standard" & Count) & "'" Response.Write RunQuery(SQL) End If rs.MoveNext Wend If Trim(NytKolonnenavn) <> "" Then SQL = "Alter Table `" & Table & "` Add Column `" & NytKolonnenavn & "` " & NyDatatype If Trim(NyVaerdi) <> "" Then SQL = SQL & "(" & NyVaerdi & ")" If NyUnsigned = "ja" Then SQL = SQL & " Unsigned" If NyAuto = "ja" Then SQL = SQL & " Auto_Increment Primary Key" If NyNul = "" Then SQL = SQL & " Not Null" If Trim(NyStandard) <> "" Then SQL = SQL & " Default '" & NyStandard & "'" Response.Write RunQuery(SQL) End If If Not SQLFejl Then Redirect("default.asp?opt=table&table=" & Server.URLencode(Table)) End If End If If Request.Querystring("action") = "delete" Then If Column = "" Then SQL = "Drop Table `" & Table & "`" Response.Write RunQuery(SQL) If Not SQLFejl Then Redirect("default.asp") Else SQL = "Alter Table `" & Table & "` Drop Column `" & Column & "`" Response.Write RunQuery(SQL) If Not SQLFejl Then Redirect("default.asp?opt=table&table=" & Server.URLencode(Table)) End If End If Response.Write "" Response.Write "" Response.Write "" Response.Write "" If Table = "" Then Response.Write "" Else Response.Write "" End If Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "
Tabelnavn: 
  • Indekser/nøgler
  • Data
  • Tabeltype:


    " If Table = "" Then Response.Write "" Else Response.Write " " End If Response.Write "


    " Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" If Table <> "" Then Set rs = Conn.Execute("Show Columns From `" & Table & "`") Count = 0 While Not rs.EOF Count = Count + 1 If Post() Then Kolonnenavn = Request.Form("kolonnenavn" & Count) Datatype = Request.Form("datatype" & Count) Vaerdi = Request.Form("vaerdi" & Count) Unsigned = Request.Form("unsigned" & Count) Nul = Request.Form("nul" & Count) Standard = Request.Form("standard" & Count) Else Kolonnenavn = rs("Field") Datatype = rs("Type") Vaerdi = "" Unsigned = "" If InStr(Datatype, "(") Then Vaerdi = Mid(Datatype, InStr(Datatype, "(") + 1, InStrRev(Datatype, ")") - InStr(Datatype, "(") - 1) Datatype = Trim(Replace(Datatype, "(" & Vaerdi & ")", "")) End If If InStr(Datatype, "unsigned") Then Unsigned = "ja" Datatype = Trim(Replace(Datatype, "unsigned", "")) End If Nul = Replace(rs("Null"), "YES", "ja") Standard = rs("Default") End If Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" rs.MoveNext Wend End If Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "
    KolonnenavnDatatypeUnsignedNulværdiStandardværdiAutonrIndeks
    " If InStr(Datatype, "int") And rs("Extra") <> "auto_increment" Then Response.Write "" Else Response.Write " " End If Response.Write "" If rs("Extra") <> "auto_increment" Then Response.Write "" Else Response.Write " " End If Response.Write "" If rs("Extra") <> "auto_increment" Then Response.Write "" Else Response.Write " " End If Response.Write "" If rs("Extra") = "auto_increment" Then Response.Write "" Else Response.Write " " End If Response.Write "" & rs("Key") & " Slet
     
    " Response.Write "" End If ElseIf Opt = "idxkeys" Then If UkendtTabel(Table) Then Response.Write "Tabellen " & Table & " findes ikke i databasen!
    Gå til oversigten" Else Response.Write "" & Session("Database") & " -> " & Table & " -> Indekser/nøgler" Response.Write "


    " If Post() Then If Request.Form("kolonnenavn") <> "" Then Kolonnenavn = Request.Form("kolonnenavn") Indeksnavn = Request.Form("indeksnavn") Indekstype = Request.Form("indekstype") If Trim(Indeksnavn) = "" Then Indeksnavn = Kolonnenavn SQL = "Alter Table `" & Table & "` Add " & Indekstype & " `" & Indeksnavn & "` (`" & Kolonnenavn & "`)" ElseIf Request.Form("fremmednoegle") <> "" Then Fremmednoegle = Request.Form("fremmednoegle") Primaernoegle = Request.Form("primaernoegle") Noegletype = Request.Form("noegletype") SQL = "Alter Table `" & Table & "` Add Constraint Foreign Key (`" & Fremmednoegle & "`) References " & Primaernoegle & " " & Noegletype End If End If If Request.Querystring("deleteindex") = "PRIMARY" Then SQL = "Alter Table `" & Table & "` Drop Primary Key" ElseIf Request.Querystring("deleteindex") <> "" Then SQL = "Alter Table `" & Table & "` Drop Index `" & Request.Querystring("deleteindex") & "`" ElseIf Request.Querystring("deletefk") <> "" Then SQL = "Alter Table `" & Table & "` Drop Foreign Key `" & Request.Querystring("deletefk") & "`" End If If SQL <> "" Then Response.Write RunQuery(SQL) If Not SQLFejl Then Redirect("default.asp?opt=idxkeys&table=" & Server.URLencode(Table)) End If Set rs = Conn.Execute("Show Keys From `" & Table & "`") Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" While Not rs.EOF Response.Write "" Response.Write "" Response.Write "" Response.Write "" rs.MoveNext Wend Response.Write "" Response.Write "" Response.Write "" Set rs = Conn.Execute("Show Columns From `" & Table & "`") Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "
    KolonnenavnIndeksnavnIndekstype
    " & rs("Column_name") & "" & rs("Key_name") & "" If rs("Key_Name") = "PRIMARY" Then Response.Write "Primær" ElseIf rs("Index_type") = "FULLTEXT" Then Response.Write "FullText" ElseIf rs("Non_unique") = "0" Then Response.Write "Unique" Else Response.Write "Index" End If Response.Write "Slet
     


    " Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Set rs = Conn.Execute("Show Create Table `" & Table & "`") Arr_Constraints = Split(rs("Create Table"), "CONSTRAINT") If UBound(Arr_Constraints) > 0 Then For i = 1 To UBound(Arr_Constraints) Arr_Keys = Split(Arr_Constraints(i), "`") For j = 0 To UBound(Noegletyper) If InStr(1, Arr_Constraints(i), Noegletyper(j), 1) Then NoegletypeTemp = NoegletypeFork(j) Next Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Next End If Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Set rs = Conn.Execute("Show Table Status") Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "" Response.Write "
    FremmednøglePrimærnøgleNøgletypeNøgleID
    " & Arr_Keys(3) & "" & Arr_Keys(5) & " (" & Arr_Keys(7) & ")" & NoegletypeTemp & "" & Arr_Keys(1) & "Slet
     
    (Autogenereres)



    " Response.Write "For at fremmednøgler kan benyttes, skal tabellerne være af typen InnoDB.
    " Response.Write "Kolonnen der skal være fremmednøgle, skal på forhånd være forsynet med et indeks.

    " Response.Write "ODR (On Delete Restrict): En primærnøgle kan ikke slettes, hvis én eller flere fremmednøgler relaterer til den.
    " Response.Write "ODC (On Delete Cascade): Fremmednøgler slettes automatisk, hvis den tilhørende primærnøgle slettes.
    " Response.Write "OUR (On Update Restrict): En primærnøgle kan ikke opdateres, hvis én eller flere fremmednøgler relaterer til den.
    " Response.Write "OUC (On Update Cascade): Fremmednøgler opdateres automatisk, hvis den tilhørende primærnøgle opdateres." End If ElseIf Opt = "data" Then If UkendtTabel(Table) Then Response.Write "Tabellen " & Table & " findes ikke i databasen!
    Gå til oversigten" Else Response.Write "" & Session("Database") & " -> " & Table & " -> Data" Response.Write "


    " End If Set rs = Conn.Execute("Select Count(*) From `" & Table & "`") ResIalt = CLng(rs(0)) If ResIalt = 0 Then Response.Write "Der er ingen poster i tabellen..." Else Start = Request.Querystring("start") No = Request.Querystring("no") If Not IsNumeric(CStr(Start)) Then Start = 0 If CLng(Start) > ResIalt Or CLng(Start) >= CLng(No) Then Start = 0 If Not IsNumeric(CStr(No)) Then No = Start + 50 If CLng(No) > ResIalt Then No = ResIalt Response.Write "
    " Response.Write "" Response.Write "" Response.Write "Viser nu post til ud af " & ResIalt & "    


    " Response.Write "
    " Count = 0 Set rs = Conn.Execute("Show Columns From `" & Table & "`") While Not rs.EOF If InStr(1, rs("Type"), "blob", 1) Then BlobKolonner = BlobKolonner & "#" & rs("Field") & "#" Count = Count + 1 rs.MoveNext Wend Response.Write "" Set rs = Conn.Execute("Select * From `" & Table & "` Limit " & Start & ", " & No - Start) Response.Write "" For Each Field In rs.Fields Response.Write "" Next Response.Write "" Count = 0 While Not rs.EOF Response.Write "" For Each Field In rs.Fields If InStr(BlobKolonner, "#" & Field.Name & "#") Then Response.Write "" ElseIf IsNull(Field.Value) Then Response.Write "" Else Response.Write "" End If Next Response.Write "" Count = Count + 1 rs.MoveNext Wend Response.Write "
    " End If ElseIf Opt = "dbstructure" Then Response.Write "" & Session("Database") & " -> Databasestruktur" Response.Write "


    " Set rs = Conn.Execute("Show Table Status") While Not rs.EOF Set rs2 = Conn.Execute("Show Create Table `" & rs("Name") & "`") Response.Write Replace(Server.HTMLencode(rs2("Create Table")), "CREATE TABLE `" & Server.HTMLencode(rs("Name")) & "`", "CREATE TABLE `" & Server.HTMLencode(rs("Name")) & "`") & "

    " rs.MoveNext Wend Else Set rs = Conn.Execute("Show Table Status") Response.Write "" Response.Write "" Response.Write "" Response.Write "" Count = 0 Bytes = 0 While Not rs.EOF Response.Write "" Response.Write "" Response.Write "" Count = Count + 1 Bytes = Bytes + CLng(rs("Data_length")) rs.MoveNext Wend Response.Write "" Response.Write "" Response.Write "" Response.Write "
    TabelnavnTypeStørrelse  
    " & rs("Name") & "" & rs("Type") & "" & FormatNumber(CLng(rs("Data_length")) / 1000, 0) & " KB  
    " & Count & " tabeller " & FormatNumber(Bytes / 1000, 0) & " KB  


    " Response.Write ">> Opret ny tabel
    " Response.Write ">> Se databasestruktur" End If Set rs = Nothing Set rs2 = Nothing Set Conn = Nothing %>