Jump to content
john123

Running a DB query from a script

Recommended Posts

I was wondering if anyone is able to explain how to execute a query on the DB from a script. 

 

From looking around the files i  think i've got a basic understanding but i'm still confused.

 

private _query = format ["DELETE FROM bounty WHERE bountyID ='%1'",_uid]; - I understand this is the query we are running. so in table bounty delete the entry where the bounty ID .... is. I Dont quite understand whats with %1 and _uid at the end.

[_query,2] call DB_fnc_asyncCall; - i understand this sends query command to script that deals with the execution.

 

Lets say for instance i wanted to remove someones want from the database once they die how would i go about this?

private _query = format ["DELETE FROM wanted WHERE wantedName ='????????'",???????];

[_query,2] call DB_fnc_asyncCall;

 

 

 

Share this post


Link to post
Share on other sites

Only 1% sure about this but I think you can only do database shit in life_server but maybe if you have a look through the link it should be able to help you with what your doing if you have some sort of knowledge. 

 

Share this post


Link to post
Share on other sites
On 8/4/2018 at 5:43 PM, john123 said:

I was wondering if anyone is able to explain how to execute a query on the DB from a script. 

 

From looking around the files i  think i've got a basic understanding but i'm still confused.

 

private _query = format ["DELETE FROM bounty WHERE bountyID ='%1'",_uid]; - I understand this is the query we are running. so in table bounty delete the entry where the bounty ID .... is. I Dont quite understand whats with %1 and _uid at the end.

[_query,2] call DB_fnc_asyncCall; - i understand this sends query command to script that deals with the execution.

 

Lets say for instance i wanted to remove someones want from the database once they die how would i go about this?

private _query = format ["DELETE FROM wanted WHERE wantedName ='????????'",???????];

[_query,2] call DB_fnc_asyncCall;

 

 

 

So %1 is kinda used as a placeholder if that makes sense then the _uid is what is going to be put in the %1 spot. So for example,

 

private _uid = getPlayerUID player; //let's say that it's 1010101010
_query = format ["DELETE FROM bounty WHERE bountyID ='%1'",_uid];

 

So now that we have defined _uid as the players uid (the 1010101010). The %1 will now equal 1010101010.

So you also can use format for hints and stuff like that.

_name = profileName;
_uid = getPlayerUID player;
Hint format ["Your name is %1 and your uid is %2",_name,_uid];

 

That will print out something like

"Your name is Toxic and your uid is 1010101010"

When I get back on my pc later I'll fix up this reply and add code blocks and stuff. But lmk if this helped or if you need me to clarify anything.

You can do a full read up on formatting here: https://community.bistudio.com/wiki/format

Edited by ToxicRageTv

Share this post


Link to post
Share on other sites
3 hours ago, ToxicRageTv said:

So %1 is kinda used as a placeholder if that makes sense then the _uid is what is going to be put in the %1 spot. So for example,

 

private _uid = getPlayerUID player; //let's say that it's 1010101010
_query = format ["DELETE FROM bounty WHERE bountyID ='%1'",_uid];

 

So now that we have defined _uid as the players uid (the 1010101010). The %1 will now equal 1010101010.

So you also can use format for hints and stuff like that.

_name = profileName;
_uid = getPlayerUID player;
Hint format ["Your name is %1 and your uid is %2",_name,_uid];

 

That will print out something like

"Your name is Toxic and your uid is 1010101010"

When I get back on my pc later I'll fix up this reply and add code blocks and stuff. But lmk if this helped or if you need me to clarify anything.

You can do a full read up on formatting here: https://community.bistudio.com/wiki/format

that has deffo cleaned up part of my question. I just can't understand why when im running the script nothing appears to happen.

 

maybe you could write an example for lets say finding a person by the UID in table Person and deleting their entry.

 

[_query,2] call DB_fnc_asyncCall;

Also i understand this bascially sends the Query to a script that executes it on the database but whats the number 2 for.

Share this post


Link to post
Share on other sites

the 2 is just a mode. It doesn't really seem to do much in the asyncCall cuz if its set to 1, then it just exits. So just leave that as 2.

 

Also i'm not 100% sure how that script works but basically what you can do is this

private _query = format ["DELETE FROM players WHERE pid='%1'",_uid];
private _queryResult = [_query,2] call DB_fnc_asyncCall;

^ that would show you how to delete a player from the database with the given uid. You would have to modify this for the bounty hunter script 

Share this post


Link to post
Share on other sites
12 hours ago, ToxicRageTv said:

the 2 is just a mode. It doesn't really seem to do much in the asyncCall cuz if its set to 1, then it just exits. So just leave that as 2.

 

Also i'm not 100% sure how that script works but basically what you can do is this

private _query = format ["DELETE FROM players WHERE pid='%1'",_uid];
private _queryResult = [_query,2] call DB_fnc_asyncCall;

^ that would show you how to delete a player from the database with the given uid. You would have to modify this for the bounty hunter script 

Great thanks ill give it a go

Share this post


Link to post
Share on other sites

So i've been trying this code and nothing seems to happen any idea's?

 

hint"Test";

_uid = getPlayerUID player;

_query = format["SELECT name FROM players WHERE pid='%1'",_uid];
_queryResult = [_query,2] call DB_fnc_asyncCall;

hint _queryResult;

Edited by john123

Share this post


Link to post
Share on other sites
hint _queryResult;

You forgot the ""

->  hint "_queryResult";

But your hint IG gonna to say you [_query,2] call DB_fnc_asyncCall;

But it's something to see if your script work, but you can write another things like "Script Executed" or wathever.

 

(Sry for my english ^^)

Share this post


Link to post
Share on other sites
2 hours ago, Liliannismo33 said:
hint _queryResult;

You forgot the ""

->  hint "_queryResult";

But your hint IG gonna to say you [_query,2] call DB_fnc_asyncCall;

But it's something to see if your script work, but you can write another things like "Script Executed" or wathever.

 

(Sry for my english ^^)

That's completely wrong. 

 

@john123 format the hint as well.

hint format ["%1",_queryResult"];

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×