Pulling data from SQL table in script

Andy Murtagh

New Member
Hi folks,

I am currently writing a script in which I define several variables locally in the script, and set their values there also. In the case of some the values are ones that I may want to update moderately frequently, hopefully without having to un-pack and re-pack my PBO each time.

Is there a way that I can pull data from a table in the sql and use it to set my variable? For example, if I had:
a defined variable: _variable
a database name: bliss_1234
a table name: variable_value
inside that table, two columns: index (int, key, autoincrement), importantinfo

What I would want to do is make _variable equal to a value of importantinfo from the table bliss_1234.variable_value for a certain index#.

Does anyone know if this is the kind of thing which is possible in a script? Sorry, reasonably new to this whole thing and the forum search and google have failed me on this occasion (mostly I'm sure down to not knowing the right keywords to be searching for!).

Many thanks!
Q.
 
I would guess you could use something like the code here since this is doing just that. But I'm not that great with c++ so i dont see the part where it actually does the "display message on server". I see the rpt logs but not the global msg to server.
 
"[nil, nil, rSPAWN, [_crier, _payload], { (_this select 0) globalChat (_this select 1) }] call RE;" \n

guess that's it???
 
Hi folks,

I am currently writing a script in which I define several variables locally in the script, and set their values there also. In the case of some the values are ones that I may want to update moderately frequently, hopefully without having to un-pack and re-pack my PBO each time.

Is there a way that I can pull data from a table in the sql and use it to set my variable? For example, if I had:
a defined variable: _variable
a database name: bliss_1234
a table name: variable_value
inside that table, two columns: index (int, key, autoincrement), importantinfo

What I would want to do is make _variable equal to a value of importantinfo from the table bliss_1234.variable_value for a certain index#.

Does anyone know if this is the kind of thing which is possible in a script? Sorry, reasonably new to this whole thing and the forum search and google have failed me on this occasion (mostly I'm sure down to not knowing the right keywords to be searching for!).

Many thanks!
Q.

I'm a newb at arma2 programming but isn't _variable actually an object? isn't that what the _ denotes?
 
The "_" denotes locality of the variable, which could be an object, or a string, number, etc.
_localVar - local to this machine, this script
globalVar - local to this machine
"publicVar" - a little different, read up on it. Sent across the network.
 
The "_" denotes locality of the variable, which could be an object, or a string, number, etc.
_localVar - local to this machine, this script
globalVar - local to this machine
"publicVar" - a little different, read up on it. Sent across the network.

thanks, this is helpful information.

holy crap, this arma2 coding is starting to come together. So you can pass code to every client on the server with a public variable.... I just assumed they held data only.
 
thanks, this is helpful information.

holy crap, this arma2 coding is starting to come together. So you can pass code to every client on the server with a public variable.... I just assumed they held data only.
Read the biki, it's helped me a lot.
 
"[nil, nil, rSPAWN, [_crier, _payload], { (_this select 0) globalChat (_this select 1) }] call RE;" \n

guess that's it???


Hi Machine, thanks for your reply!
I'm not sure I see the right piece of that code, or at least not in the context that I'm looking for. I'm guessing the string that queries is:
Code:
_key = format["CHILD:999:select payload, loop_interval, start_delay from message where instance_id = ?:[%1]:", dayZ_instance];
Just not sure I see any obvious context to the syntax... I'm guessing here that payload, loop_interval, start_delay are all table columns in the table and the where instance_id = ? seems obvious enough... But I don't see where it points at which table is used! I'm also completely lost as to the CHILD:999 portion of the query. I'll do some reading up on the format function.

Are there any examples you know of where just a single variable is pulled from a single table column? That might let me narrow down the syntax a bit more for my purposes.

Thanks for the help!
 
Ooh hang on, I missed it...
_key = format["CHILD:999:select payload, loop_interval, start_delay from message where instance_id = ?:[%1]:", dayZ_instance];

So the table name is in there, in red. Still not sure on the exact syntax I'd need though =/
Upon reading, "format" function appears just to create an array of other variables rather than any kind of pull, so I'm guessing the query itself has to be something to do with the "CHILD:999:select" part of the code, bit I can find no reference of it in the script commands list to check on syntax =/

Anybody got any ideas or can provide insight into the specific arguments and their purpose / context?
 
The call you have is definitely what begins mySQL communication - but I'm not sure what part is pulling variables down. Is this code from server_monitor.sqf?


From my server_monitor.sqf - sends the key, gets mysql response _result checks it's status (_status) then creates _myArray which seems to hold the values (it's parsed right after this)
Code:
//Stream in objects
/* STREAM OBJECTS */
//Send the key
_key = format["CHILD:302:%1:",dayZ_instance];
_result = _key call server_hiveReadWrite;
 
diag_log "HIVE: Request sent";
 
//Process result
_status = _result select 0;
 
_myArray = [];
if (_status == "ObjectStreamStart") then {
_val = _result select 1;
//Stream Objects
diag_log ("HIVE: Commence Object Streaming...");
for "_i" from 1 to _val do {
_result = _key call server_hiveReadWrite;
 
_status = _result select 0;
_myArray set [count _myArray,_result];
//diag_log ("HIVE: Loop ");
};
//diag_log ("HIVE: Streamed " + str(_val) + " objects");
};
 
so say you wanted to pull a group of admins who can use a script you could do...

_playerisadmin = format["CHILD:999:select adminID, from admins where instance_id = ?:[%1]:", dayZ_instance];


then _playerisadmin would be your list of admins?
 
so say you wanted to pull a group of admins who can use a script you could do...

_playerisadmin = format["CHILD:999:select adminID, from admins where instance_id = ?:[%1]:", dayZ_instance];


then _playerisadmin would be your list of admins?

I think you need to call the hive with _playerisadmin to execute the query...

here is something interesting. I've been trying to find data on CHILD:999 but all I can find is info on the other child calls from the hive code:
https://github.com/rajkosto/hive/blob/master/Hive/Source/HiveLib/HiveExtApp.cpp
 
so to call it would this work?
Code:
if ((getPlayerUID player) in ["_playerisadmin"]) exitWith

can't be that simple i'm sure.
 
so to call it would this work?
Code:
if ((getPlayerUID player) in ["_playerisadmin"]) exitWith

can't be that simple i'm sure.

no, I think you need to call it like this:
Code:
_playerisadmin = format["CHILD:999:select adminID, from admins where instance_id = ?:[%1]:", dayZ_instance];
_data2 = "HiveEXT" callExtension _playerisadmin;

Then you have to get the data out of that... This is the problem I am having right now.

Here is the code for getting custom inventories for players when they log in (bliss package invcust)

take a look at what they are doing with the key. In this example player_login.sqf it works just fine... but I can't get the damn child:999 to work with my hive.dll
Code:
if (_model == "") then {
_key = format["CHILD:999:select replace(cl.`inventory`, '""', '""""') inventory, replace(cl.`backpack`, '""', '""""') backpack, replace(coalesce(cl.`model`, 'Survivor2_DZ'), '""', '""""') model from `cust_loadout` cl join `cust_loadout_profile` clp on clp.`cust_loadout_id` = cl.`id` where clp.`unique_id` = '?':[%1]:",str(_playerID)];
_data = "HiveEXT" callExtension _key;
//Process result
_result = call compile format ["%1", _data];
_status = _result select 0;
if (_status == "CustomStreamStart") then {
if ((_result select 1) > 0) then {
_data = "HiveEXT" callExtension _key;
_result = call compile format ["%1", _data];
_inventory = call compile (_result select 0);
_backpack = call compile (_result select 1);
_model = call compile (_result select 2);
};
};
};
 
is the child 999 a read / write permission? like 309 is read 999 is write?

If you look at that github link I posted, it describes the different child functions and what they do. All except 999. 999 is in theory supposed to allow you to execute custom queries. I don't know if it is limited to read or write.
 
999 can do read and write. there was a write only, 998, that one is bugged and it was confirmed to me will not be fixed.

The logic how the hive call works i best described in a code snippet:

Code:
    // define query
    _key = format ["CHILD:999: select id from building WHERE class_name= '%1' AND id > ?:[0]:", _classname];    // format the sql call for the hiveext.dll
    _result = _key call server_hiveReadWrite;  // execute the hive call
 
    _status    = _result select 0;            // get the status of the result
 
    if (_status == "CustomStreamStart") then {    //check if the stream coming from the hive was opened
        _val = _result select 1;                  // get the number of entries that will be coming in the stream
        diag_log format["SARGE DEBUG: Value of - _val : %1",_val];
    };

After this check you run this code:

Code:
        _result = _key call server_hiveReadWrite; 
        _tbl_bld_id = _result select 0;            // will contain your actual value
 
999 can do read and write. there was a write only, 998, that one is bugged and it was confirmed to me will not be fixed.

The logic how the hive call works i best described in a code snippet:

Code:
    // define query
    _key = format ["CHILD:999: select id from building WHERE class_name= '%1' AND id > ?:[0]:", _classname];    // format the sql call for the hiveext.dll
    _result = _key call server_hiveReadWrite;  // execute the hive call
 
    _status    = _result select 0;            // get the status of the result
 
    if (_status == "CustomStreamStart") then {    //check if the stream coming from the hive was opened
        _val = _result select 1;                  // get the number of entries that will be coming in the stream
        diag_log format["SARGE DEBUG: Value of - _val : %1",_val];
    };

After this check you run this code:

Code:
        _result = _key call server_hiveReadWrite;
        _tbl_bld_id = _result select 0;            // will contain your actual value

Hey sarge,

Trying to figure out the code here as it is a bit confusing in the query structuring. It looks like you are only passing one variable (_classname) to the query as a parameter but I see two params(?) exoected in the query.

I see "class_name='%1'" and "id > ?:[0]"

Can you please elaborate on what these are? I am guessing that the ? corresponds to the "0" in the brackets and the '%1' corresponds to the variable _classname. If this is the case, why not pass both variables with "%1" or "?"

edit: I see now that the %1 is the position marker for the format method. it looks like the ? is the position marker for the first query parameter [0].

Is child:999 only capable of taking one parameter?
 
actually i think you dont even need the ?/[0]. Thats just the way to substitute in variables in the hive call.

you could also do a direct

_sqlstring ="CHILD:999: select id from building WHERE class_name= 'barrack' AND id > 0";

need to give that a try though.

cheers, Sarge
 
Back
Top