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

@ -71,6 +71,8 @@ public interface SqlInsert {
SqlInsert argClobReader(String argName, Reader arg); SqlInsert argClobReader(String argName, Reader arg);
SqlInsert argNull(String argName);
SqlInsert withArgs(SqlArgs args); SqlInsert withArgs(SqlArgs args);
SqlInsert apply(Apply apply); SqlInsert 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;
@ -159,7 +160,6 @@ public class SqlInsertImpl implements SqlInsert {
return positionalArg(adaptor.nullLocalDate(arg)); return positionalArg(adaptor.nullLocalDate(arg));
} }
@Override @Override
public SqlInsert argDateNowPerApp() { public SqlInsert argDateNowPerApp() {
return positionalArg(adaptor.nullDate(options.currentDate())); return positionalArg(adaptor.nullDate(options.currentDate()));
@ -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,53 +187,49 @@ 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) {

View file

@ -71,6 +71,8 @@ public interface SqlUpdate {
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,6 +230,10 @@ 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) {