Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Making a Database.

Making a Database.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #15 on Wed 08 Oct 2003 06:42 AM (UTC)

Amended on Wed 08 Oct 2003 06:47 AM (UTC) by Xyborg

Message
Thansk Nick. That's a great help. Love learning more about MUSHClient.

Even now that I know what line I'm looking at, I can't see anything wrong with it. I mean... God I hate being a newb. Even after a month or so I'm still clueless to VBscript. *sigh* Now I see why I'm the only one on the muds I play to ever toy with it.

[EDIT]

Nevermind. I fixed it, but now I got another error I don't even know how to deal with.

Error number: -2147221164
Event: Execution of line 47 column 5
Description: Class not registered
Called by: Function/Sub: OnSetup called by timer
Reason: processing timer ""

Comepletely lost here.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #16 on Wed 08 Oct 2003 07:26 PM (UTC)
Message
Hmm. It seems to be saying that the Microsoft Jet ODBC driver is missing. This seems quite odd, since you should have Microsoft.Jet.OLEDB.3.51 installed as standard on Windows 98 and Microsoft.Jet.OLEDB.4.0 on anything newer. Unless it is complaining about using the version independant name, which makes no sense either.

Hmm.. Jusr tested this on mine.. Apparently it won't work, which makes me seriously wonder about the stupidity of even having a version independant ID for such things. It would mean that the program to use the driver would have to search the registry for the short version, then back track to get the real provider. Sigh...

It will probably work if you change it to Microsoft.Jet.OLEDB.4.0, unless you are on Win98, in which case you may need to upgrade. I'll look around and see if I can find why the simplified version doesn't work, in spite of the fact that it is supposed to. :(
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #17 on Wed 08 Oct 2003 08:10 PM (UTC)
Message
Hmm. I just nosed around a bit. Seems that 'some' servers that use ODBC can be accessed through the version independent ID. An example is MSDASQL, which you can access using either the version like 'MSDASQL.1' or the independent ID 'MSDASQL'. It seesm that like any good Micro$loth product, the one people use the most often is broken and can't be accessed through an non-version specific name, thus dooming all of use to having half our programs stop working the moment they upgrade from 4.0 to whatever the next version will be...

The only solution seems to be to check the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet for the 'current' installed version. Of course then you have to look for the highest version number key under that in order to get the correct version.

Of course, assuming that .jod is 'standard' across version you can look in HKEY_CLASES_ROOT\.jod and the full name is in there. This may be specific to 4.0 though.

If the stupid installer worked right it 'should' have installed a key at HKEY_CLASS_ROOT\Microsoft.Jet.OLEDB\CLSID that is the same as the 'latest' version. This is probably where adodb.connection is looking to find the driver and since there isn't one there for it to find.... If you look in there you find entries for both MSDASQL and MSDASQL.1, so this is 99.9% certain to be the heart of why the Jet engine doesn't bloody work right when you try to use it without a version number.



In any case.. Changing the name to Microsoft.Jet.OLEDB.4.0 'should' fix it. It doesn't mean it will work 2-3 years from now on a system using 5.0 or something, but the only 'real' solution right now is to either add a key to the registry yourself to 'fix' the issue or search the registry every bloody time you start the plugin to figure out what the version is you need to use. Either solution is a stupid waste of the programmers time imho.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #18 on Wed 08 Oct 2003 11:28 PM (UTC)
Message
Ok. Changed the thing to Microsoft.Jet.OLEDB.4.0 which in turn made the script compile for the most part. I did get one error.

Error number: -2146827864
Event: Execution of line 57 column 3
Description: Object required: 'db'
Called by: Function/Sub: OnSetup called by timer
Reason: processing timer ""

which is located in the StartDB function.

  Exists = vbFalse
  For Each oTable In db.Tables
    If UCase(oTable.Name) = UCase("IPData") Then
      Exists = vbTrue
      Exit For
    End If
  Next


Since I don't know anything about this database stuff and Microshaft crap, I don't know what I'm doing. But even though I got that error, the script still runs. I can't add/list/clear anything because I get the following error:

ip:clear gave me this.
The Microsoft Jet database engine cannot find the input table or query 'IPList'. Make sure it exists and that its name is spelled correctly.
ip:list gave me this.
The Microsoft Jet database engine cannot find the input table or query 'IPData'. Make sure it exists and that its name is spelled correctly.
ip:add gave me this.
Could not find output table 'IPList'.

and the rest of the errors are pretty much the same.

But I do get the "IPList database created." when I load the plugin.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #19 on Thu 09 Oct 2003 12:10 AM (UTC)
Message
Hmm. OK. db.Tables should be CatHandle.Tables. I missed this one. Basically it works like this:

object.item

Where object is a 'handle' that points to or sort of contains the item, in this case the ADOX.Catalog. Item is either 1) a property (something you read/set) or 2) a function/sub that gets called.

