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

fix: multi setll #61

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sql/src/main/kotlin/com/smeup/dbnative/sql/SQLDBFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class SQLDBFile(


private fun readNextFromResultSet(loadNext: Boolean): Result {
if (nextResult == null) nextResult = Result(resultSet.toValues())
if (nextResult == null || nextResult!!.record.isEmpty()) nextResult = Result(resultSet.toValues())
val result = nextResult

var found: Boolean = false
Expand Down
29 changes: 22 additions & 7 deletions sql/src/test/kotlin/com/smeup/dbnative/sql/SQLReadEqualTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class SQLReadEqualTest {

companion object {

private lateinit var dbManager: SQLDBMManager

@BeforeClass
@JvmStatic
fun setUp() {
Expand Down Expand Up @@ -67,7 +66,7 @@ class SQLReadEqualTest {
@Test
fun findRecordsIfChainAndReadEExistingKey() {
val dbFile = dbManager.openFile(EMPLOYEE_VIEW_NAME)
val setllResult = dbFile.setll( "C01")
val setllResult = dbFile.setll("C01")
assertEquals("SALLY KWAN", getEmployeeName(dbFile.readEqual("C01").record))
assertEquals("DELORES QUINTANA", getEmployeeName(dbFile.readEqual("C01").record))
assertEquals("HEATHER NICHOLLS", getEmployeeName(dbFile.readEqual("C01").record))
Expand All @@ -79,23 +78,23 @@ class SQLReadEqualTest {
@Test
fun readUntilEof() {
val dbFile = dbManager.openFile(EMPLOYEE_VIEW_NAME)
val setllResult = dbFile.setll( "C01")
val setllResult = dbFile.setll("C01")
var readed = 0;
var readResult = Result()
while (dbFile.eof() == false) {
readResult = dbFile.readEqual("C01")
readed++
}
assertEquals(4, readed)
assertTrue (readResult.indicatorEQ)
assertTrue(readResult.indicatorEQ)
dbManager.closeFile(EMPLOYEE_VIEW_NAME)
}

@Test
fun equals() {
val dbFile = dbManager.openFile(EMPLOYEE_VIEW_NAME)
val chainResult = dbFile.setll( "C01")
assertTrue (dbFile.equal())
val chainResult = dbFile.setll("C01")
assertTrue(dbFile.equal())
dbManager.closeFile(EMPLOYEE_VIEW_NAME)
}

Expand All @@ -112,6 +111,20 @@ class SQLReadEqualTest {
dbManager.closeFile(EMPLOYEE_VIEW_NAME)
}

@Test
fun setllReadsetllReade() {
val dbFile = SQLReadEqualTest.dbManager.openFile(MUNICIPALITY_TABLE_NAME)
assertTrue(dbFile.setll(buildMunicipalityKey("IT", "LOM", "BS")))
while (!dbFile.eof()) {
dbFile.read()
}
assertTrue(dbFile.setll(buildMunicipalityKey("IT", "LOM", "BS")))
val result = dbFile.readEqual(buildMunicipalityKey("IT", "LOM", "BS"))
assertEquals("ACQUAFREDDA", getMunicipalityName(result.record))

SQLReadEqualTest.dbManager.closeFile(MUNICIPALITY_TABLE_NAME)
}

@Test
fun doesNotFindRecordsIfReadEWithKeyNotExistingKey() {
val dbFile = dbManager.openFile(EMPLOYEE_VIEW_NAME)
Expand All @@ -130,6 +143,7 @@ class SQLReadEqualTest {
assertEquals(0, dbFile.readEqual("C01").record.size)
dbManager.closeFile(EMPLOYEE_VIEW_NAME)
}

@Test
fun setgtReade() {
val dbFile = SQLReadEqualTest.dbManager.openFile(MUNICIPALITY_TABLE_NAME)
Expand All @@ -146,6 +160,7 @@ class SQLReadEqualTest {
assertEquals("ZONE", getMunicipalityName(dbFile.readEqual(buildMunicipalityKey("IT", "LOM", "BS")).record))
var r = dbFile.readEqual(buildMunicipalityKey("IT", "LOM", "BS"))
assertTrue(dbFile.eof())
assertTrue(r.indicatorEQ)
r = dbFile.readEqual(buildMunicipalityKey("IT", "LOM", "BS"))
assertTrue(dbFile.eof())
SQLReadEqualTest.dbManager.closeFile(MUNICIPALITY_TABLE_NAME)
Expand Down