MySQL string to variable
#25

Thus far, ive tried 2 things to load the string.

pawn Код:
new fetch[24 + 2];
cache_get_field_content( 0, "username", fetch, g_Handle, sizeof fetch );

cache_get_row(0 , 1, fetch, g_Handle );
strcat( VehicleInfo[vehicleID][vOwner], fetch ); // VehicleInfo[vehicleID][Owner] is empty by default, so no need for strdel in this case
Both of them didnt load the strings.
Things that i know what couldnt be the case:
the field 'username' in the database is a VARCHAR, with the size of 24.
the field 'username' is in the database at place 1; vehicleid, username, modelid, etc
the variable 'vOwner' in the enum has the size MAX_PLAYER_NAME, which is 24.

When the gamemode starts, im calling the function 'VehicleLoadAll()', which is:
pawn Код:
stock VehicleLoadAll()
{
    for( new i = 1; i < MAX_PERS_VEHICLES; i ++ )
    {
        VehicleLoad( i );
    }
}
VehicleLoad():
pawn Код:
stock VehicleLoad( vehicleID )
{
    new query[128];
    format( query, sizeof query, "SELECT * FROM vehicles WHERE carid = %i", vehicleID );
    mysql_function_query( g_Handle, query, true, "OnVehicleLoad", "i", vehicleID );
    return 1;
}
OnVehicleLoad:
pawn Код:
forward OnVehicleLoad( vehicleID );
public OnVehicleLoad( vehicleID )
{
    new row, num;
    cache_get_data( row, num, g_Handle );
    if( row )
    {
        new fetch[24 + 2];
        cache_get_field_content( 0, "username", fetch, g_Handle, sizeof fetch );
        VehicleInfo[vehicleID][vModel]              = cache_get_row_int( 0, 2, g_Handle );
        VehicleInfo[vehicleID][vLoc][0]             = cache_get_row_float( 0, 3, g_Handle );
        VehicleInfo[vehicleID][vLoc][1]             = cache_get_row_float( 0, 4, g_Handle );
        VehicleInfo[vehicleID][vLoc][2]             = cache_get_row_float( 0, 5, g_Handle );
        VehicleInfo[vehicleID][vLoc][3]             = cache_get_row_float( 0, 6, g_Handle );
        VehicleInfo[vehicleID][vColor1]             = cache_get_row_int( 0, 7, g_Handle );
        VehicleInfo[vehicleID][vColor2]             = cache_get_row_int( 0, 8, g_Handle );
       
        strcat( VehicleInfo[vehicleID][vOwner], fetch );
       
        VehicleInfo[vehicleID][vLocked]             = cache_get_row_int( 0, 9, g_Handle );
        VehicleInfo[vehicleID][vID] = CreatePersVehicle( VehicleInfo[vehicleID][vModel],
                                                         VehicleInfo[vehicleID][vLoc][0], VehicleInfo[vehicleID][vLoc][1], VehicleInfo[vehicleID][vLoc][2], VehicleInfo[vehicleID][vLoc][3],
                                                         VehicleInfo[vehicleID][vColor1], VehicleInfo[vehicleID][vColor2], VehicleInfo[vehicleID][vOwner], VehicleInfo[vehicleID][vLocked], false );

        printf( "Vehicle from %s has been loaded. (ID: %i)", VehicleInfo[vehicleID][vOwner], vehicleID );
    }
    return 1;
}
And this query to create the table:
pawn Код:
strcat( query, "CREATE TABLE IF NOT EXISTS vehicles( carid INT( 11 ) AUTO_INCREMENT, username VARCHAR( 24 ), modelid INT( 11 ), " );
    strcat( query, "xpos FLOAT, ypos FLOAT, zpos FLOAT, apos FLOAT, color1 INT( 11 ), color2 INT( 11 ), locked TINYINT( 1 ), " );
    strcat( query, "compslot0 INT( 4 ), compslot1 INT( 4 ), compslot2 INT( 4 ), compslot3 INT( 4 ), compslot4 INT( 4 ), compslot5 INT( 4 ), " );
    strcat( query, "compslot6 INT( 4 ), compslot7 INT( 4 ), compslot8 INT( 4 ), compslot9 INT( 4 ), compslot10 INT( 4 ), " );
    strcat( query, "compslot11 INT( 4 ), PRIMARY KEY( carid ) )" );
    mysql_function_query( g_Handle, query, false, "SendQuery", "" );
The variable size of 'query' is large enough, since the table gets created without any errors.
Reply


Messages In This Thread
MySQL string to variable - by Wesley221 - 29.04.2013, 18:17
Re: MySQL string to variable - by MP2 - 30.04.2013, 08:33
Re: MySQL string to variable - by AndreT - 30.04.2013, 08:51
Re: MySQL string to variable - by MP2 - 30.04.2013, 08:53
Re: MySQL string to variable - by AndreT - 30.04.2013, 10:19
Re: MySQL string to variable - by MP2 - 30.04.2013, 10:42
Re: MySQL string to variable - by AndreT - 30.04.2013, 12:30
Re: MySQL string to variable - by MP2 - 30.04.2013, 12:37
Re: MySQL string to variable - by Wesley221 - 30.04.2013, 13:48
Re: MySQL string to variable - by Wesley221 - 02.05.2013, 15:24
Re: MySQL string to variable - by Calabresi - 02.05.2013, 18:07
Re: MySQL string to variable - by Wesley221 - 02.05.2013, 18:13
Re: MySQL string to variable - by Calabresi - 02.05.2013, 18:19
Re: MySQL string to variable - by Wesley221 - 02.05.2013, 18:24
Re: MySQL string to variable - by Calabresi - 02.05.2013, 18:28
Re: MySQL string to variable - by Wesley221 - 02.05.2013, 18:35
Re: MySQL string to variable - by Calabresi - 02.05.2013, 18:48
Re: MySQL string to variable - by Wesley221 - 02.05.2013, 19:37
Re: MySQL string to variable - by Wesley221 - 03.05.2013, 17:43
Re: MySQL string to variable - by Scenario - 03.05.2013, 17:51
Re: MySQL string to variable - by Wesley221 - 03.05.2013, 19:32
Re: MySQL string to variable - by InfiniTy. - 03.05.2013, 19:41
Re: MySQL string to variable - by Wesley221 - 03.05.2013, 20:32
Re: MySQL string to variable - by InfiniTy. - 03.05.2013, 20:51
Re: MySQL string to variable - by Wesley221 - 04.05.2013, 13:54
Re: MySQL string to variable - by InfiniTy. - 04.05.2013, 14:39
Re: MySQL string to variable - by Wesley221 - 04.05.2013, 15:13
Re: MySQL string to variable - by Wesley221 - 05.05.2013, 14:16

Forum Jump:


Users browsing this thread: 1 Guest(s)