I tried node-jt400 (SQL Update)

SQL update

SQLupdate.js


app.get("/update", function (req, res, next) {
    var count = 0;
    pool.update("update member set prof=? WHERE id=?", ["I tried to update", 100])
        .then(function (nUpdated) {
        count = nUpdated;
        res.send(count + "Updated");
    });
});

The value returned by the callback is set to the updated number. nodejt07.png Update result nodejt08.png

SQL insert

SQLinsert.js


app.get("/insert", function (req, res, next) {
    var insertIds = "";
    var tableName = "MEMBER", idColumn = "ID", rows = [
        { ID: 105, LNAME: "Oda", FNAME: "Nobunaga", PROF: "Before reaching the goal ...", TOKUTEN: 10.5 },
        { ID: 106, LNAME: "Toyotomi", FNAME: "Hideyoshi", PROF: "We unified the world.", TOKUTEN: 10.6 }
    ];
    pool.insertList(tableName, idColumn, rows)
        .then(function (listOfGeneratedIds) {
        for (var _i = 0, listOfGeneratedIds_1 = listOfGeneratedIds; _i < listOfGeneratedIds_1.length; _i++) {
            var insertId = listOfGeneratedIds_1[_i];
            insertIds = insertIds + insertId.toString() + ",";
        }
        res.send(insertIds + "Was inserted");
    });
});

Unfortunately this could not be done on V5R4. Although it is the cause, it seems that the following SQL is issued internally.

SELECT ID FROM NEW TABLE(INSERT INTO MEMBER (ID, LNAME, FNAME, PROF, TOKUTEN) VALUES(?, ?, ?, ?, ?), (?, ?, ?, ?, ?)) 
params: [105,"Oda","Nobunaga","Before reaching the goal ...",10.5,106,"Toyotomi","Hideyoshi","Unified the world",10.6]

It seems that this SQL cannot be interpreted, and an error occurs.

I was able to execute it on V7R2, so I will post the result. nodejt09.png

nodejt10.png

SQL batch update

SQLbatchUpdate.js


app.get("/batchUpdate", function (req, res, next) {
    var insertIds = "";
    var data = [
        [107, "Tokugawa","Ieyasu","The first generation",1],
        [108, "Tokugawa","Hidetada","Second generation",2],
        [109, "Tokugawa","Iemitsu","Third generation",3]
    ];
    pool.batchUpdate("INSERT INTO MEMBER (ID,LNAME,FNAME,PROF,TOKUTEN) VALUES(?,?,?,?,?)", data)
        .then(function (result) {
        for (var _i = 0, result_1 = result; _i < result_1.length; _i++) {
            var insertId = result_1[_i];
            insertIds = insertIds + insertId.toString() + ","; //result is number of updated rows for each row. [1, 1, 1] in this case.
        }
        res.send(insertIds + "Was inserted");
    });
});

This could be done on V5R4. nodejt11.png The return value seems to return the number of updates for each row.

nodejt12.png

Recommended Posts

I tried node-jt400 (SQL Update)
I tried node-jt400 (SQL query)
I tried node-jt400 (SQL stream)
I tried node-jt400 (Programs)
I tried node-jt400 (execute)
I tried node-jt400 (Transactions)
I tried node-jt400 (Environment construction)
I tried node-jt400 (IFS write)
I tried node-jt400 (IFS read)
I tried Spring.
I tried tomcat
I tried youtubeDataApi.
I tried refactoring ①
I tried FizzBuzz.
I tried JHipster 5.1
[I tried] Spring tutorial
I tried using Gson
I tried QUARKUS immediately
I tried using TestNG
I tried Spring Batch
I tried using Galasa
I tried DI with Ruby
I tried using azure cloud-init
I tried Spring State machine
I tried Drools (Java, InputStream)
I tried Rails beginner [Chapter 1]
I tried the Docker tutorial!
I tried using Apache Wicket
I tried the VueJS tutorial!
I tried using Java REPL
I tried source code analysis
I tried the FizzBuzz problem
I tried putting XcodeGen + SwiftPM
I tried Rails beginner [Chapter 2]
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried to verify yum-cron
I tried Jets (ruby serverless)
I tried metaprogramming in Java
I tried to implement flexible OR mapping with MyBatis Dynamic SQL
I tried Angular tutorial + SpringBoot + PostgreSQL
I tried to chew C # (indexer)
I tried something called recursive search
I tried using Spring + Mybatis + DbUnit
[K8s] I tried communication between pods!
I tried morphological analysis with MeCab
I tried a little digdag docker.run_options
I tried to summarize iOS 14 support
I tried to interact with Java
I tried UDP communication with Java
I tried to explain the method
I tried putting Domino11 in CentOS7
I tried the Java framework "Quarkus"
[Rails] I tried deleting the application
I tried using Java8 Stream API
I tried Java's micro-benchmark tool JMH
I tried using JWT in Java
I tried GraphQL with Spring Boot
I tried to summarize Java learning (1)
I tried to understand nil guard
[Android] I tried using Coordinator Layout.