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

Table field naming convention issues #1474

Closed
hantsy opened this issue Mar 6, 2020 · 7 comments
Closed

Table field naming convention issues #1474

hantsy opened this issue Mar 6, 2020 · 7 comments
Assignees
Labels
bug Something isn't working DB client Helidon DB Client

Comments

@hantsy
Copy link

hantsy commented Mar 6, 2020

  • Helidon Version:2.0.m1
  • Helidon SE
  • JDK version: AdaptOpenJDK 11
  • OS: Windows 10
  • Docker version (if applicable):

I used PostgreSQL in Docker for tests.

When I defined the createdAt as TIMESTAMP like this.

createdAt TIMESTAMP NOT NULL DEFAULT LOCALTIMESTAMP ,

Then I tried to fetch this field via DbRow, I found the field name is createdat, not createdAt. I am not sure this is the design purpose or an issue.

(I have changed my codes to use created_at as the field name finally to avoid this issue)

@m0mus m0mus added DB client Helidon DB Client bug Something isn't working labels Mar 6, 2020
@Tomas-Kraus
Copy link
Member

This can be affected by too many things, not just Helidon. I don't have access to your DB so please verify few things first.

ResultSet rs = statement.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
String name = metaData.getColumnLabel(i); // where i is index of your column

If metaData.getColumnLabel(i) returns case-sensitive names and Helidon does not, it's bug in Helidon.

@hantsy
Copy link
Author

hantsy commented Mar 7, 2020

This problem should be caused by PostgreSQL itself. I know camel-case naming maybe not a good option for RDBMS.

@m0mus
Copy link
Contributor

m0mus commented Mar 7, 2020

@hantsy It's worth investigating it. @Tomas-Kraus can you simulate it based on the sample code here https://blog.xojo.com/2016/09/28/about-postgresql-case-sensitivity/ and make sure that DB Client doesn't have problems with case sensitivity.

@hantsy
Copy link
Author

hantsy commented Mar 7, 2020

I confirmed this is a PostgreSQL issue(maybe convention in PostgreSQL).

I defined a table like this.

CREATE TABLE IF NOT EXISTS Person(
ID UUID DEFAULT uuid_generate_v4() ,
FullName VARCHAR(255) NOT NULL,
Email VARCHAR(255) NOT NULL,
createdAt TIMESTAMP NOT NULL DEFAULT LOCALTIMESTAMP ,
PRIMARY KEY (ID)
);

And create a jdbc sample to connect the database and println the metadata of table Persone.

public class JdbcMetadataSample {
    private final String url = "jdbc:postgresql://localhost/test";
    private final String user = "user";
    private final String password = "password";

    public void printPersonTableMetadata() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
            System.out.println("Connected to the PostgreSQL server successfully.");

            var statement = conn.prepareStatement("select FullName, EMAIL, createdAt from PERSON");
            ResultSet rs = statement.executeQuery();
            ResultSetMetaData metaData = rs.getMetaData();

            for (int i = 1; i <= metaData.getColumnCount(); i++) {
                String label = metaData.getColumnLabel(i);
                String name = metaData.getColumnName(i);
                System.out.println("label:" + label);
                System.out.println("name:" + name);
            }

        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
    }

    public static void main(String[] args) {
        JdbcMetadataSample app = new JdbcMetadataSample();
        app.printPersonTableMetadata();
    }
}

It prints the following results.

Connected to the PostgreSQL server successfully.
label:fullname
name:fullname
label:email
name:email
label:createdat
name:createdat

The column name and table name in the SQL are case-insensitive, and in the JDBC metadata, all become lowercase.

@ljnelson
Copy link
Member

ljnelson commented Mar 7, 2020

That's right; DatabaseMetaData can help you here.

@Tomas-Kraus
Copy link
Member

@hantsy It's worth investigating it. @Tomas-Kraus can you simulate it based on the sample code here https://blog.xojo.com/2016/09/28/about-postgresql-case-sensitivity/ and make sure that DB Client doesn't have problems with case sensitivity.

Integration tests are running with MySQL. But maybe it's time to add few more databases.

@Tomas-Kraus
Copy link
Member

Closing this. Created #1518 to setup PgSQL integration tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working DB client Helidon DB Client
Projects
Archived in project
Development

No branches or pull requests

4 participants