Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently October 2nd, 2024, 3:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: trapping return value on sql statement
PostPosted: March 14th, 2005, 11:58 pm 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
This is a quite basic question but it involves script and databases so I'm posting it in here...

I'm just learning OpusScript and I'm new to this type of language and syntax (I trained on COBOL and have only had experience of SQL since).

In the following case:

var rset = mydb.ExecuteSQL("select * from products;");

how would I trap the false return (i.e. no records)? The example I found in the help files uses IF. But can I use IF with an assignment (as above?) or is there some two stage process I have to do? :?

Could someone please help with some syntax?


Thanks v. much

Melanie

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


For this message Melanie has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: March 15th, 2005, 12:05 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Hi Melanie,

Thank you for your enquiry.

The easiest way to determine if no records were returned is to use the GetNumberOfRecords() function to count the number of records in the record set. For example:

Code:
myDB = new Database("FILEDSN=yourdsn.dsn;")
Rset = myDB.ExecuteSQL("SELECT * FROM products;")
if (Rset.GetNumberOfRecords() == 0) {
Debug.trace("No Records Found!")
}


If no records were returned, the debug pane will appear and display 'No Records Found!'.

Kind regards,

_________________
Robin Garrett
Digital Workshop Technical Support


For this message Robin Garrett has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: March 15th, 2005, 1:44 pm 
Offline

Joined: October 25th, 2004, 3:09 pm
Posts: 32
var rset = mydb.ExecuteSQL("select * from products;");
if (rset == false) {
Debug.trace("Error")
}

This will test for rset returning false but this only happens if there is an error. If there are no records you will get a record set object and will have to use the GetNumberOfRecords() function as Robin suggests.


For this message Tony Coleman has been thanked by : mackavi


Top
 Profile  
 
 Post subject: thanks
PostPosted: March 15th, 2005, 9:52 pm 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
Thanks both v. much. :D

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


For this message Melanie has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group