SA-MP Forums Archive
SQLite wildcard search - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQLite wildcard search (/showthread.php?tid=440303)



SQLite wildcard search (SOLVED) - Pottus - 29.05.2013

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?


Re: SQLite wildcard search - Vince - 29.05.2013

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.


Re: SQLite wildcard search - Pottus - 29.05.2013

%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));