Author Topic: [NWNX ODBC] multiple resultset  (Read 468 times)

Legacy_Epitaffio

  • Jr. Member
  • **
  • Posts: 70
  • Karma: +0/-0
[NWNX ODBC] multiple resultset
« on: December 13, 2011, 05:32:13 pm »


               This is a repost from the nwnx forum, maybe here can it have more visibility ':wub:'


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:


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.
               
               

               


                     Modifié par Epitaffio, 14 décembre 2011 - 12:00 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
[NWNX ODBC] multiple resultset
« Reply #1 on: December 13, 2011, 06:25:40 pm »


               Why so many empty lines? Takes space and makes readers have to piece your text together. (which is annoying)

I might be just tired, but I honestly sat here 5 minutes trying to understand what exactly is the problem that you want a solution to, or what it is that you are even trying to do. Also, I don't know what you mean by "join".. You mean combine the loops or something?
               
               

               


                     Modifié par Xardex, 13 décembre 2011 - 06:26 .
                     
                  


            

Legacy_Epitaffio

  • Jr. Member
  • **
  • Posts: 70
  • Karma: +0/-0
[NWNX ODBC] multiple resultset
« Reply #2 on: December 14, 2011, 12:09:35 pm »


               Fixed the first post..

By join i mean the sql command :look:

What i am trying to do is quite simple, with the nwnx odbc plugin i am executing a query with a loop through the resultset.

When in this loop i execute another query, the first resultset is overwritten and the loop is stopped.

The problem can easily fixed with a join command for the two query, but in case i can't do a join command i am stuck (i copy a part of the second post from the nwnx forum to explain this)


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();
        }

}


I hope now it's more clear ^^"
               
               

               


                     Modifié par Epitaffio, 14 décembre 2011 - 12:34 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
[NWNX ODBC] multiple resultset
« Reply #3 on: December 14, 2011, 02:09:59 pm »


               Im still a little confused... I assume with 'resultet' you mean SQLFetch?

...Couldn't you just define them their own variables and place them so they don't get mixed?
int iResultOuter = SQLFetch(); // For the outer loop
int iResultInner = SQLFetch(); // For the inner loop

Someone who actually knows this plugin should pitch in already..
               
               

               


                     Modifié par Xardex, 14 décembre 2011 - 02:14 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
[NWNX ODBC] multiple resultset
« Reply #4 on: December 14, 2011, 08:02:15 pm »


               If I correctly understand what you're trying to do, this will probably do it:

SQLExecDirect("SELECT table1.column1, table2.column1 FROM table1, table2");
while(SQLFetch())
{
     string s1 = SQLGetData(1);
     string s2 = SQLGetData(2);
     
     // perform any comparison/operation on the strings here
}

Of course you should replace table1 and 2 by your current table names, same thing for the column names.

EDIT: If it's not what you need plz give more details on what you're trying to do, you might not necessarily need to make those loops you posted with the correct query.


Kato
               
               

               


                     Modifié par Kato_Yang, 14 décembre 2011 - 08:30 .