Most SQLite Weird Problem
#1

Check this filterscript out:
pawn Код:
#include <a_samp>

new DB:MyDB;

//==============================================================================
public OnFilterScriptInit()
{
    MyDB = db_open("MyPhone.db");
    db_free_result(db_query(MyDB, "CREATE TABLE IF NOT EXISTS `Users` (`Name`,`Number`)"));

    return 1;
}

public OnFilterScriptExit()
{
    db_close(MyDB);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/number", true))
    {
        new query[256], DBResult:Result;

        new pName[24];
        GetPlayerName(playerid, pName, sizeof(pName));
        format(query, sizeof(query), "SELECT * FROM `Users` WHERE `Name` = '%s'", pName);
        Result = db_query(MyDB, query);

        if(!db_num_rows(Result))
        {
            new MyNumber[10];

            MyNumber[0] = '0';
            MyNumber[1] = '7';
            MyNumber[2] = (1 + random(8)) + '0';
            for(new i = 3; i < 10; i++)
            MyNumber[i] = random(10) + '0';

            format(query, sizeof(query), "INSERT INTO `Users` (`Name`,`Number`) VALUES('%s','%s')", pName, MyNumber);
            db_free_result(db_query(MyDB, query));

/*
            format(query, sizeof(query), "INSERT INTO `Users` (`Name`) VALUES('%s')", pName);
            db_free_result(db_query(MyDB, query));

            SendClientMessage(playerid, -1, query);

            format(query, sizeof(query), "INSERT INTO `Users` (`Number`) VALUES('%s')", MyNumber);
            db_free_result(db_query(MyDB, query));

            SendClientMessage(playerid, -1, query);
*/


            format(query, 128, "Name: %s | Phone number: %s", pName, MyNumber);
            SendClientMessage(playerid, -1, query);
        }
        return 1;
    }
    return 0;
}
And now check this results out:




Why the number contains the name too !?
Reply
#2

You've changed your code from what was shown in that screenshot. Try again now and take a new screenshot, you've commented out the main part of the code shown in your screenshot that executes.
Reply
#3

Quote:
Originally Posted by __
Посмотреть сообщение
You've changed your code from what was shown in that screenshot. Try again now and take a new screenshot, you've commented out the main part of the code shown in your screenshot that executes.
Ok, thanks for answer.

The code:
pawn Код:
#include <a_samp>

new DB:MyDB;

//==============================================================================
public OnFilterScriptInit()
{
    MyDB = db_open("iPhone.db");
    db_free_result(db_query(MyDB, "CREATE TABLE IF NOT EXISTS `Users` (`Name`,`Number`)"));

    return 1;
}

public OnFilterScriptExit()
{
    db_close(MyDB);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/number", true))
    {
        new query[256], DBResult:Result;

        new pName[24];
        GetPlayerName(playerid, pName, sizeof(pName));
        format(query, sizeof(query), "SELECT * FROM `Users` WHERE `Name` = '%s'", pName);
        Result = db_query(MyDB, query);

        if(!db_num_rows(Result))
        {
            new MyNumber[10];

            MyNumber[0] = '0';
            MyNumber[1] = '7';
            MyNumber[2] = (1 + random(8)) + '0';
            for(new i = 3; i < 10; i++)
            MyNumber[i] = random(10) + '0';

            format(query, sizeof(query), "INSERT INTO Users (Name, Number) VALUES('%s', '%s')", pName, MyNumber);
            db_free_result(db_query(MyDB, query));

            SendClientMessage(playerid, -1, query);

            format(query, 128, "Name: %s | Phone number: %s", pName, MyNumber);
            SendClientMessage(playerid, -1, query);
        }
        return 1;
    }
    return 0;
}
The photo: http://imageshack.us/photo/my-images/600/samp034p.png/
Reply
#4

Shouldn't MyNumber be an integer ?... hence its naming.
Reply
#5

Yea, but a int variable never can start with 0.
Reply
#6

I can't see the problem. Perhaps you might have more luck with this code:

pawn Код:
new MyNumber = 10000000 + random(90000000);

            format(query, sizeof(query), "INSERT INTO Users (Name, Number) VALUES('%s', '07%d')", pName, MyNumber);
            db_free_result(db_query(MyDB, query));
Reply
#7

But can you test my code ? To see if you got the same problem, please ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)