add argNull, fix column size metadata setup

This commit is contained in:
Jörg Prante 2022-06-24 17:19:03 +02:00
parent 9c1a331d6b
commit 46eed697d4
5 changed files with 43 additions and 42 deletions

View file

@ -10,9 +10,7 @@ import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@ -237,15 +235,14 @@ public class DatabaseImpl implements Database {
int cols = rsmd.getColumnCount(); int cols = rsmd.getColumnCount();
while (rs.next()) { while (rs.next()) {
String name = ""; String name = "";
Integer size = 0; int size = 0;
for (int i = 1; i <= cols; i++) { for (int i = 1; i <= cols; i++) {
String label = rsmd.getColumnName(i); String label = rsmd.getColumnName(i);
Object v = rs.getObject(i); if ("COLUMN_NAME".equalsIgnoreCase(label)) {
if (label.equals("COLUMN_NAME")) { name = rs.getString(i);
name = (String) v;
} }
if (label.equals("COLUMN_SIZE")) { if ("COLUMN_SIZE".equalsIgnoreCase(label)) {
size = (Integer) v; size = rs.getBigDecimal(i).intValue();
} }
} }
map.put(name, size); map.put(name, size);

View file

@ -49,27 +49,29 @@ public interface SqlInsert {
SqlInsert argDateNowPerApp(); SqlInsert argDateNowPerApp();
SqlInsert argDateNowPerApp( String argName); SqlInsert argDateNowPerApp(String argName);
SqlInsert argDateNowPerDb(); SqlInsert argDateNowPerDb();
SqlInsert argDateNowPerDb( String argName); SqlInsert argDateNowPerDb(String argName);
SqlInsert argBlobBytes(byte[] arg); SqlInsert argBlobBytes(byte[] arg);
SqlInsert argBlobBytes( String argName, byte[] arg); SqlInsert argBlobBytes(String argName, byte[] arg);
SqlInsert argBlobStream(InputStream arg); SqlInsert argBlobStream(InputStream arg);
SqlInsert argBlobStream( String argName, InputStream arg); SqlInsert argBlobStream(String argName, InputStream arg);
SqlInsert argClobString(String arg); SqlInsert argClobString(String arg);
SqlInsert argClobString( String argName, String arg); SqlInsert argClobString(String argName, String arg);
SqlInsert argClobReader(Reader arg); SqlInsert argClobReader(Reader arg);
SqlInsert argClobReader( String argName, Reader arg); SqlInsert argClobReader(String argName, Reader arg);
SqlInsert argNull(String argName);
SqlInsert withArgs(SqlArgs args); SqlInsert withArgs(SqlArgs args);

View file

@ -1,5 +1,6 @@
package org.xbib.jdbc.query; package org.xbib.jdbc.query;
import java.sql.Types;
import org.xbib.jdbc.query.util.DebugSql; import org.xbib.jdbc.query.util.DebugSql;
import org.xbib.jdbc.query.util.InternalStringReader; import org.xbib.jdbc.query.util.InternalStringReader;
import org.xbib.jdbc.query.util.Metric; import org.xbib.jdbc.query.util.Metric;
@ -158,7 +159,6 @@ public class SqlInsertImpl implements SqlInsert {
public SqlInsert argLocalDate(LocalDate arg) { public SqlInsert argLocalDate(LocalDate arg) {
return positionalArg(adaptor.nullLocalDate(arg)); return positionalArg(adaptor.nullLocalDate(arg));
} }
@Override @Override
public SqlInsert argDateNowPerApp() { public SqlInsert argDateNowPerApp() {
@ -179,7 +179,6 @@ public class SqlInsertImpl implements SqlInsert {
} }
@Override @Override
public SqlInsert argDateNowPerDb( String argName) { public SqlInsert argDateNowPerDb( String argName) {
if (options.useDatePerAppOnly()) { if (options.useDatePerAppOnly()) {
return namedArg(argName, adaptor.nullDate(options.currentDate())); return namedArg(argName, adaptor.nullDate(options.currentDate()));
@ -188,54 +187,50 @@ public class SqlInsertImpl implements SqlInsert {
} }
@Override @Override
public SqlInsert argBlobBytes(byte[] arg) { public SqlInsert argBlobBytes(byte[] arg) {
return positionalArg(adaptor.nullBytes(arg)); return positionalArg(adaptor.nullBytes(arg));
} }
@Override @Override
public SqlInsert argBlobBytes( String argName, byte[] arg) { public SqlInsert argBlobBytes( String argName, byte[] arg) {
return namedArg(argName, adaptor.nullBytes(arg)); return namedArg(argName, adaptor.nullBytes(arg));
} }
@Override @Override
public SqlInsert argBlobStream(InputStream arg) { public SqlInsert argBlobStream(InputStream arg) {
return positionalArg(adaptor.nullInputStream(arg)); return positionalArg(adaptor.nullInputStream(arg));
} }
@Override @Override
public SqlInsert argBlobStream( String argName, InputStream arg) { public SqlInsert argBlobStream( String argName, InputStream arg) {
return namedArg(argName, adaptor.nullInputStream(arg)); return namedArg(argName, adaptor.nullInputStream(arg));
} }
@Override @Override
public SqlInsert argClobString(String arg) { public SqlInsert argClobString(String arg) {
return positionalArg(adaptor.nullClobReader(arg == null ? null : new InternalStringReader(arg))); return positionalArg(adaptor.nullClobReader(arg == null ? null : new InternalStringReader(arg)));
} }
@Override @Override
public SqlInsert argClobString( String argName, String arg) { public SqlInsert argClobString( String argName, String arg) {
return namedArg(argName, adaptor.nullClobReader(arg == null ? null : new InternalStringReader(arg))); return namedArg(argName, adaptor.nullClobReader(arg == null ? null : new InternalStringReader(arg)));
} }
@Override @Override
public SqlInsert argClobReader(Reader arg) { public SqlInsert argClobReader(Reader arg) {
return positionalArg(adaptor.nullClobReader(arg)); return positionalArg(adaptor.nullClobReader(arg));
} }
@Override @Override
public SqlInsert argClobReader( String argName, Reader arg) { public SqlInsert argClobReader( String argName, Reader arg) {
return namedArg(argName, adaptor.nullClobReader(arg)); return namedArg(argName, adaptor.nullClobReader(arg));
} }
@Override
public SqlInsert argNull(String argName) {
return namedArg(argName, new SqlNull(Types.VARCHAR));
}
@Override @Override
public SqlInsert withArgs(SqlArgs args) { public SqlInsert withArgs(SqlArgs args) {
return apply(args); return apply(args);

View file

@ -13,64 +13,66 @@ public interface SqlUpdate {
SqlUpdate argBoolean(Boolean arg); SqlUpdate argBoolean(Boolean arg);
SqlUpdate argBoolean( String argName, Boolean arg); SqlUpdate argBoolean(String argName, Boolean arg);
SqlUpdate argInteger(Integer arg); SqlUpdate argInteger(Integer arg);
SqlUpdate argInteger( String argName, Integer arg); SqlUpdate argInteger(String argName, Integer arg);
SqlUpdate argLong(Long arg); SqlUpdate argLong(Long arg);
SqlUpdate argLong( String argName, Long arg); SqlUpdate argLong(String argName, Long arg);
SqlUpdate argFloat(Float arg); SqlUpdate argFloat(Float arg);
SqlUpdate argFloat( String argName, Float arg); SqlUpdate argFloat(String argName, Float arg);
SqlUpdate argDouble(Double arg); SqlUpdate argDouble(Double arg);
SqlUpdate argDouble( String argName, Double arg); SqlUpdate argDouble(String argName, Double arg);
SqlUpdate argBigDecimal(BigDecimal arg); SqlUpdate argBigDecimal(BigDecimal arg);
SqlUpdate argBigDecimal( String argName, BigDecimal arg); SqlUpdate argBigDecimal(String argName, BigDecimal arg);
SqlUpdate argString(String arg); SqlUpdate argString(String arg);
SqlUpdate argString( String argName, String arg); SqlUpdate argString(String argName, String arg);
SqlUpdate argDate(LocalDateTime arg); SqlUpdate argDate(LocalDateTime arg);
SqlUpdate argDate( String argName, LocalDateTime arg); SqlUpdate argDate(String argName, LocalDateTime arg);
SqlUpdate argLocalDate(LocalDate arg); SqlUpdate argLocalDate(LocalDate arg);
SqlUpdate argLocalDate( String argName, LocalDate arg); SqlUpdate argLocalDate(String argName, LocalDate arg);
SqlUpdate argDateNowPerApp(); SqlUpdate argDateNowPerApp();
SqlUpdate argDateNowPerApp( String argName); SqlUpdate argDateNowPerApp(String argName);
SqlUpdate argDateNowPerDb(); SqlUpdate argDateNowPerDb();
SqlUpdate argDateNowPerDb( String argName); SqlUpdate argDateNowPerDb(String argName);
SqlUpdate argBlobBytes(byte[] arg); SqlUpdate argBlobBytes(byte[] arg);
SqlUpdate argBlobBytes( String argName, byte[] arg); SqlUpdate argBlobBytes(String argName, byte[] arg);
SqlUpdate argBlobStream(InputStream arg); SqlUpdate argBlobStream(InputStream arg);
SqlUpdate argBlobStream( String argName, InputStream arg); SqlUpdate argBlobStream(String argName, InputStream arg);
SqlUpdate argClobString(String arg); SqlUpdate argClobString(String arg);
SqlUpdate argClobString( String argName, String arg); SqlUpdate argClobString(String argName, String arg);
SqlUpdate argClobReader(Reader arg); SqlUpdate argClobReader(Reader arg);
SqlUpdate argClobReader( String argName, Reader arg); SqlUpdate argClobReader(String argName, Reader arg);
SqlUpdate argNull(String argName);
SqlUpdate withArgs(SqlArgs args); SqlUpdate withArgs(SqlArgs args);
SqlUpdate apply(Apply apply); SqlUpdate apply(Apply apply);

View file

@ -1,5 +1,6 @@
package org.xbib.jdbc.query; package org.xbib.jdbc.query;
import java.sql.Types;
import org.xbib.jdbc.query.util.DebugSql; import org.xbib.jdbc.query.util.DebugSql;
import org.xbib.jdbc.query.util.InternalStringReader; import org.xbib.jdbc.query.util.InternalStringReader;
import org.xbib.jdbc.query.util.Metric; import org.xbib.jdbc.query.util.Metric;
@ -229,7 +230,11 @@ public class SqlUpdateImpl implements SqlUpdate {
return namedArg(argName, adaptor.nullClobReader(arg)); return namedArg(argName, adaptor.nullClobReader(arg));
} }
@Override
public SqlUpdate argNull(String argName) {
return namedArg(argName, new SqlNull(Types.VARCHAR));
}
@Override @Override
public SqlUpdate withArgs(SqlArgs args) { public SqlUpdate withArgs(SqlArgs args) {
return apply(args); return apply(args);