Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql: TRUE/FALSE display as 1/0 #35

Open
jankatins opened this issue Feb 16, 2021 · 2 comments
Open

postgresql: TRUE/FALSE display as 1/0 #35

jankatins opened this issue Feb 16, 2021 · 2 comments
Labels

Comments

@jankatins
Copy link

Using

%LOAD postgresql dbname=postgres host=localhost
Select FALSE as bar;

I get a display of

bar
0

Which looks wrong to my eyes which are used to normal psql output. If this has to be fixed deeper, I can also open a ticket in soci...

@marimeireles
Copy link
Member

marimeireles commented Mar 1, 2021

Hey @jankatins thank you for the issue.
Yeah, if the usual output is TRUE/FALSE then we should aim for that.
The way we're displaying data in our tables is using the following piece of code, that can be found here:

                try {
                    switch(props.get_data_type())
                    {
                        case soci::dt_string:
                            cell = r.get<std::string>(i, "NULL");
                            break;
                        case soci::dt_double:
                            cell = std::to_string(r.get<double>(i));
                            cell.erase(cell.find_last_not_of('0') + 1, std::string::npos);
                            if (cell.back() == '.') {
                                cell.pop_back();
                            }
                            break;
                        case soci::dt_integer:
                            cell = std::to_string(r.get<int>(i));
                            break;
                        case soci::dt_long_long:
                            cell = std::to_string(r.get<long long>(i));
                            break;
                        case soci::dt_unsigned_long_long:
                            cell = std::to_string(r.get<unsigned long long>(i));
                            break;
                        case soci::dt_xml:
                        case soci::dt_blob:
                            break;
                        case soci::dt_date:
                            std::tm when = r.get<std::tm>(i);
                            cell = std::asctime(&when);
                            break;
                    }
                } catch (...) {
                    cell = "NULL";
                }

This was copied from SOCI's docs on how to display data. As you can see... It doesn't have a special case treating bools, I think the problem might be related to that? I don't have the time in the moment, but here's how I'd tackle the problem in case someone else is interested in doing it:

  1. Learn if SOCI has a specific type to treat bools, something like soci::dt_bool
    1.1. If it does, just include this case on the switch statement, get the data with r.get and either attribute TRUE/FALSE to the cell var.
    1.2 If it doesn't maybe it's possible to add an if inside the switch statement that is catching the bool types (maybe it's soci::dt_integer?) read the value inputed by the user with r.get and either attribute TRUE/FALSE to the cell var.

Thanks again!

@marimeireles
Copy link
Member

We could also just overwrite this locally. Easier than proposing upstream.

@marimeireles marimeireles added the good first issue Good for newcomers label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants