[HELP REQUEST] Inserting values into SQL

Hello .

I hawe Question …

How can I add values into SQL code from C++ ?

CharacterDatabase.PQuery(“SELECT * FROM characters WHERE guid=A”);

In this example I need replace variabile A with character GUID …

I am see in code that exist format string like %u , %s , %i but I am trying this and not working…

Can anyone help me please ?

Thanks. and sorry for my lite engish.


So in my case :

CharacterDatabase.PQuery(printf (“SELECT * FROM characters WHERE guid=%i”, playerGuid));

It is correct ?

I really don’t know why you imported printf into the query, he sent you an example how to use “%”.

% —> A % followed by another % character will write % to stdout.

Here you have an example:

    QueryResult result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", acc_id); 

And this example is very easy to understand:

   printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);

I hawe Question …How can I add values into SQL code from C++ ?

You will mean, how to select values from database, right?

Thank you for your example lesone . I am C++ Beginer and I need this in my custom command … But I am try some variants and trinity every crash …

Yes I will mean how to execute query on database , where query has VARIABILE as Input

Static query work . but if I am trying add variabile into query , trinity fail every time…