GithubHelp home page GithubHelp logo

Comments (4)

wilk avatar wilk commented on August 25, 2024

Well, it's my fault.
Query is just a method to execute a pure SQL statement and follows the solution

SELECT * FROM NEW TABLE (INSERT INTO Users (name, age) VALUES ("Wilk", 26))

By the way, it could be an interesting feature returning the last inserted record after an INSERT sql query ;)

Cheers
Wilk

from node-ibm_db.

onelifemedia avatar onelifemedia commented on August 25, 2024

Are you using a prepare statement? I can't seem to get anything back from an INSERT.

I can't figure out how to INSERT an escaped string, which leaves me vulnerable to errors and SQL injection. Of course, the prepare doesn't seem to return the new inserted row.

What a conundrum.

from node-ibm_db.

avikalar avatar avikalar commented on August 25, 2024

You can use a prepare statement here, to insert an escaped string. You can use the following code snippet as a reference to use prepare statement.

var value = 'AB$C\'DI';
var queryString = "INSERT INTO ***** VALUES(?)";
conn.prepare(queryString, function(err, stmt) {

        stmt.bindSync([value]);
        stmt.executeSync(stmt);
        console.log('Statement executed');

        queryString = "SELECT * FROM *******";
        conn.query(queryString, function (err, data) {
            if (err) {
                console.log('Error recieved: \n'+err);
            }
            console.log(JSON.stringify(data));
        });

        conn.close(function(){
            console.log("Connection Closed");
        });
    });

The insert statement will not return the last row. If you need to fetch the key of the last inserted row, in case of auto generated keys, you can use the following query

SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1'

This query will fetch the latest key generated within a transaction scope and return it back to the user.

If this does not resolve your issue, please share more details, so that we can take a look.

from node-ibm_db.

zamrokk avatar zamrokk commented on August 25, 2024

this works, but if another solution exists ... i buy it

SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1

from node-ibm_db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.