Skip to Content
0

how to delete rows from table using XSJS?

Jul 11, 2017 at 03:24 PM

224

avatar image
Former Member

I have a table with 2 columns, USER and USER_EMAIL. This contains about 5 rows and I want to delete the rows using XSJS. Here is my attempt.

function cleanup(){

    var connection = $.db.getConnection();
    var query;
    try {
        query  = 'DELETE FROM \"SCHEMA\".\"TABLE\" WHERE \"USER\" = ' + "'" + rowValue + "'"; //here rowValue is a string variable

        var pstmt = connection.prepareStatement(query);
       var result = pstmt.executeUpdate();
     $.response.setBody(result);

     }catch (e) {
         $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
         $.response.setBody(e.message);
     }
}

 

I tested the query on HANA and it seems to work but when I run it through XSJS it doesn't work.

This is the query I ran on HANA

        DELETE FROM "SCHEMA"."TABLE" WHERE USER= 'USER_ONE';

I ran both

var result = pstmt.executeUpdate(); and
var result = pstmt.executeQuery();

but neither one works, they run but the table is not updated. executeUpdate() returns "1". Not sure what that means. Also I'm using XS classic. If anyone has some idea of to get this working, please share.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Florian Pfeffer
Jul 11, 2017 at 07:35 PM
1

That method executeUpdate returns 1 means, that your statement updated 1 data record (please the the XS JS API reference for that).

But I assume that the changed data is not commited, cause you have not executed method commit of the connection object (connection.commit()) and the autocommit mode is not enabled.

Regards,
Florian

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Yeah, I was simply missing that one line of code/

0