intercept / intercept-database

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

InterceptDB return values always use the same data type as specified in the database #4

Closed Xeno69 closed 5 years ago

Xeno69 commented 5 years ago

With extDB3 you have the option to return values either as string or more like Arma types.

extDB3 example:

[getSettings] SQL1_1 = SELECT name, value FROM settings; OUTPUT =1-string, 2

The settings table has two columns, name and value, both are varchar in the database.

Data can look like this in the table:

name value
points [30,7,15,5,10,5,10,4,2]
db_autosave true
ranked ["Sergeant","Lieutenant","Captain","Major","Sergeant","Corporal"]
mixed [10,[0,1,2],"Somename",6,1,["AAA","BBB"],5]

extDB3 returns the name in getSettings always as string and value in some directly parsable value (with parseSimpleArray).

So db_autosave db result (after parseSimpleArray) will look like this in extDB3:

["db_autosave", true] ["points", [30,7,15,5,10,5,10,4,2]]

while with interceptDB the dbResultToArray looks like this:

["db_autosave", "true"] ["points", "[30,7,15,5,10,5,10,4,2]"]

Would be nice to have a similar feature in interceptDB (and makes using existing extDB3 databases easier and more important compatible)

dedmen commented 5 years ago

I'd just add special handling for when a string starts with [ or a is true/false, or only contains a number. Would that handle all your use cases?

Would be optional and default disabled, I think I'd let the user enable that via config, but don't really want a seperate SQF command just for that. Or maybe dbResultToParsedArray or something like that? seperate command to try to parse strings into array/bool/number ?

Xeno69 commented 5 years ago

Nope, won't handle all cases, simply because SQL data types don't match Arma ones.

Please check how extDB3 saves arrays or any other data type compared to interceptDB. As long as it is not the same it's not usable, sorry to say that.

dedmen commented 5 years ago

Huh? But what I wrote doesn't have anything to do with SQL data types. It will all just be string.

dedmen commented 5 years ago

How does this look? Query: SELECT "[1,2,true,True,false,False,[1,2,3]]" Ingame output:

[//Rows
    [//Row 1
        [1,2,true,true,false,false,[1,2,3]]
    ]
]

Handles true/false, all arrays, and everything that starts with a number.

Select "1" -> [[1]]

Select "myvar" -> [["myvar"]] (fails to parse)

Select "" -> [[""]] cannot sensibly parse that to aynthing else.

Select "[]" -> [[[]]]

Everything that comes from DB tries to be parsed using parseSimpleArray. If that fails it just defaults to pushing a string to the output array.