Writing to SQLite inside loop
#1

hi guys got a wee bit of an issue. I'm not fantastically familliar with SQLite in pawn and This kinda works but not really...

pawn Код:
new Query[256];
    for(new varID=1;varID<=2001;varID++) {
        format(Query,sizeof(Query), "INSERT INTO `VEHICLES` (`LINEIDENT`,`VALID`, `INFO`) VALUES('%d', '0','invalid')", varID);
        db_query(Database, Query);
    }
basically on inspection the GM hangs up at 56 ID's written to the database then it just stops dead.

What I don't need is a diatribe on why i should use MySQL etc and anyone that does that gets negative rep...

The only thing i would like any advice on is why it's hanging - I'm going to assume it's due to me doing this inside a loop. Anyone with superior knowledge on the issue of SQLite please feel free to make suggestions or comments.

before anyone asks I've gone through multiple tutorials and I think my query string is formatted correctly - I've also looked through a number of tutorials on SQLite and can't really see an issue.

Any helpful comments are much appreciated, Thanks Guys!
Reply
#2

An issue, what i see at the first sight is, that you - most likely - forgot to free the result. I mean like this:

pawn Код:
new Query[256];

for(new varID=1;varID<=2001;varID++)
{
    format(Query,sizeof(Query), "INSERT INTO `VEHICLES` (`LINEIDENT`,`VALID`, `INFO`) VALUES('%d', '0','invalid')", varID);
    db_free_result(db_query(Database, Query));
}
I'm not sure, that causes the problem, but i hope, it'll help a bit.


Kind regards,
T101
Reply
#3

why you dont use Slice Bud include ??
Reply
#4

call me old fashioned, but if I haven't written it - I don't typically like to use it. I'll admit I'm tempted though lol.

to be honest the only reason i'm not using something like that is that I'm going for the most streamlined I can get using SQLite in its rawest form. Easier for me to learn that way. Also I don't like to rely on 3rd party code that may become unsupported at some point but I guess the easy way to do it would be to simply integrate code into my gm and edit it to suit my purposes.

Thanks for the suggestions guys. I'll give the free result a try and report back!
Reply
#5

Yeah...It takes forever, I closed it before it was finished because it was taking way to long. I got 1528 inserted though. Not sure why you would insert that many though. Are you just making all the vehicle ids available so you can use UPDATE?
Reply
#6

yeah I'm basically writing the base data to the database - it's actually part of the new tsys system I'm writing and i need to have blanks available due to vehicle id's changing all over the place. I think what I'll do is I'll simply distribute the base db file with the system and have it setup beforehand.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)