How do you load lots of cars from mysql?
#1

For those who use g-stylzzz's plugin only....


my way:
Код:
stock LoadVehsr()
{
	new query[32];
    format(query,256,"SELECT * FROM vehs");
    mysql_query(query);
    mysql_store_result();
	while(mysql_retrieve_row())
        {
            new field[13][128];
            if(mysql_num_rows() == 0) continue;
            mysql_fetch_row_format(query, "|");
            explode(query, field, "|");
            new mdl,vidid,Float:x,Float:y,Float:z,Float:r;
            mdl=strval(field[0]);
            x=strval(field[1]);
            y=strval(field[2]);
            z=strval(field[3]);
            r=strval(field[5]);
            vidid=CreateVehicle(mdl,x,y,z+0.5,r,0,1,-1);
  		}
	mysql_free_result();
	return 1;
}
Please post your code too.
Reply
#2

Sscanf.
Reply
#3

Wrong section.

Refer to scripting discussion.
Reply
#4

sscanf instead of explode for splitting the values, but I also limit what I select, so I'm not selecting arbitrary values that I don't need at all.

Also your code is practically illogical:
pawn Код:
new query[32];
format(query,256,"SELECT * FROM vehs");
You have 32 cells but you try and allocate 256 cells to write your query to. You should just use sizeof() in format, as string sizes are constant.
Reply
#5

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
sscanf instead of explode for splitting the values, but I also limit what I select, so I'm not selecting arbitrary values that I don't need at all.

Also your code is practically illogical:
pawn Код:
new query[32];
format(query,256,"SELECT * FROM vehs");
You have 32 cells but you try and allocate 256 cells to write your query to. You should just use sizeof() in format, as string sizes are constant.
i actually edited a lil before posting coz it was actually to load dealer vehicles. btw i posted it in this section coz i wanted to know how people load their shit off mysql :P .. i dont have any problems with my loading. just wondering.. sometimes i use a for loop to load them instead of while. ok anyone else?
Reply
#6

Why would you even format a constant?
Reply
#7

What do you mean? If you mean the strval part then idk. The guy in the tutorial did that so did i. Never knew we dont need to. If there is a better and faster way to load the pkease show me how
Reply
#8

"SELECT * FROM vehs" doesn't require a string, you can use it directly in your query, you're wasting 128 (32*4) bytes of memory.
Reply
#9

Oh ok ill change everything then. Mm what abt the code is it good or is there a better and faster way?
Reply
#10

Quote:
Originally Posted by THE_KNOWN
Посмотреть сообщение
Oh ok ill change everything then. Mm what abt the code is it good or is there a better and faster way?
Quote:
Originally Posted by playbox12
Посмотреть сообщение
Sscanf.
Golly Gee.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)