Skip to content

Commit 5e45180

Browse files
authored
Fix Issue #8.
1 parent 2d2740f commit 5e45180

File tree

4 files changed

+61
-60
lines changed

4 files changed

+61
-60
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Open COBOL ESQL 4j (OCESQL 4j) consits of open-source Embedded SQL pre-compiler
55

66
# Requirements
77

8-
* Open-source database
8+
* Open-source database.
99
OCESQL 4j currently supports PostgreSQL database only.
1010

11-
* [opensource COBOL 4j](https://github.com/opensourcecobol/opensourcecobol4j)
11+
* [opensource COBOL 4j](https://github.com/opensourcecobol/opensourcecobol4j) v1.0.2 or later.
1212

13-
* [sbt](https://www.scala-sbt.org/)(Optional)
13+
* [sbt](https://www.scala-sbt.org/)(Optional).
1414

1515

1616
# Installation
@@ -50,10 +50,10 @@ See test cases or sample programs.
5050

5151
# TODO
5252

53-
- [ ] Implement Prepared Statement
54-
- [ ] Support other COBOL data types (COMP5, Japanese, ... etc)
55-
- [ ] Add test cases
56-
- [ ] tests for SQL CA(communication area)
57-
- [ ] tests for SQL data types
58-
- [ ] Set up test environments using Github Actions
59-
- [ ] Create docker images
53+
- [ ] Implement Prepared Statement.
54+
- [ ] Support other COBOL data types (COMP5, Japanese, ... etc).
55+
- [ ] Add test cases.
56+
- [ ] tests for SQL CA(communication area).
57+
- [ ] tests for SQL data types.
58+
- [ ] Set up test environments using Github Actions.
59+
- [ ] Create docker images.

dblibj/project/target/active.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

dblibj/src/main/scala/Common.scala

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ object Common {
313313
while(storage.getByte(i) != 0) {
314314
i += 1
315315
}
316-
Some(new String(storage.getByteArray(0, i)))
316+
Some(new String(storage.getByteArray(0, i), "SHIFT-JIS"))
317317
} catch {
318318
case e: Throwable => None
319319
}
@@ -367,33 +367,23 @@ object Common {
367367
}
368368

369369
private def createCobolDataUnsignedNumber(sv: SQLVar, addr: CobolDataStorage, index: Int, data: scala.Array[Byte]): Unit = {
370-
val finalBufLen = sv.length
371-
val finalBuf = new scala.Array[Byte](finalBufLen)
372-
val indexOfPoint = data.indexOf('.'.toByte)
373-
val beforeDp = if (indexOfPoint < 0) sv.length else indexOfPoint
374-
val fillZero = sv.length - beforeDp + sv.power
375-
for(i <- 0 to fillZero - 1) {
370+
val finalBuf: scala.Array[Byte] = new scala.Array(sv.length)
371+
val isNegative = data(0) == '-'.toByte
372+
val valueFirstIndex = if(isNegative) {1} else {0}
373+
374+
val indexOfDecimalPoint = {
375+
val index = data.indexOf('.')
376+
if(index < 0) { data.length } else { index }
377+
}
378+
for(i <- 0 until finalBuf.length) {
376379
finalBuf(i) = '0'.toByte
377380
}
378-
for(i <- 0 to beforeDp - 1) {
379-
finalBuf(i + fillZero) = data(i)
381+
for(i <- valueFirstIndex until indexOfDecimalPoint) {
382+
finalBuf(i + finalBuf.length - (indexOfDecimalPoint + sv.power)) = data(i)
380383
}
381-
382-
if(sv.power < 0) {
383-
var afterDp = 0
384-
if(indexOfPoint < 0) {
385-
afterDp = data.length - beforeDp - DECIMAL_LENGTH
386-
for(i <- 0 to (afterDp - 1)) {
387-
finalBuf(fillZero + beforeDp + i) = data(beforeDp + DECIMAL_LENGTH + i)
388-
}
389-
}
390-
val fillZero_ = - sv.power - afterDp
391-
for(i <- 0 to (fillZero_ - 1)) {
392-
finalBuf(i) = '0'.toByte
393-
}
384+
for(i <- 0 until finalBuf.length) {
385+
addr.setByte(i, finalBuf(i))
394386
}
395-
396-
addr.memcpy(finalBuf, sv.length)
397387
}
398388

399389
private def createCobolDataSignedNumberTc(sv: SQLVar, addr: CobolDataStorage, index: Int, str: scala.Array[Byte]): Unit = {

dblibj/src/main/scala/Select.scala

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ import java.text.SimpleDateFormat
77
import scala.collection.immutable.Queue
88

99
object Select {
10+
11+
def getPreviousOperationResultSet(id: Int): Operation[Option[ResultSet]] =
12+
lookUpConnList(id).flatMap(_ match {
13+
case None => operationPure(None)
14+
case Some((_, pConn)) => operationPure(pConn.result match {
15+
case Right(EResultSet(rs)) => Some(rs)
16+
case _ => None
17+
})
18+
})
19+
20+
private def errorProc: Operation[Unit] = for {
21+
_ <- setLibErrorStatus(OCDB_NOT_FOUND())
22+
_ <- logLn("TUPLES NODATA")
23+
} yield ()
24+
1025
def ocesqlExecSelectIntoOne(id: Int, query: Option[String], nParams: Int, nResParams: Int): Operation[Unit] = (for {
1126
state <- operationCPure(getState)
1227
_ <- whenExecuteAndExit(query.getOrElse("").length == 0, for {
@@ -21,6 +36,8 @@ object Select {
2136
ocesqlExec(id, query)
2237
})
2338

39+
rs <- operationCPure(getPreviousOperationResultSet(id))
40+
2441
status <- operationCPure(setResultStatus(id))
2542
_ <- whenExecuteAndExit(!status, operationPure(()))
2643

@@ -30,32 +47,27 @@ object Select {
3047
_ <- setLibErrorStatus(OCDB_EMPTY())
3148
} yield ())
3249

33-
// TODO remark これ不要?
34-
tuples <- operationCPure(OCDBNtuples(id))
35-
36-
_ <- operationCPure(
37-
if(tuples < 1) {
38-
for {
39-
_ <- setLibErrorStatus(OCDB_NOT_FOUND())
40-
_ <- logLn("TUPLES NODATA")
41-
} yield ()
42-
} else {
43-
forM(state.globalState.sqlResVarQueue.zipWithIndex){e => {
44-
val (sv, i) = e
45-
if(i >= fields){
46-
operationPure(())
47-
} else {
48-
for {
49-
retStr <- OCDBGetValue(id, i + 1)
50-
_ <- operationPure(retStr match {
51-
case Some(str) => createCobolData(sv, 0, str, state.globalState.occursInfo)
52-
case _ => ()
53-
})
54-
} yield ()
55-
}
50+
_ <- operationCPure(rs match {
51+
case None => errorProc
52+
case Some(rs) => if (rs.next()) {
53+
forM(state.globalState.sqlResVarQueue.zipWithIndex) { e => {
54+
val (sv, i) = e
55+
if (i >= fields) {
56+
operationPure(())
57+
} else {
58+
for {
59+
retStr <- OCDBGetValue(id, i + 1)
60+
_ <- operationPure(retStr match {
61+
case Some(str) => createCobolData(sv, 0, str, state.globalState.occursInfo)
62+
case _ => ()
63+
})
64+
} yield ()
5665
}
57-
}
58-
})
66+
}}
67+
} else {
68+
errorProc
69+
}
70+
})
5971
} yield ()).eval
6072

6173
def ocesqlExecSelectIntoOccurs(id: Int, query: Option[String], nParams: Int, nResParams: Int): Operation[Unit] = (for {

0 commit comments

Comments
 (0)