SQLite issue
#1

hey guys - beenplaying around with sqlite a bit and Had some pretty god luck until i hit a query that is rather large ad have to split the string and join using strcat():

pawn Код:
format(QueryA, sizeof(QueryA), "INSERT INTO `VEHICLES` (`ID`, `VALID`, `MODEL`, `XPOS`, `YPOS`, `ZPOS`, `ZAPOS`, `COL1`, `COL2`, `COST`, `BOUGHT`, `SECURE`, `ASECURE`, `BUYBAR`, `MOD1`, `MOD2`,` MOD3`, `MOD4`, `MOD5`, `MOD6`, `MOD7`, `MOD8`, `MOD9`, `MOD10`, `MOD11`, `MOD12`, `MOD13`, `MOD14`, `MOD15`, `MOD16`, `MOD17`, `OWNER`, `NAME`, `PAINTJOB`, `FACTION`)");
                format(QueryB, sizeof(QueryB), " VALUES('%d', '1', '%d', '%f', '%f', '%f', '%f', '%d', '%d', '%d', ",varID, VehicleSetupInfo[varID][model], VehicleSetupInfo[varID][x_spawn], VehicleSetupInfo[varID][y_spawn], VehicleSetupInfo[varID][z_spawn], VehicleSetupInfo[varID][za_spawn], VehicleSetupInfo[varID][color_1], VehicleSetupInfo[varID][color_2], VehicleSetupInfo[varID][vehiclecost]);
                strcat(QueryA, QueryB);
                format(QueryB, sizeof(QueryB), "'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '[NULL]', '%s', '-1', '-1' )", DB_Escape(VehicleSetupInfo[varID][name]));
                strcat(QueryA, QueryB);
                db_query(TSYS_Database, QueryA);

Is that the right way to do it or am I being dumb because it don't work lol. Is there a better way to do it than this and would somebody be kind enough to show me it? Thanks in advance guys
Reply
#2

lol aa i think you need to set the QueryA string to 1000
Reply
#3

nah - just gives the header readout on compile then stops the GM load-up dead but does not crash. everything just stops processing at the point of use of the above code :S
Reply
#4

You sure? I think your strings are too short.
Reply
#5

I do it this way. I find it faster.

pawn Код:
format(query, sizeof(query), "UPDATE `blah` SET `money` = %d, `field1` = 'hi'");
format(query, sizeof(query), "%s, `field2` = 'hey', `field3` = 'fk u'", query);
Reply
#6

Yea that's how I got mine setup as well.
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
format is a lot slower than strcat.
wow, really? I thought it was faster because all it does is set a string's value (and format the placeholders), although strcat consists of something along the lines of:

pawn Код:
strcat(dest[], const source[], maxlength=sizeof dest)
{
    strins(dest, source, strlen(dest), maxlength);
}
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
They aren't even close! Read this:

https://sampforum.blast.hk/showthread.php?tid=57018
Why then there is format if strcat is faster?
Reply
#9

Have you checked out SQLitei (https://sampforum.blast.hk/showthread.php?tid=303682)?

The first example (in that thread) pretty much shows you how to do this with prepared statements.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)