SQLite wildcard search
#1

Alright, well I'm trying to get some wildcard searching in my DB for looking up banned user names and IP's I've referred to this tutorial here https://sampforum.blast.hk/showthread.php?tid=262417

Specially this line here demonstrates how to do a wildcard search

" delete from `players` where `playerName` = 'Henry%' "

So here is what I have

pawn Код:
format(Query, sizeof(Query), "DELETE FROM `BannedUsers` Where `PlayerName` = '%s%c'", DB_Escape(text), 37);
printf("%s", Query);
Result = db_query(BannedUsers, Query);
Output:

DELETE FROM `BannedUsers` Where `PlayerName` = 'test%'

Plasenote this will work when the wildcard is removed and the whole name is supplied

DELETE FROM `BannedUsers` Where `PlayerName` = 'testname'

I don't seem to be getting any query results when trying to use a wildcard in the search anyone have any ideas here or is this a SAMP limitation with SQLite?
Reply
#2

When using the format function you need to use double percent signs to insert a literal percent sign. Otherwise the parser will interpret the percent sign as a placeholder.
Reply
#3

%c inserts character 37 which is a percent sign, i'll try your way though just in case.

Edit - Still doesn't work so it's something else Vince even if I write the whole name it will fail with the wildcard character so it's either a SAMP limitation or % is not the wildcard character.

Edit - Solution

It would appear that tutorial was wrong, here is the correct query syntax

format(Query, sizeof(Query), "SELECT `PlayerName` FROM `BannedUsers` Where `PlayerName` LIKE '%s%%'", DB_Escape(text));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)