Hmm.. looking at my code I did this wrong anyway. The code should be:


  if not Exists then
    CatHandle.Create GetProvider
    world.ColourNote "lightblue", "midnightblue", "IPList database created."
  end if

  'Get a connection to the provider to check tables.
  CatHandle.ActiveConnection = GetProvider

  'Check to see if Table (the actually storage place) exists.
  Exists = vbFalse
  For Each oTable In CatHandle.Tables
    If UCase(oTable.Name) = UCase("IPData") Then
      Exists = vbTrue
      Exit For
    End If
  Next

  if not Exists then
    'Create the table.
    if DoSQL ("CREATE TABLE IPData (" & _
      "  ip_address varchar(15) NOT NULL," & _
      "  player_name varchar(64) NOT NULL)") Then
      world.ColourNote "lightblue", "midnightblue", "IPList database created."
    else
      StartDB = 2
      Exit Function 
    end if
  end if

  'Close the ADOX connection.
  Set CatHandle = Nothing

  'Open our database.
  Set DBHandle = CreateObject ("ADODB.Connection")
  DBHandle.Open GetProvider


Now for the other issues:

The code for ip:clear, ip:add and ip:remove is flat out wrong. Replace IPList with IPData in the subs 'Add', 'Remove' and 'ClearList'. The code in 'List' should be right, but I suspect that the mistakes in StartDB resulted in the database not actually being created. I have no idea why it gave you the 'IPList database created.' message, since it obviously didn't do so.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #20 on Thu 09 Oct 2003 06:25 AM (UTC)
Message
Yay. No compile errors or nothing. Now I just can't get the commands to work and stuff. Gonna give you a list of problem messages I get when I use the ip: commands.

ip:add/ip:remove/ip:clear
Object required

ip:list
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Tried to make a couple changes like adding the 'StartDB = 0' line back in at the end of what you had in your last post and that didn't work.

Anyways. Back to working on my newbish script that will just track the highest number recieved. *sigh* Having a hard time doing that, but I think I'm on the right track.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #21 on Thu 09 Oct 2003 09:01 AM (UTC)
Message
Ok... Here is the fix:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="IPDatabase"
   author="Kagehi Kossori"
   id="5dfbc176dad925866871c1dc"
   language="VBscript"
   purpose="Maintains a database of IPs and player names."
   date_written="2003-10-06"
   date_modified="2003-10-06"
   requires="3.24"
   save_state="y"
   version="1.0"
   >
<description trim="y">
<![CDATA[
  This plugin manages a basic database of players and IPs.
  
  Commands are:
  
  ip:add <Player> <IP Address>   - Adds a player and IP to the database.
  
  ip:remove <Player> - Removes an item from the database, by Player name.
  
  ip:clear <IP Address {optional}> - Will clear all names with a single IP or the entire database.
  
  ip:list <IP or Player {optional)> - This will show an entire like id you leave off the name or IP.
  If you use a name or an IP, then it will list that name and IP or all names associated with that IP.
  
  ip:help - This help page.
  
]]>
</description>
</plugin>
<aliases>
  <alias script="Add"
   match="ip:add * *"
   enabled="y"
   group="commands">
  </alias>
  
  <alias script="List"
   match="ip:list"
   enabled="y"
   group="commands">
  </alias>
  
  <alias script="List"
   match="ip:list *"
   enabled="y"
   group="commands">
  </alias>
  
  <alias script="Remove"
   match="ip:remove *"
   enabled="y"
   group="commands">
  </alias>

  <alias script="ClearList"
   match="ip:clear
   group="commands""
   enabled="y">
  </alias>
</aliases>

<script>
<![CDATA[
dim DBHandle

sub OnPluginInstall
'  timer: enabled, one-shot, active-if-not-connected
  world.addtimer "", 0, 0, 5, "", 1 + 4 + 32, "OnSetup"
end sub

sub Onsetup(tName)
  dim Link
  Link = StartDB
  select case Link
    case 0
      world.ColourNote "lightblue", "midnightblue", "IP list plugin started."
    case 1
      world.ColourNote "white", "red", "ADOX Catalog missing. You may need to download the latest MDAC from Microsoft."
    case 2
      world.ColourNote "white", "red", "Table creation failed."
  end select    
end sub

function GetProvider
  'Uses the "version independent" provider name, to hopefully simplify matters.
  GetProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=IPList.mdb;Jet OLEDB:Engine Type=5;"
end function

function StartDB
  Dim FSO, Exists, CatHandle, oTable
  
  On Error Resume Next

  'Connect to the ADOX functions.
  Set CatHandle = CreateObject ("ADOX.Catalog")
  
  If Err.Number <> 0 Then
    StartDB = 1
    Exit Function 
  End If
  
  On Error Goto 0
  
  'Lets first see if it exists.
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Exists = FSO.FileExists ("IPList.mdb")
  Set FSO = Nothing
  
  if not Exists then
    CatHandle.Create GetProvider
    world.ColourNote "lightblue", "midnightblue", "IPList database created."
  end if
  
  'Get a connection to the provider to check tables.
  CatHandle.ActiveConnection = GetProvider
  
  'Check to see if Table (the actually storage place) exists.
  Exists = vbFalse
  For Each oTable In CatHandle.Tables
    If UCase(oTable.Name) = UCase("IPData") Then
      Exists = vbTrue
      Exit For
    End If
  Next
  
  'Close the ADOX connection.
  Set CatHandle = Nothing

  'Open our database.
  Set DBHandle = CreateObject ("ADODB.Connection")
  DBHandle.Open GetProvider

  if not Exists then
    'Create the table.
    if DoSQL ("CREATE TABLE IPData (" & _
      "  ip_address varchar(15) NOT NULL," & _
      "  player_name varchar(64) NOT NULL)") Then
      StartDB = 2
      Exit Function 
    else
      world.ColourNote "lightblue", "midnightblue", "IPList database created."
    end if
  end if
  
  StartDB = 0 'Return with a code indicating everything was a success (hopefully).
end function

'
'  Execute some arbitrary SQL
'
Function DoSQL (sSQL)
  DoSQL = vbTrue' error return
  On Error Resume Next
  
' Execute it
  DBHandle.Execute sSQL
  If Err.Number <> 0 Then
    world.ColourNote "white", "red", Err.Description
    Exit Function 
  End If

  On Error GoTo 0
  
  DoSQL = vbFalse' OK return
end Function

sub Add (aName, Output, Wilds)
  Dim ip_address, player_name
  player_name = Wilds(1)
  ip_address = Wilds(2)
  note player_name
  note ip_address
  If DoSQL _
    ("INSERT INTO IPData (player_name, ip_address)" & _
          " VALUES (" & _
          """" & player_name & """, " & _
          """" & ip_address & """);") Then Exit Sub         
 
  world.ColourNote "white", "green", "Player '" & player_name & _
     "' added to the database"  
end sub

sub Remove (aName, Output, Wilds)
  If DoSQL _
    ("DELETE FROM IPData WHERE player_name = " & _
          """" & Wilds(1) & """ ") Then Exit Sub
 
  world.ColourNote "white", "green", "Player '" & Wilds(1) & _
     "' deleted from the database"
end sub

sub List (aName, Output, Wilds)
  Dim ip_address, player_name
  Dim rst, count, SQuery
  Dim LastIP
  if Wilds(1) = "" then
    sQuery = "SELECT * FROM IPData ORDER BY ip_address"
  else
    sQuery = "SELECT * FROM IPData WHERE " & _
         "player_name like ""%" & wildcards (1) & "%"" " & _
         "OR ip_address like ""%" & wildcards (1) & "%"" " & _
         "ORDER BY ip_address"
  end if
  
  On Error Resume Next
  
  Set rst = CreateObject ("ADODB.Recordset")
  rst.Open sQuery, DBHandle
  
  If Err.Number <> 0 Then
    world.ColourNote "white", "red", Err.Description
    Set rst = Nothing
    Exit Sub
  End If
  
  count = 0
  ' display each record
  Do Until rst.EOF
    count = count + 1
    ip_address   = rst.Fields ("ip_address").Value
    player_name  = rst.Fields ("player_name").Value
    If LastIP <> ip_address then
      world.note " "
      world.ColourNote "white", "darkred", ip_address & ":"
      LastIP = ip_address
    End If
    
    world.ColourNote "white", "darkred", player_name
    rst.MoveNext
  Loop
  
  Set rst = Nothing
end sub

sub ClearList (aName, Output, Wilds)
  if Wilds(1) <> "" then
    If DoSQL _
    ("DELETE FROM IPData WHERE ip_address = " & _
          """" & Wilds(1) & """ ") Then Exit Sub
    world.ColourNote "white", "green", "IP '" & Wilds(1) & _
     "' deleted from the database"
  else
    If DoSQL("DELETE FROM IPData") Then Exit Sub
    world.ColourNote "white", "green", "All data erased."
  end if
end sub
]]>
</script> 

<!--  Plugin help  -->
<aliases>
  <alias
   script="OnHelp"
   match="ip:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
  World.Note World.GetPluginInfo (World.GetPluginID, 3)
End Sub
]]>
</script> 
</muclient>

