Deprecated: Use of "parent" in callables is deprecated in /var/www/html/forum/src/vendor/league/flysystem-eventable-filesystem/src/EventableFilesystem.php on line 431
  • If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

DB Bug?

GowLi

Member
Hello,
i write a function to use select on my DB:

Code:
function dbQueryStatement(statement) {
            if (dbc != null) {
                var res = dbc.query(statement);
                if (res[0] != null) {
                    if ((Object.values(res[0]).toString()) != "") {
                        var result = "";
                        ((Object.values(res[0])).toString().replace("/\[\]/", "").split(",")).forEach(function(element) {
                            result += String.fromCharCode(element);
                        });
                        return result;
                    }
                }
            }
        return null;
    }

The Object.values dosent really work it sends: [[....]] so there is [ and ] to much to parse the elements. Also u get the ascii codes and not the String. Is it possible to fix this?

Sorry for my bad English...
 

GowLi

Member
I know how to change to String "....result += String.fromCharCode(element);..."...
The Problem is that i dont can use the information like this row[0].

The Code works but it is a workaround... i ask to fix this problem.
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
you are also using dbc.query wrong it seems like you need a callback at the end like so

Code:
dbc.query(statement, (err, rows) => {

})
 

GowLi

Member
I also get the same result: engine.log(rows[0]); -> {"count(*)":[48]}
how can i grap the 48?

Thanks :)
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
i suppose that you got either some weird query or some other stupid result

the "48" is actually in ascii a zero, but numeric values should get retrieved as a real number without an array, so I suppose you get an ascii string with the number "0" in it as a string
how does your execute statement look like? are you sure that you get 48 entries? or are you expecting 0 entries?
 

GowLi

Member
I know how to convert the ascii...
I expect the 48(Zero) but i want to get the result like this rows[0][0].

How can i do this with the default query?
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
how many rows as result do you expect now? 0 or 48? because either your query statement is a bit fucked up or you just get because of some weird reason ascii back
the result you get seems to be ascii, so convert it to ascii and then use parseInt to convert it into a number
 

GowLi

Member
I'll explain it again. This time in detail, it's not the problem I'm converting the ASCII 48 to 0. My problem is it "engine.log(rows[0]);" returns the following from "{"count(*)":[48]}" and now I just want to select the 48. Normally you can do this with rows[0][0] etc. because I want to keep the statement general I cannot use rows[0]['count(*)']. I just want to have the first column of the result.

Thanks in advance!
 

Multivitamin

Well-Known Member
Tier III
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
if you really need the 48 (and you are 100% sure what you do there because it can have some unexpected results when having a row count with 2 decimals) then just select them like

rows[0]['count(*)'][0]
 

GowLi

Member
Yes but i dont can say count(*) because in other sql statements i can use 'ingameName' etc... so i need it without the count(*)
And this dosnt work (for me)
 

flyth

is reticulating splines
Staff member
Developer
Contributor
Maybe rename the field inside your query then, like select count(*) as counter - then you can use rows[0]['counter'][0].
I'm not sure if I got the actual problem, though.
 

GowLi

Member
That would be a solution, but I would still like to have a possibility like rows[0][0][0]. Also not only me has the Problem with the ASCII result, i think a normal String in default is the better solution.

Sinusbot:
SinusBot 1.0.0-beta.5-b262b6a (TS 3.3.2)

Linux Debian 9
MariaDB (MySQL)

Thanks in advance!
 

flyth

is reticulating splines
Staff member
Developer
Contributor
I would still like to have a possibility like rows[0][0][0]
Yeah, right now that's not an option and I would have to change the interface to do an indexed representation like that as well. I'm not sure if I'll be adding that as most people using JS and coming from PHP are more familiar with the other method.

i think a normal String in default is the better solution
If changing to strings, it wouldn't be binary safe like it is in other languages. But maybe I'll add another mode to disable binary compatibility in general... I'll think about it.
 
Top