mIRC Home    About    Download    Register    News    Help

Print Thread
#40620 08/08/03 11:33 PM
Joined: Jul 2003
Posts: 35
R
root Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jul 2003
Posts: 35
Sorry to disturb again, but the last post didnt really work out to what I hoped it would...
Again the problem;
Trying to make mIRC write to microsoft access, (specifically the newest colomn, rows 1,2,3,5,7).
Using mIRC 6.03, windows 98 se, and windows xp (two machines going to be running the script). I no -nothing- of vb and was told COM object was the best way to do it, unfortunately I know as much about COM as I do about VB. So any help, any at all would be most appreciated. If you think it is a big job or you have more then a lot to contribute and dont feel like making a 50000 word post mail me at admin@montrealshells.com or just post it anyhoo .

Thanks

#40621 09/08/03 01:21 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Do you know SQL?

By far, the easiest solution is to comopen an ADODB.Connection object and use its Execute method to apply:
INSERT INTO TableName (Field1, Field2, Field3, Field4) VALUES ('string1', 'string2', 3, 'string4');

Here's an example of how you might go about using this method.
Code:

alias dbWrite {
 
  ;  Alter this SQL statement to use the correct TableName and FieldNames, and of course
  ;  the values you wish to add to the database. This could be made much more dynamic,
  ;  but for the purpose of showing how to get it working, a simpler version suffices.
  ;
  var %SQL = $&[color:#00007F]
    INSERT INTO MyTable (Nick, Channel, CurrentUsers, CTime) $&
    VALUES (' $+ $nick $+ ', ' $+ $chan $+ ', $nick($chan,0) $+ , $ctime $+ );
  [/color]
  ;  Put the exact path (D:\path\to\filename.mdb) to your Access database here.
  ;
  var %DBPath = [color:#840017]$mircdir $+ MyDB.mdb[/color]
  
  ;  This statement is complete, do not touch.
  ;
  var %ConnectionString = Provider=Microsoft.JET.OLEDB.4.0;Data Source= $+ %DBPath
  
  ;  Instantiate a Connection object.
  ;
  .comopen cnMyDB ADODB.Connection
  
  ;  Attempt to connect the Connection object to your database.
  ;
  if ($com(cnMyDB, Open, 5, bstr, %ConnectionString) == 0) {
  
    ;  If we're in here, we didn't connect to the database; issue an error message.
    ;
    echo $color(ctcp) -ati * COM could not open the database.
    
    ;  Close the COM connection
    ;
    .comclose cnMyDB
    
    ;  Halt the script on an error condition.
    ;
    halt
  }
  
  ;  If we're here, the database is open, ready to write to.
  ;
  !.echo -q $com(cnMyDB, Execute, 5, bstr, %SQL)
  
  ;  Close down the Connection object (destroy it).
  ;
  .comclose cnMyDB
  
}

This alias would be called from a channel event (since it uses $nick and $chan). on !*:JOIN:#MySmallChannel: dbWrite .. which is obviously not a particularly good idea, but works for the purposes of demonstration.

You might even store your SQL statements in a hash table and process them all at once by looping through them all while the Connection object is open, a process known as batch processing.

Disclaimer: You must know SQL (or be able to follow the examples above) in order for to safely modify this scriptlet. If you need more control, you could also instantiate an ADODB.RecordSet object and use its hidden Collect method to access the different fields. This is also how you would retrieve individual field values from a SQL SELECT recordset.

EDIT: I noticed I'd forgotten to halt on cnMyDB.Open failure.

Last edited by Hammer; 09/08/03 08:11 AM.

DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#40622 09/08/03 03:01 AM
Joined: Jul 2003
Posts: 35
R
root Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jul 2003
Posts: 35
* Blinks rapidly *
That really does help. Thanks


Link Copied to Clipboard