Issues I corrected:

1. I had the part that opened the database in the wrong place. I forgot that DOSQL opened it in Nick's version. I also needed to release the ADOX first, since having that connection in place caused the table creation to fail, even after attempting to open the database.

2. The SQL bit that created the table was producing the success message when something went wrong, but had it worked, would instead have insisted that the database creation procedure had in fact failed. Oops!

3. The otehr error was a result of the connection to the database being open, but the table not being available. I assume this is the case though, but I am not sure. It did happen to me once, with a connection to ADODB open, but no database opened with it (it hadn't been created, so couldn't really be opened).

Everything should now work.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #22 on Thu 09 Oct 2003 09:12 AM (UTC)

Amended on Thu 09 Oct 2003 09:24 AM (UTC) by Xyborg

Message
Thanks a bunch. I'll check it out and I'll edit this post with my results. Though I really gotta stop letting you all do everything for me lol. Not learning too much, but I am learning a little bit. I'll be all leet like you as I slowly learn all this.

[EDIT]
Getting a few errors. I had to make a couple changes to an area where you misplaced a couple quotes, but other than that, the script loaded fine. I didn't getting any errors until I tried using some commands.

"ip:add Aburame 65.139.45.45" Displayed:
[b]Aburame
65.139.45.45
Object Required[/b]

"ip:list" Displayed:
[b]Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.[/b]

"ip:list Aburame" Displayed:
Error number: -2146828275
Event: Execution of line 136 column 5
Description: Type mismatch: 'wildcards'
Called by: Function/Sub: List called by alias
Reason: processing alias ""

and the other commands just gave me the "Object required" thing.

Other than those, I think it's working fine. But what do I know -_-

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #23 on Thu 09 Oct 2003 08:56 PM (UTC)
Message
Hmm. I don't have a clue why this is happening. A good bet is that the original database has been corrupted by the prior mistakes and no connection object ever gets created. I ran the script 'as posted' and tried ip:add, ip:remove, ip:list and ip:clear, all of them worked on my computer. I didn't try ip:list <name> however.

Try adding the line:

note typename(DBHandle)

to each of the command subs. You will need to comment these lines out later when you don't need them anymore, but the result *should* be 'Connection'. If it says anything else, especially 'Empty', then something is definitely going wrong in StartDB and you may have to delete the existing IPList.mdb file and try loading the plugin again so it can create a working version.

