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 ➜ Jscript ➜ Can I access SQL database in MUSHclient with Jscript?

Can I access SQL database in MUSHclient with Jscript?

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


Posted by Lbc   (4 posts)  Bio
Date Sat 04 Aug 2001 12:14 PM (UTC)

Amended on Sat 04 Aug 2001 12:18 PM (UTC) by Lbc

Message
if can, how to? thanks.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 05 Aug 2001 04:07 AM (UTC)
Message
Another interesting challenge. :)

I had wondered this myself, and your question prompted me to find the answer. I got the following code to work - whether it works for you depends on whether you have the same things installed, but let's hope. In any case it is a guide to the technique.

I tested this in the immediate window, but in practice you would put it inside a suitable function.

My example assumes:


  • Database is set up as an ODBC database (I used MySQL on Windows NT) - with the DSN set up as a system dsn called "database_dsn"
  • My user id is "myname" and the password is "swordfish"
  • I am doing a select on table "mytable"
  • I am extracting "fieldname" (ie. a field in the table) and using world.note to display it on the screen



// make our COM object
var rsl = new ActiveXObject("ADODB.Recordset.2.5");

// the select statement we want to execute
var source = "SELECT * from mytable LIMIT 10";

// the connect string
var connect =  "DSN=database_dsn;" +
               "User Id=myname;" +
               "Password=swordfish;"

// open the database, do the select
rsl.Open (source, connect, 0);

// loop until end of file (EOF)
while (!rsl.EOF )
  {
  world.note (rsl ("fieldname"));
  rsl.MoveNext ();
  }

// close database
rsl.Close;

// release the COM object
rsl = "";


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lbc   (4 posts)  Bio
Date Reply #2 on Sun 05 Aug 2001 08:59 AM (UTC)
Message
Thanks a lot

i have almost done it myself before u replied my post:P

it took me a whole day to find article in Microsoft's web

site:(

here's my code, i made a bad mistake, after i saw ur post,

i solved it, this code is a bit different with urs:)

//////////////////////////////////////////////
function test1()
{

var xxx=new ActiveXObject("ADODB.Connection");

var rs = new ActiveXObject("ADODB.RecordSet");

xxx.Open("DSN=test1");

rs=xxx.Execute("select * from list1")

//while (!rs.EOF)
//world.note(rs.exits); THIS IS MY BAD CODE,BECAUSE I DIDNT KNOW THE RIGHT WAY TO USE "ADODB.RecordSet"

while (!rs.EOF)
world.note(rs("exits"));//this is right after i saw ur post:)

rs.close();
rs = nothing;
}

BTW:could u please give out a handbook of ADO?or tell me where can i get it, i cant find it in M$'s homepage, thanks again:)
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 05 Aug 2001 09:04 PM (UTC)
Message
Your method is probably better, because you separate out getting the connection from getting the recordset, thus you can get multiple recordsets in one script.

You could also use "ADODB.Command" to send commands to SQL - eg. "create table", "update table", and so on.

As for finding more details, I went to Microsoft's site, clicked on "Search", typed in "ado" and checked only "Developer resources" and "Support & the knowledge base" and found quite a good example as the first search result (in VB, but you can get the drift from it).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lbc   (4 posts)  Bio
Date Reply #4 on Mon 06 Aug 2001 03:15 AM (UTC)
Message
thank u very much

i found a microsoft ado programmer book, it's very nice.

eh, another question: how can i pay shareware fee in cash,

if i have not a credit card?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 06 Aug 2001 03:23 AM (UTC)
Message

Yes, you can pay with cash by using our Secure Online Server


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Wuliao   (14 posts)  Bio
Date Reply #6 on Wed 29 Aug 2001 03:46 PM (UTC)
Message
I used the same method to access the MS Access database. The only problem is that I can not make it support international language. Every non-English characters I retrieved back is ?.

Any idea how can I solve the problem?

Thanks
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 29 Aug 2001 10:05 PM (UTC)
Message
I don't know. A quick scan of the knowledge base has revealed hundreds of articles that match on "Access" and "unicode", and I don't have time to read them all.

Try looking/asking around on some of the developer forums (eg. CodeProject, CodeGuru), as your question is not really specific to MUSHclient.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


31,410 views.

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.