About Store Forum Documentation Contact



Post Reply 
MySQL / MSSQL - accessing certain rows problem
Author Message
Kiekos Offline
Member

Post: #1
MySQL / MSSQL - accessing certain rows problem
Hey there!

I set up my MSSQL (and later MySQL) database in order to do the tutorial and it worked fine. Then I modified the database so that it contains one table which looks like this:

[Image: FyVANTx.png]

One column ("login") and one row ("testlogin").

The problem is that the whole thing doesn't work as I'd like it to. I have the sample GUI window loaded ("player name.gobj").

I've tried doing this:

Code:
{
   Str TextLine = login.getTextLine("name")();  
   Str rowValue;

   if(sql.existsTable(table_name))
   {
       if(!sql.getAllRows(table_name, &messages))
           Exit(S+"Can't get rows from table:\n"+messages);

       for(;sql.getNextRow();)
       {
          sql.getCol(0, rowValue);

          if (TextLine == rowValue) { SuccessfulLogin = true; }
       }
   }
}

But it turns out that even if I type "testlogin" in the textline and the comparing process starts, it doesn't see that the textline equals the row.

I'm probably doing some coding mistakes but I'm only just starting the database thing so any help would be much appreciated.

Thanks,
Kiekos
(This post was last modified: 05-26-2013 11:45 AM by Kiekos.)
05-25-2013 06:51 PM
Find all posts by this user Quote this message in a reply
Kiekos Offline
Member

Post: #2
RE: MySQL / MSSQL - accessing certain rows problem
Anyone?
05-27-2013 02:35 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #3
RE: MySQL / MSSQL - accessing certain rows problem
Code:
{
   Str TextLine = login.getTextLine("name")();  
   Str rowValue;
   if(sql.getAllRows(table_name)){
           for(;sql.getNextRow();){
                 sql.getCol(0, rowValue);
                 if(TextLine == rowValue) { SuccessfulLogin = true; }
           }
   }
}

If this doesn't work then all that could be wrong is lower and or uppercase. You can use Casedown / up for that.

Sorry, couldn't let you make this mistake, please use this method instead

Code:
if(sql.getRows("tablename",S+"login="+TextLine)){
   sql.getNextRow();
   sql.getCol(2,Password) /*Compare password here etc*/
   SuccessfulLogin = true;
}
(This post was last modified: 05-27-2013 03:14 PM by TBJokers.)
05-27-2013 02:42 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Kiekos Offline
Member

Post: #4
RE: MySQL / MSSQL - accessing certain rows problem
(05-27-2013 02:42 PM)TBJokers Wrote:  Sorry, couldn't let you make this mistake, please use this method instead

Code:
if(sql.getRows("tablename",S+"login="+TextLine)){
   sql.getNextRow();
   sql.getCol(2,Password) /*Compare password here etc*/
   SuccessfulLogin = true;
}

What mistake? Is the method I used incorrect? I haven't created any password column yet. I just wanted to try the basic database set up with 1 column.



After further investigation I found out that the app kept connecting to MSSQL database instead of MySQL database, as your code was working only for MSSQL database. I didn't know why but then I deleted the switch (in the code below) and it magically started working for MySQL.

I think it was trying to connect to both MySQL and MSSQL database and so it was using the second one. After leaving only MySQL connection in the code - everything works fine.

Code:
bool SQL MODE;

void SQLConnection()
{
    SQL_MODE = true;

    // connect to server/database
    switch(SQL_MODE)
    {
    case true:  if(!sql.connectMySQL("localhost"            , "mydatabase", "root", "", &messages))Exit(S+"Can't connect to Server!\nError: "+messages);
    case false: if(!sql.connectMSSQL("LocalHost\\SQLExpress", "test_db"   , ""    , "", &messages))Exit(S+"Can't connect to Server!\nError: "+messages);
    }
}

So yeah, thanks TBJokers ^^
(This post was last modified: 05-27-2013 04:49 PM by Kiekos.)
05-27-2013 03:42 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #5
RE: MySQL / MSSQL - accessing certain rows problem
Code:
if(sql.getRows("tablename",S+"login="+TextLine)){
   sql.getNextRow();
   sql.getCol(2,Password) /*Compare password here etc*/
   SuccessfulLogin = true;
}

Using that will require less from the computer, for a server with a lot of communication you don't want to catch 1000rows and look through, instead use that and only catch if there's a row with the column login= Textline.

considering you have alot more users your previous method would be harsh to use.
(This post was last modified: 05-28-2013 01:33 PM by TBJokers.)
05-28-2013 01:31 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Kiekos Offline
Member

Post: #6
RE: MySQL / MSSQL - accessing certain rows problem
Allright, thanks a lot!
05-28-2013 02:43 PM
Find all posts by this user Quote this message in a reply
Post Reply