The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

asp mssql

This (usually) works using Jscript+classic asp, but sometimes it doesn't, so I'm wondering what's wrong with this?
I know it's something, but since it usually works, I'm not sure..

 connect=0;
 connectnum=0;

function execQuery(str)                                                   
{
if(connect==0)
{
    connect=Server.CreateObject('ADODB.Connection');
    connect.Open(application('db_connection'));

connectnum++;
try
{                                                       
eval("var t"+connectnum+"=Server.CreateObject('ADODB.Recordset');try{t"+connectnum+".Open(\""+str+"\", connect);} catch(er){}");                                                 
return eval("t"+connectnum);
}
catch(er){return false;}                                                    }   

var q=execQuery("select * from db_table");
mikael bergkvist Send private email
Sunday, March 19, 2006
 
 
How come you're using the eval?

Don't quote me here, but other languages I've used implement eval() as a seperate call to the interpreter and thus errors within the eval()'d code are not in the same scope as your error handler.

I'm going to look at it all again, but I'm just curious why you chose to eval() instead of just building the strings you need.
Shane Harter Send private email
Sunday, March 19, 2006
 
 
I used to use this to execute sql strings and return the resulting recordset, and since I might do that a lot in a page, I escalated the 'connectnum' each time..thus the eval()..
 var t1,
 var t2,
 var t3,
 etc..
That way, I could call this function over and over, and mix the results from several queries in one go.

I know, I should have done it OOP, and this is really sucky code, but I was young at the time - and now I just got real curious why it worked most of the time, but not all of the time?
mikael bergkvist Send private email
Monday, March 20, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz