18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Problem with count(*)

PriyaPriya Members
edited November -1 in Sahi - Open Source
Hi all,

I just want retrive the count of users who belongs to WORK_GROUP_ID '1' and STATUS can be 9001||9002||9003
Here is my code:
Can any one suggest me whats wrong

var db = _getDB("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@10.11.252.254:1521:qgn600r2", "userId", "password");
var $Query=[];
$Query=db.select("select count(*) from USER_PROFILE where (WORK_GROUP_ID) = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003');
_alert(($Query[0]["COUNT(*)"]));


Regards
Priya

Comments

  • narayannarayan Administrators
    The end double quote in the query is missing. (The string was not terminated properly.)
    $Query=db.select("select count(*) from USER_PROFILE where (WORK_GROUP_ID) = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'");
    
    If that was just a typo while reporting here, correct us : )
  • hi
    sorry Narayana . i have used the same code what ever u have sent . it was missing only here but not in my script. please help me out


    Regards
    Priya
  • I have used this script :

    var db = _getDB("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@10.11.252.254:1521:qgn600r2", "userid", "passwrd");
    var $Query=[];
    $Query=db.select("select count(*) from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'");
    _alert(($Query[0]["COUNT(*)"]));


    I am getting this error

    Error in script:
    SyntaxError: missing : after property id (<cmd>#69(eval)#1)
    --Stopped Playback: FAILURE--


    Can U please explain me what is this error.
  • narayannarayan Administrators
    Could you try this?
    $Query=db.select("select count(*) as total from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'");
    _alert(($Query[0]["total"]));
    
    I have given a name to the count(*). If this does not work, I will have to test it out and see. Btw, are you sure these are the lines which cause the problem?
  • Hi Narayan,
    Thanks for the responce. i have tried the above query , but even this is returning an "undefined value"
  • Hi Priya,

    See if this works:
    var db = _getDB("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@10.11.252.254:1521:qgn600r2", "userid", "passwrd");
    var $Query=[];
    $Query[0]=[];
    _set($Query, db.select("select count(*) from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'"));
    _alert($Query[0]["COUNT(*)"]);//I hope COUNT(*) is the name of the column
    
    Regards,
    Pankaj.
  • Hi pankaj,

    This statement is executing more than once which leads to failure.

    _set($Query, db.select("select count(*) from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'"));
  • Can we see the error log?
  • Hi pankaj,

    If i use the Query like this,means if set the returned value to a $query,

    _set($Query, db.select("select count(*) from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'"));

    This error is generated,

    The Query line repeats for several times and this error line is given
    TypeError: 'db' is undefined
    No trace available

    same line if written like this :

    $Query=db.select("select count(*) from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'");

    jserror SyntaxError: missing : after property id (#69(eval)#1)

    And i am sure that DB connection is successful because other queries are working fine and i am facing this problem only with count(*).
  • narayannarayan Administrators
    Pankaj:
    Your way of using _set for db queries will not work for Sahi V2.
    _set is used to assign values fetched from the browser. The db query is executed on the proxy itself and hence you no longer need to do that.

    Priya:
    Why don't you alert $Query[0] and see what is being returned? That will give you an idea of why you keep seeing an error.
  • Hi narayan,

    Its giving the below syntax error hence cannot move further

    Error in script:
    SyntaxError: missing : after property id (<cmd>#69(eval)#1)
    --Stopped Playback: FAILURE--

    <cmd>#69 does this mean error in line 69,but i have only 5 lines of code.
  • Oops!
    I am still using the older version. Sorry guys :(
  • Hi narayan and pankaj,
    thanks for the responce
    i got the solution to retrieve the total number of rows in a table without using the count,as count(*) is giving a problem

    var $stmt="select * from USER_PROFILE where WORK_GROUP_ID = '1' and STATUS_CD = '9001' or STATUS_CD = '9002' or STATUS_CD = '9003'";
    $rs=db.select($stmt);
    _alert($rs.length);
  • narayannarayan Administrators
    Cool.
    I will check why count(*) fails.
Sign In or Register to comment.