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

Driver cuts out the question mark from columns labels (aliases) #2535

Open
DmitriyGod opened this issue Nov 9, 2024 · 3 comments
Open

Driver cuts out the question mark from columns labels (aliases) #2535

DmitriyGod opened this issue Nov 9, 2024 · 3 comments
Labels
Backlog The topic in question has been recognized and added to development backlog

Comments

@DmitriyGod
Copy link

Driver version

latest

SQL Server version

mcr.microsoft.com/mssql/server:2022-latest

Client Operating System

any

JAVA/JVM version

any

Table schema

no

Problem description

Driver cuts out the question mark from columns labels (aliases):

var stmt = connection.prepareStatement(
    """
        select 1 as "any questions ???"
        """);

var metaData = stmt.getMetaData();
var actual = metaData.getColumnLabel(1);
var expected = "any questions ???";

Assertions.assertEquals(expected, actual);

out:
Expected :any questions ???
Actual :any questions nullnullnull

Expected behavior

Driver must keep question marks

Actual behavior

Driver cuts out the question mark from columns labels (aliases).

Error message/stack trace

Any other details that can be helpful

All other drivers keeps question mark in labels.

JDBC trace logs

@machavan
Copy link

Adding a stmt.executeQuery post prapreStatement makes it bring the column labels correctly.

try (Connection connection = DriverManager.getConnection(url)) {
	try(var stmt = connection.prepareStatement(
		    """
	        select 1 as "any questions ???"
	        """);) {
		

                stmt.executeQuery();
		
                var metaData = stmt.getMetaData();
		var actual = metaData.getColumnName(1);
		var expected = "any questions ???";
		Assertions.assertEquals(expected, actual);				
	}			
}

@DmitriyGod
Copy link
Author

We are developing a security tool that checks query on compile-time via PreparedStatement. We are cannot execute query. Also this is common task — to know query Metadata without execution

@machavan
Copy link

Sure. Is changing the alias to a name (which does not contain question marks) an option at your end, as a work-around?

@github-project-automation github-project-automation bot moved this to To be triaged in MSSQL JDBC Nov 12, 2024
@machavan machavan added the Backlog The topic in question has been recognized and added to development backlog label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog The topic in question has been recognized and added to development backlog
Projects
Status: Backlog
Development

No branches or pull requests

2 participants