Fix a DB issue with parsing short, byte, and long values

This commit is contained in:
James Seibel
2023-10-07 15:51:27 -05:00
parent 8f0c820c09
commit 4ddfb8342d
4 changed files with 67 additions and 12 deletions
@@ -38,6 +38,8 @@ public class TestDataRepo extends AbstractDhRepo<TestDto>
"Id INT NOT NULL PRIMARY KEY\n" +
"\n" +
",Value TEXT NULL\n" +
",LongValue BIGINT NULL\n" +
",ByteValue TINYINT NULL\n" +
");";
this.queryDictionaryFirst(createTableSql);
}
@@ -55,8 +57,10 @@ public class TestDataRepo extends AbstractDhRepo<TestDto>
{
int id = (int) objectMap.get("Id");
String value = (String) objectMap.get("Value");
long longValue = (Long) objectMap.get("LongValue");
byte byteValue = (Byte) objectMap.get("ByteValue");
return new TestDto(id, value);
return new TestDto(id, value, longValue, byteValue);
}
@Override
@@ -69,8 +73,8 @@ public class TestDataRepo extends AbstractDhRepo<TestDto>
String value = (dto.value != null) ? dto.value+"" : "NULL";
return
"INSERT INTO "+this.getTableName()+" (Id, Value) " +
"VALUES("+id+",'"+value+"');";
"INSERT INTO "+this.getTableName()+" (Id, Value, LongValue, ByteValue) " +
"VALUES("+id+",'"+value+"',"+dto.longValue+","+dto.byteValue+");";
}
@Override
@@ -81,7 +85,10 @@ public class TestDataRepo extends AbstractDhRepo<TestDto>
return
"UPDATE "+this.getTableName()+" " +
"SET Value = '"+value+"' " +
"SET " +
" Value = '"+value+"' \n" +
" ,LongValue = "+dto.longValue + " \n" +
" ,ByteValue = "+dto.byteValue + " \n" +
"WHERE Id = "+id;
}
+31 -1
View File
@@ -20,19 +20,49 @@
package testItems.sql;
import com.seibel.distanthorizons.core.sql.IBaseDTO;
import org.junit.Assert;
public class TestDto implements IBaseDTO
{
public int id;
public String value;
public long longValue;
public byte byteValue;
public TestDto(int id, String value)
public TestDto(int id, String value, long longValue, byte byteValue)
{
this.id = id;
this.value = value;
this.longValue = longValue;
this.byteValue = byteValue;
}
@Override
public String getPrimaryKeyString() { return this.id+""; }
@Override
public boolean equals(Object other)
{
if (other.getClass() != this.getClass())
{
return false;
}
else
{
TestDto otherDto = (TestDto) other;
return otherDto.id == this.id
&& otherDto.value.equals(this.value)
&& otherDto.longValue == this.longValue
&& otherDto.byteValue == this.byteValue;
}
}
@Override
public String toString()
{
return this.id + ", " + this.value + ", " + this.longValue + ", " + this.byteValue;
}
}
@@ -82,14 +82,13 @@ public class DhRepoSqliteTest
//===========//
// insert
TestDto insertDto = new TestDto(0, "a");
TestDto insertDto = new TestDto(0, "a", 0L, (byte) 0);
testDataRepo.save(insertDto);
// get
TestDto getDto = testDataRepo.getByPrimaryKey("0");
Assert.assertNotNull("get failed, null returned", getDto);
Assert.assertEquals("get/insert failed, not equal", insertDto.id, getDto.id);
Assert.assertEquals("get/insert failed, not equal", insertDto.value, getDto.value);
Assert.assertEquals("get/insert failed, not equal", insertDto, getDto);
// exists - DTO present
Assert.assertTrue("DTO exists failed", testDataRepo.exists(insertDto));
@@ -97,14 +96,13 @@ public class DhRepoSqliteTest
// update
TestDto updateMetaFile = new TestDto(0, "b");
TestDto updateMetaFile = new TestDto(0, "b", Long.MAX_VALUE, Byte.MAX_VALUE);
testDataRepo.save(updateMetaFile);
// get
getDto = testDataRepo.getByPrimaryKey("0");
Assert.assertNotNull("get failed, null returned", getDto);
Assert.assertEquals("get/insert failed, not equal", updateMetaFile.id, getDto.id);
Assert.assertEquals("get/insert failed, not equal", updateMetaFile.value, getDto.value);
Assert.assertEquals("get/insert failed, not equal", updateMetaFile, getDto);
// delete