Author Topic: Help add mysql inquiry  (Read 1322 times)

Artyom91

  • Advanced Member
  • ****
  • Posts: 257
  • Karma: +2/-43
    • View Profile
Help add mysql inquiry
« on: December 18, 2015, 02:28:19 pm »
Hello.

https://github.com/OHSystem/OHSystem/blob/master/ghost/src/ghostdbmysql.cpp#L828

Code: [Select]
uint32_t MySQLRegAdd( void *conn, string *error, uint32_t botid, string user, string server, string mail, string password, string type )
{
    uint32_t RowID = 0;
    transform( user.begin( ), user.end( ), user.begin( ), ::tolower );
    transform( mail.begin( ), mail.end( ), mail.begin( ), ::tolower );
    string EscServer = MySQLEscapeString( conn, server );
    string EscName = MySQLEscapeString( conn, user );
    string EscMail = MySQLEscapeString( conn, mail );
    string EscPassword = MySQLEscapeString( conn, password );
    string QueryCheck = "SELECT `bnet_username`, `user_ppwd`, `email` from dle_users where name = '" + EscName + "' or bnet_username = '" + EscName + "' or email = '" + EscMail + "'";
    bool isUser = false;
    string Pass = "";
    string Mail = "";

    if( mysql_real_query( (MYSQL *)conn, QueryCheck.c_str( ), QueryCheck.size( ) ) != 0 )
    {
        *error = mysql_error( (MYSQL *)conn );
        return 0;
    }
    else
    {
        //RowID = mysql_insert_id( (MYSQL *)conn );
        MYSQL_RES *Result = mysql_store_result( (MYSQL *)conn );
        if (Result)
        {
            vector<string> Row = MySQLFetchRow( Result );
            if (Row.size( ) == 3)
            {
                isUser = true;
                Pass = Row[1];
                Mail = Row[2];
            }
            mysql_free_result( Result );
        }
        else
            *error = mysql_error( (MYSQL *)conn );
    }

    if( type == "r" && !isUser )
    {
        string Query = "INSERT INTO dle_users ( name, bnet_username, email, user_realm, admin_realm, password, user_bnet, user_joined ) VALUES ( '" + EscName + "', '" + EscName + "', '" + EscMail + "', '" + EscServer + "', '" + EscServer + "', '" + EscPassword + "', '1', UNIX_TIMESTAMP() )";

        if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 )
            *error = mysql_error( (MYSQL *)conn );

        return 1;
    }
    else if( type == "r" && isUser )
        return 5;
    else if( type == "c" && isUser )
    {
        if( Pass != EscPassword )
            return 3;
        else if( Mail != EscMail )
            return 4;
        else
        {
            string Query = "UPDATE `dle_users` SET `user_bnet` = '2', `admin_realm` = '" + EscServer + "', `bnet_username` = '" + EscName + "' WHERE `email` = '" + EscMail + "';";
            if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 )
                *error = mysql_error( (MYSQL *)conn );
            else
                return 2;
        }
    }
    else if( type == "c" && !isUser )
        return 6;

    return 0;
}

Here I need to add another query:

Code: [Select]
        {
            string Query = "UPDATE `dle_users` SET `user_bnet` = '2', `admin_realm` = '" + EscServer + "', `bnet_username` = '" + EscName + "' WHERE `email` = '" + EscMail + "';";
            if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 )
                *error = mysql_error( (MYSQL *)conn );
            else
                return 2;
        }

It does not work:

Code: [Select]
        {
            string Query = "UPDATE `dle_users` SET `user_bnet` = '2', `admin_realm` = '" + EscServer + "', `bnet_username` = '" + EscName + "' WHERE `email` = '" + EscMail + "';";
            string Query = "SELECT `123` ;";
            if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 )
                *error = mysql_error( (MYSQL *)conn );
            else
                return 2;
        }
« Last Edit: December 18, 2015, 02:29:51 pm by Artyom91 »

uakf.b

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
  • Karma: +85/-12
    • View Profile
Re: Help add mysql inquiry
« Reply #1 on: December 21, 2015, 10:10:58 am »
Did you add CONSOLE_Print statements to before the query is executed and in the else body to check the execution path?

Artyom91

  • Advanced Member
  • ****
  • Posts: 257
  • Karma: +2/-43
    • View Profile
Re: Help add mysql inquiry
« Reply #2 on: December 21, 2015, 09:53:58 pm »
Sorry, I do not understand. Please tell me how to add the request after:

Code: [Select]
string Query = "UPDATE `dle_users` SET `user_bnet` = '2', `admin_realm` = '" + EscServer + "', `bnet_username` = '" + EscName + "' WHERE `email` = '" + EscMail + "';";

Artyom91

  • Advanced Member
  • ****
  • Posts: 257
  • Karma: +2/-43
    • View Profile
Re: Help add mysql inquiry
« Reply #3 on: December 26, 2015, 08:31:45 pm »
Did.

Code: [Select]
        {
        string Query = "INSERT INTO `oh_users` (`user_id`, `user_name`, `user_password`, `user_ppwd`, `user_email`, `user_level` ) SELECT `user_id`, `name`, `password`, `user_ppwd`, `email`, `user_group` FROM `dle_users` WHERE  `email` = '" + EscMail + "';";
        if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 )
            *error = mysql_error( (MYSQL *)conn );

        string Query2 = "UPDATE `oh_users` SET `user_bnet` = '2', `admin_realm` = '" + EscServer + "', `bnet_username` = '" + EscName + "' WHERE `user_email` = '" + EscMail + "';";
        if( mysql_real_query( (MYSQL *)conn, Query2.c_str( ), Query2.size( ) ) != 0 )
            *error = mysql_error( (MYSQL *)conn );
        else
            return 2;
        }

Now the bot listens only to the users table are tied nickname.