As for the quotes you 'fixed', there shouldn't have been any that are wrong. Since you haven't posted what you changed I can't comment on how or if you messed something up changing them. :p

I just did a comparison, the only thing I changed/added to the version posted here was a comment I added. This has no effect on the code itself. Odds are your IPList.mdb got corrupted or something similar and that is what is preventing it from working. If that isn't it, then I have no idea why it won't run on your machine.

Hmm.. This is wrong though in list:

  if Wilds(1) = "" then
    sQuery = "SELECT * FROM IPData ORDER BY ip_address"
  else
    sQuery = "SELECT * FROM IPData WHERE " & _
         "player_name like ""%" & wildcards (1) & "%"" " & _
         "OR ip_address like ""%" & wildcards (1) & "%"" " & _
         "ORDER BY ip_address"
  end if

it needs to be:

  if Wilds(1) = "" then
    sQuery = "SELECT * FROM IPData ORDER BY ip_address"
  else
    sQuery = "SELECT * FROM IPData WHERE " & _
         "player_name like ""%" & Wilds (1) & "%"" " & _
         "OR ip_address like ""%" & Wilds (1) & "%"" " & _
         "ORDER BY ip_address"
  end if

And these lines in Add:

  note player_name
  note ip_address

where for testing. They should really be commented out like:

  'note player_name
  'note ip_address

However, these are the 'only' errors I can find. Everything else works exactly as intended for me. Including ip:list <name>, once the above mistake is fixed.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #24 on Thu 09 Oct 2003 09:08 PM (UTC)

Amended on Thu 09 Oct 2003 09:11 PM (UTC) by Shadowfyr

Message
Hmm. Better yet, instead of adding the 'note typename(DBHandle)' lines, instead change the end of the 'StartDB' sub to this:



  if typename(DBHandle) <> "Connection" then
    world.ColourNote "white", "red", "Unable to connect to table."
    StartDB = -1
    exit function
  end if

  StartDB = 0 'Return with a code indicating everything was a success (hopefully).
end function


In other words, just add those additional lines. This won't fix the problem with the database that I suspect you are having, but it will display an error if the problem is in fact what I suspect. If it does display it, then odds are very good that your current IPList.mdb is bad and you needed to delete it, then try loading the plugin again to create a new one that works.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #25 on Fri 10 Oct 2003 12:35 AM (UTC)
Message
Deleting the IPList.mdb and then restarting the plugin worked perfectly. Didn't think about doing that. Thanks for everything. As for the problem with the quotes, it was in the clearlist alias. Other than that, it's working perfectly.

*bows respectfully*

Thank you again for your help.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #26 on Fri 10 Oct 2003 12:45 AM (UTC)

Amended on Fri 10 Oct 2003 12:54 AM (UTC) by Xyborg

Message
Found a small problem. I get an error when I use ip:list (name) for some reason. I think it's because of the way the list is organized. Like, it's listed buy IP and the players under that IP.

[EDIT]
I'm an idiot. You posted the solution. Just ignore this post -_-

[EDIT2]
Although I can add the exact same IP to the database. Dunno if there is a way to stop that or not. So that I don't have duplicate entries.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #27 on Fri 10 Oct 2003 01:04 AM (UTC)
Message
I intentionally allowed this. That is so that if you have say 4 people with the same IP, then doing 'ip:list 123.123.123.123' would list them like this:

123.123.123.123:
  Fred
  Grub
  Sam
  Ginger

It makes it easier to spot multiple attempts to use the same IP to log in, but with different names. Some people may have legitimate reasons for this, like multple computers on a network, but someone that gets banned may be dumb enough to simply try a new name from the same ISP. I assumed this was what you would need. You could instead go back and create the database over again making the ip_address as UNIQUE, don't remember the exact syntax for that though.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #28 on Sat 11 Oct 2003 07:48 PM (UTC)
Message
Yeah. That layout is great. Just I have things like:

123.123.123.123
Xyborg
Xyborg
Xyborg

That's the only thing I dislike about the script. Other than that, it's awsome. It does the job, with a little clutter, but still does the job.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


85,225 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.