intercept / intercept-database

A database library for Intercept
MIT License
14 stars 9 forks source link

dbResultToParsedArray removes some rows #16

Closed th3-sh0w3r closed 5 years ago

th3-sh0w3r commented 5 years ago

Hey,

(replace # with `, can't do that because of github code insert)

my connection works fine now. But there is another problem. I have some arrays in my DB like: "[#license_civ_air#, 0]" and the gear array "[#U_C_Poloshirt_blue#,##,##,##,##,[#ItemMap#,#ItemCompass#,#Itemwatch#],##,##,##,[],[],[],[],[],[],[##,##,##,##],[##,##,##,##],[##,##,##,##],[],[],[],[]]".

This is my result if I use dbResultToArray

__________ DB-INFO ___________
Mode: sync
Values: [""76561198114764155""]
ConfigName: queryRequestCIV
Is multi: [false,false]
Is connected: true
Ping: true
Affected rows: 1
Last insert ID: 0
Result array:

"Row: ""[[#license_civ_driver#,1],[#license_civ_boat#,0],[#license_civ_pilot#,0],[#license_civ_pilotp#,0],[#license_civ_trucking#,0],[#license_civ_gun#,0],[#license_civ_dive#,0],[#license_civ_rebel#,0],[#license_civ_hunt#,0],[#license_civ_illegalprocess#,0],[#license_civ_home#,1],[#license_civ_copper_pro#,0],[#license_civ_iron_pro#,0],[#license_civ_alu_pro#,0],[#license_civ_siliz_pro#,0],[#license_civ_silber_pro#,0],[#license_civ_zin_pro#,0],[#license_civ_glass_pro#,0],[#license_civ_kohl_pro#,0],[#license_civ_holz_pro#,0],[#license_civ_stein_pro#,0],[#license_civ_rubin_pro#,0],[#license_civ_schwefel_pro#,0],[#license_civ_bus#,0],[#license_civ_post#,0],[#license_civ_taxi#,0],[#license_civ_dir#,0],[#license_civ_airp#,0],[#license_civ_bauf#,0],[#license_civ_panne#,0],[#license_civ_ambu#,0],[#license_civ_train#,0],[#license_civ_gwsc#,0],[#license_civ_gwsk#,0],[#license_civ_gwsg#,0],[#license_civ_gwss#,0],[#license_civ_gwsm#,0],[#license_civ_gwsb#,0],[#license_civ_gwsf#,0],[#license_civ_gws#,0]]"""
"Row: 0"
"Row: ""[#U_C_Poloshirt_blue#,##,##,##,##,[#ItemMap#,#ItemCompass#,#Itemwatch#],##,##,##,[],[],[],[],[],[],[##,##,##,##],[##,##,##,##],[##,##,##,##],[],[],[],[]]"""
"Row: ""[70,80,100,0]"""
"Row: 0"
"Row: ""[5802.58,10197.9,0.0997663]"""

and this is my result if I use dbResultToParsedArray:

__________ DB-INFO ___________
Mode: sync
Values: [""76561198114764155""]
ConfigName: queryRequestCIV
Is multi: [false,true]
Is connected: true
Ping: true
Affected rows: 1
Last insert ID: 0
Result array: 

"Row: 0"
"Row: ""[70,80,100,0]"""
"Row: 0"
"Row: ""[5802.58,10197.9,0.0997663]"""

Instead of turning the array from "[#license_civ_air#, 0]" to [#license_civ_air#, 0] it just removes it.

What can I do there?

EDIT: The other arrays like ""[70,80,100,0]"" doesn't turn into [70,80,100,0] too.

dedmen commented 5 years ago

It parses ' and " quotes, like Arma does too. ` is not a valid quote

th3-sh0w3r commented 5 years ago

But I have another array, and there are these characters around numbers and that works. Maybe it only works on numbers. I think I will use some other characters now. Thanks.

Edit: Can you tell me why it doesn‘t turn „[30,30]“ into [30,30]?

dedmen commented 5 years ago

and are not valid quotes. Only " and '

th3-sh0w3r commented 5 years ago

Yes I mean these 2 but i‘m on the phone and can‘t write that characters. But the command doesn‘t remove them.

@dedmen Now I'm at the PC and I mean "[30,30]" into [30,30]

dedmen commented 5 years ago

Wait... What are you actually storing in the database? Are you storing the string [30,30] like SELECT "[30,30]" or are you storing "[30,30]" like SELECT "\"[30,30]\"" ?

The parsing code is here: https://github.com/intercept/intercept-database/blob/master/src/res.cpp#L92 I don't take care of any quotes, everything is done by parseSimpleArray command. If it doesn't work with parseSimpleArray then I don't think I can help you much. Can you maybe attach a SQL dump file so I can see what data you actually have? Maybe just a small excerpt of your db.

th3-sh0w3r commented 5 years ago

Wait... What are you actually storing in the database? Are you storing the string [30,30] like SELECT "[30,30]" or are you storing "[30,30]" like SELECT "\"[30,30]\"" ?

The parsing code is here: https://github.com/intercept/intercept-database/blob/master/src/res.cpp#L92 I don't take care of any quotes, everything is done by parseSimpleArray command. If it doesn't work with parseSimpleArray then I don't think I can help you much. Can you maybe attach a SQL dump file so I can see what data you actually have? Maybe just a small excerpt of your db.

I'm storing "[30,30]" not "\"[30,30]\"" This is my table:

DROP TABLE IF EXISTSplayers`;

CREATE TABLE players ( uid int(12) NOT NULL AUTO_INCREMENT, name varchar(32) NOT NULL, aliases text NOT NULL, playerid varchar(50) NOT NULL, cash varchar(400) NOT NULL DEFAULT '"[0,0,0,0]"', bankacc varchar(400) NOT NULL DEFAULT '"[0,0,0,0]"', coplevel enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20') NOT NULL DEFAULT '0', mediclevel enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20') NOT NULL DEFAULT '0', opforlevel enum('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20') NOT NULL DEFAULT '0', civ_licenses text NOT NULL, cop_licenses text NOT NULL, med_licenses text NOT NULL, opfor_licenses text NOT NULL, civ_gear text NOT NULL, cop_gear text NOT NULL, med_gear text NOT NULL, opfor_gear text NOT NULL, civ_stats varchar(400) NOT NULL DEFAULT '"[100,100,100,0]"', cop_stats varchar(400) NOT NULL DEFAULT '"[100,100,100,0]"', med_stats varchar(400) NOT NULL DEFAULT '"[100,100,100,0]"', opfor_stats varchar(400) NOT NULL DEFAULT '"[100,100,100,0]"', arrested int(12) NOT NULL, adminlevel enum('0','1','2','3','4','5') NOT NULL DEFAULT '0', civ_alive tinyint(1) NOT NULL DEFAULT '0', civ_position varchar(64) NOT NULL DEFAULT '"[]"', skill_level varchar(400) NOT NULL DEFAULT '"[0,0]"', pin int(4) NOT NULL DEFAULT '0', blueprints text NOT NULL, insert_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_seen timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (uid), UNIQUE KEY playerid (playerid), KEY name (name) ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1; `

The command only selects type of varchar. The other arrays in text, longtext are not shown/selected. But it doesn't remove the quotes from the array. It is just like the normal dbResultToArray but only with removing of text, longtext etc.

And another question, this is my config.yalm

insertRequestInsert: > INSERT INTO players (playerid, name, cash, bankacc, aliases, arrested, skill_level, cop_licenses, med_licenses, civ_licenses, opfor_licenses, civ_gear, cop_gear, med_gear, opfor_gear, blueprints) VALUES(?, ?, ?, ?, ?, ?, ?, '"[]"', '"[]"', '"[]"', '"[]"', '"[]"', '"[]"', '"[]"', '"[]"', '"[]"')

Do I need to put the ' apostrophs around it?

dedmen commented 5 years ago

I'm storing "[30,30]" not "\"[30,30]\""

No.. You're not.

'"[100,100,100,0]"' '"[]"' '"[0,0]"'

You are storing "[0,0]" instead of what you're supposed to [0,0] Your strings are not supposed to have embedded quotes. That's your problem.

th3-sh0w3r commented 5 years ago

I'm storing "[30,30]" not ""[30,30]""

No.. You're not.

'"[100,100,100,0]"' '"[]"' '"[0,0]"'

You are storing "[0,0]" instead of what you're supposed to [0,0] Your strings are not supposed to have embedded quotes. That's your problem.

Ohh wow... I thought mysql isn't working if I don't use the apostrophs. I will test it. Thank you. That means in my config.yaml I must only use the ? and then I can go and insert a array like this "[30,30]"

Because I tried that yesterday but it didn't work for me. Even that removed the array from the select. Or do I need to insert the array without quotes and it will select it with quotes?

th3-sh0w3r commented 5 years ago

@dedmen Maybe it removes the rows because in the file https://github.com/intercept/intercept-database/blob/bf27d7adf4c673d75d6d3b30454c88c36d974472/src/res.cpp#L61 you added blob support from this issue: https://github.com/intercept/intercept-database/issues/11 but not blob support for the parsedArray command: https://github.com/intercept/intercept-database/blob/bf27d7adf4c673d75d6d3b30454c88c36d974472/src/res.cpp#L85

th3-sh0w3r commented 5 years ago

Hey, @dedmen

i've added blob support to the parsed array command and now it works :) Thank you very much for your help. Maybe you can update/add this in the future.

This is what I changed: https://github.com/nflug/intercept-database/commit/2f5ead0f2a6e8fd5f356f8c1edaee69407446a80

dedmen commented 5 years ago

you added blob support from this issue: #11 but not blob support for the parsedArray command

AH! I only tested that with varchar, not text.

That means in my config.yaml I must only use the ? and then I can go and insert a array like this "[30,30]"

Yes, but make sure that your string is actually "[30,30]" and not """[30,30]"""

dedmen commented 5 years ago

deae4aee9a0959e9177c2fea2d45eb11919b94cc