logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Odbc multiple resultset

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux technical support
View previous topic :: View next topic  
Author Message
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Tue Dec 13, 2011 16:10    Post subject: Odbc multiple resultset Reply with quote

Hi all, i've searched this along the forum, but with any results..

If i need to do two o more SQLFetch() in a while structure, like this:

Code:

    sSQL = "SELECT * FROM table1 ";
    SQLExecDirect(sSQL);
    while(SQLFetch()==SQL_SUCCESS){

      sSQL = "SELECT * FROM table2 ";
      SQLExecDirect(sSQL);
      while(SQLFetch()==SQL_SUCCESS){

         //Other Code Line
      
      }

    }


and i can't or don't want to do a join, how i can accomplish that?

I've read some pappillon's post where he say that the Hashset plugin is for this, but the plugin is for windows only and i'm using linux : (

Any hint? Thanks in advance.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Dec 13, 2011 23:25    Post subject: Reply with quote

Why can't you use a JOIN?
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Wed Dec 14, 2011 13:58    Post subject: Reply with quote

Too many sql and while structure, not linked table or different function in the same while:

Code:

string test1(){
    string sSQL = "SELECT * from table";
    SQLExecDirect(sSQL);
    while(SQLFetch()==SQL_SUCCESS){
         return SQLGetData(1);
    }
}

string test2(){
    string sSQL = "SELECT * from table";
    SQLExecDirect(sSQL);
    while(SQLFetch()==SQL_SUCCESS){
         return SQLGetData(1);
    }
}


sSQL = "SELECT * FROM table";
SQLExecDirect(sSQL);
while(SQLFetch()==SQL_SUCCESS){

    if(){
        test1();
    }else{
        test2();
    }

}



something like this..
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Wed Dec 14, 2011 15:36    Post subject: Reply with quote

Doing nested queries in a loop is a bad practice: you shold avoid this. If one resultset is not enough for you, you're probably doing something wrong. I've yet to see a task that really requires multiple resultsets and can't be optimized to use only one.
If join must depend on some field, just do two left joins, one of them will be NULL. Having extra fields in the resultset won't cost you too much, while nested queries will.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Wed Dec 14, 2011 16:55    Post subject: Reply with quote

Hum, yes it's what i'm doing at this time, optimizing query, table and code to use only one resultset.. but sometimes the query become too long or/and difficult to manage and it's more simple to do another fetch in another resultset.

So, only for talking, there aren't any ways to do multiple resultset? : (


Ps. the problems for doing multiple fetch are memory related or what?
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Wed Dec 14, 2011 19:15    Post subject: Reply with quote

No, NWNX database plugin currently doesn't support multiple resultsets. It's not a matter of memory, it just wasn't designed for that because there was no need for this.
If you don't want to have all these long SQL queries in the script, create a view and use it as a simple table.
Hundreds of extra queries will affect performance and cause lag.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Wed Dec 14, 2011 20:06    Post subject: Reply with quote

Ok, thanks a lot virusman, kind as everytime!
Back to top
View user's profile Send private message
mariasam



Joined: 24 Sep 2013
Posts: 1

PostPosted: Tue Sep 24, 2013 13:00    Post subject: Reply with quote

Thank you very much! Now it works perfectly Wink Smile
_________________
http://prep4sure.com
Back to top
View user's profile Send private message
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Sat Sep 28, 2013 22:14    Post subject: Reply with quote

Alternatively, use cursors.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux technical support All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group