Skip to content

Commit

Permalink
Merge pull request #59 from smeup/develop_df
Browse files Browse the repository at this point in the history
Handle error on readE without prior pointing with LO flag enabled in response
  • Loading branch information
foresti-smeup committed Dec 18, 2023
2 parents 471d165 + 76a1428 commit ea709c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 7 additions & 1 deletion sql/src/main/kotlin/com/smeup/dbnative/sql/SQLDBFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ class SQLDBFile(
}

override fun readEqual(): Result {
return readEqual(adapter.getLastKeys())
var result = Result()
try {
result = readEqual(adapter.getLastKeys())
} catch (exc: Exception) {
result.indicatorLO = true
}
return result
}

override fun readEqual(key: String): Result {
Expand Down
15 changes: 9 additions & 6 deletions sql/src/test/kotlin/com/smeup/dbnative/sql/SQLReadEqualTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.smeup.dbnative.sql

import com.smeup.dbnative.file.Result
import com.smeup.dbnative.sql.utils.*
import org.junit.AfterClass
import org.junit.BeforeClass
Expand Down Expand Up @@ -48,11 +49,10 @@ class SQLReadEqualTest {
}

@Test
fun throwsExceptionIfImmediatelyReadE() {
fun errorIfImmediatelyReadE() {
val dbFile = dbManager.openFile(EMPLOYEE_VIEW_NAME)
assertFailsWith(Exception::class) {
dbFile.readEqual()
}
var result = dbFile.readEqual()
assertTrue(result.indicatorLO)
dbManager.closeFile(EMPLOYEE_VIEW_NAME)
}

Expand Down Expand Up @@ -81,11 +81,13 @@ class SQLReadEqualTest {
val dbFile = dbManager.openFile(EMPLOYEE_VIEW_NAME)
val setllResult = dbFile.setll( "C01")
var readed = 0;
var readResult = Result()
while (dbFile.eof() == false) {
var readResult = dbFile.readEqual("C01")
readResult = dbFile.readEqual("C01")
readed++
}
assertEquals(4, readed)
assertTrue (readResult.indicatorEQ)
dbManager.closeFile(EMPLOYEE_VIEW_NAME)
}

Expand Down Expand Up @@ -132,7 +134,8 @@ class SQLReadEqualTest {
fun setgtReade() {
val dbFile = SQLReadEqualTest.dbManager.openFile(MUNICIPALITY_TABLE_NAME)
assertTrue(dbFile.setgt(buildMunicipalityKey("IT", "LOM", "BS")))
assertEquals("ALBAVILLA", getMunicipalityName(dbFile.readEqual(buildMunicipalityKey("IT", "LOM")).record))
val result = dbFile.readEqual(buildMunicipalityKey("IT", "LOM"))
assertEquals("ALBAVILLA", getMunicipalityName(result.record))
SQLReadEqualTest.dbManager.closeFile(MUNICIPALITY_TABLE_NAME)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class SQLUnsupportedFeaturesTest {
@Test
fun usupportedUnpositioning() {
val dbFile = SQLUnsupportedFeaturesTest.dbManager.openFile(MUNICIPALITY_TABLE_NAME)
assertFails {dbFile.readEqual(buildMunicipalityKey("IT", "LOM", "BS"))}
val result = dbFile.readEqual(buildMunicipalityKey("IT", "LOM", "BS"))
assertTrue { result.indicatorLO }
SQLUnsupportedFeaturesTest.dbManager.closeFile(MUNICIPALITY_TABLE_NAME)
}

Expand Down

0 comments on commit ea709c5

Please sign in to comment.