Skip to content

Try a simpler approach for handling Timestamps on SQL Server #6038

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

Open
wants to merge 1 commit into
base: release24.7-SNAPSHOT
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void prepare(DbScope scope)
String mdFormat = switch (_dateFormat)
{
case "mdy" -> "MM-dd";
case "dmy" -> "dd-MM";
case "dmy" -> "MM-dd";
default -> throw new IllegalStateException("Unsupported date format: " + _dateFormat);
};

Expand Down Expand Up @@ -171,108 +171,109 @@ public TimestampStatementWrapper(ConnectionWrapper conn, Statement stmt, String
}

@Override
public void setTimestamp(String parameterName, Timestamp x) throws SQLException
public void setTimestamp(String parameterName, Timestamp ts) throws SQLException
{
if (x != null)
if (ts != null)
{
setObject(parameterName, convert(x));
setObject(parameterName, convert(ts), Types.TIMESTAMP);
}
else
{
super.setTimestamp(parameterName, x);
super.setTimestamp(parameterName, ts);
}
}

@Override
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException
public void setTimestamp(String parameterName, Timestamp ts, Calendar cal) throws SQLException
{
if (x != null)
if (ts != null)
{
setObject(parameterName, convert(x));
setTimestamp(parameterName, ts);
}
else
{
super.setTimestamp(parameterName, x, cal);
super.setTimestamp(parameterName, ts, cal);
}
}

@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
public void setTimestamp(int parameterIndex, Timestamp ts) throws SQLException
{
if (x != null)
if (ts != null)
{
setObject(parameterIndex, convert(x));
setObject(parameterIndex, convert(ts), Types.TIMESTAMP);
}
else
{
super.setTimestamp(parameterIndex, x);
super.setTimestamp(parameterIndex, ts);
}
}

@Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException
public void setTimestamp(int parameterIndex, Timestamp ts, Calendar cal) throws SQLException
{
if (x != null)
if (ts != null)
{
setObject(parameterIndex, convert(x));
setTimestamp(parameterIndex, ts);
}
else
{
super.setTimestamp(parameterIndex, x, cal);
super.setTimestamp(parameterIndex, ts, cal);
}
}

@Override
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
{
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp)
setObject(parameterIndex, x);
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp ts)
setTimestamp(parameterIndex, ts);
else
super.setObject(parameterIndex, x, targetSqlType, scale);
}

@Override
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException
{
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp)
setObject(parameterIndex, x);
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp ts)
setTimestamp(parameterIndex, ts);
else
super.setObject(parameterIndex, x, targetSqlType);
}

@Override
public void setObject(int parameterIndex, Object x) throws SQLException
{
super.setObject(parameterIndex, convert(x));
if (x instanceof Timestamp ts)
setTimestamp(parameterIndex, ts);
else
super.setObject(parameterIndex, x);
}

@Override
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException
{
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp)
setObject(parameterName, x);
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp ts)
setTimestamp(parameterName, ts);
else
super.setObject(parameterName, x, targetSqlType, scale);
}

@Override
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException
{
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp)
setObject(parameterName, x);
if (targetSqlType == Types.TIMESTAMP && x instanceof Timestamp ts)
setTimestamp(parameterName, ts);
else
super.setObject(parameterName, x, targetSqlType);
}

@Override
public void setObject(String parameterName, Object x) throws SQLException
{
super.setObject(parameterName, convert(x));
}

private Object convert(Object x)
{
return x instanceof Timestamp ts ? convert(ts) : x;
if (x instanceof Timestamp ts)
setTimestamp(parameterName, ts);
else
super.setObject(parameterName, x);
}

private String convert(Timestamp ts)
Expand Down