Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » EGL Development Tools » SQLException(Cannot trap exception)
SQLException [message #896708] Thu, 19 July 2012 13:04 Go to next message
Nathan Reed is currently offline Nathan ReedFriend
Messages: 74
Registered: June 2012
Member
Windows XP
EDT 0.8.0
RichUI calling dedicated service

I have modified some RBD code in edt to replace sqllib. The two sets of code below both correctly access a row in a table when the requested row exist. No exception is encountered in that case.

When I try to access a row that does not exist I do not get an sqlexception. Per the tutorial and all the help I can find on try, get and onexception I believe an sql exception should occur if no row exist?

I simply want to know if the attempt to access a row was successful or not.

Sorry for the stupid but I must be doing something wrong and just do not see it.

I also note that I do not see any sql related debug variables.

Can anyone help? Am I approaching this wrong?

Much thx,

Nathan Reed

	function getProcessorMasterRecord(ProcessorID decimal(11,0) in, ProcessorMasterRecord            ProcessorMaster inout) returns (error)
		ProcessorMasterRecord.PROCID = ProcessorID;
		try
			get ProcessorMasterRecord from ProcessorMasterTable;
			NoErrorRecord.severity = 0;
			NoErrorRecord.message = " ";
			return(NoErrorRecord);
		onexception(sqlex sqlexception)
			if (sqlex.SQLState == "02000")
				ErrorRecord.severity = 0000001;
				ErrorRecord.message = "Record not found.";
				return(ErrorRecord);
			else
				ErrorRecord.severity = 0000002;
				ErrorRecord.message = "SQL error getting record.";
				return (ErrorRecord);	
			end // End if	
		end // End try
	end // End function



	function getProcessorMasterRecord(ProcessorID decimal(11,0) in, ProcessorMasterRecord ProcessorMaster inout) returns (error)
		ProcessorMasterRecord.PROCID = ProcessorID;
		try
			get ProcessorMasterRecord 
					from ProcessorMasterTable
					using (ProcessorID)
					with #sql{ select * from ProcessorMaster
										where ProcID = ?};
			NoErrorRecord.severity = 0;
			NoErrorRecord.message = " ";
			return(NoErrorRecord);
		onexception(sqlex sqlexception)
			if (sqlex.SQLState == "02000")
				ErrorRecord.severity = 0000001;
				ErrorRecord.message = "Record not found.";
				return(ErrorRecord);
			else
				ErrorRecord.severity = 0000002;
				ErrorRecord.message = "SQL error getting record.";
				return (ErrorRecord);	
			end // End if	
		end // End try
	end // End function

Re: SQLException [message #896757 is a reply to message #896708] Thu, 19 July 2012 15:39 Go to previous messageGo to next message
Nathan Reed is currently offline Nathan ReedFriend
Messages: 74
Registered: June 2012
Member
Additional information.

I am accessing MySQL 5.1. The table is defined with a unique primary key of one field PROCID. The record definition follows.
package common;

record ProcessorMaster type Entity{@table{name = "processormaster"}}
	PROCID decimal(10){@id};
	PROCNAME string;
	PROCCONTNAME string;
	PROCADDRL1 string;
	PROCADDRL2 string;
	PROCCITY string;
	PROCSTPRV string;
	PROCPHONE decimal(10);
	PROCCONTEMAIL string;
	PROCINSTEMAIL string;
	PROCSETUPDT date;
	PROCSTATUS int;
	PROCPASSWORD string;
end // End record definition
Re: SQLException [message #896772 is a reply to message #896757] Thu, 19 July 2012 16:39 Go to previous messageGo to next message
Dan Darnell is currently offline Dan DarnellFriend
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member

Hmmm. Good question. I wouldn't expect you to get an exception on a row not found but I'm still getting up to speed on how database access in EDT works versus RBD. In RBD, I can do something like this:

get customerRecord with #sql{ SELECT * FROM customer where customerNumber = :customerNumber and foo = 'bar' };

if (SysVar.sqlData.sqlCode == 100)		

  // Customer not found

else

  // Customer found

end


No "sysvar" in EDT so I wonder what the equivalent is or if the technique is altogether different.

--Dan
Re: SQLException [message #896779 is a reply to message #896772] Thu, 19 July 2012 17:42 Go to previous messageGo to next message
Nathan Reed is currently offline Nathan ReedFriend
Messages: 74
Registered: June 2012
Member
Dan:

Thx for the feedback. I am coding around the issue but then I will have to retest a bunch of stuff. If you were doing much in the way of DB in RBD then migrating to EDT is not just a snap.

Testing to see if a record/row exist seems very basic. I was using the code below in RBD. That is why when I found no variable I assumed I must need to trap exception. Bad assumption.

Thx again for the feedback. I will move on.

Nathan Reed


Get ..............................................

if (sqllib.sqldata.sqlcode == 100)
				ErrorRecord.severity = 0000001;
				ErrorRecord.message = "Record not found.";
				return(ErrorRecord);
			else
				return(NoErrorRecord);
			end // End if

Re: SQLException [message #896782 is a reply to message #896779] Thu, 19 July 2012 17:58 Go to previous messageGo to next message
Dan Darnell is currently offline Dan DarnellFriend
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member

Yeah, we were basically using the same technique then. It will be interesting to hear from the EDT team what they have in mind for this.

--Dan
Re: SQLException [message #896832 is a reply to message #896782] Fri, 20 July 2012 00:53 Go to previous messageGo to next message
Joseph Vincens is currently offline Joseph VincensFriend
Messages: 31
Registered: December 2011
Location: Prospect CT
Member
Hi,

Here are 2 ways to determine no results: http://www.eclipse.org/forums/index.php/m/812398/

regards,
Joe
Re: SQLException [message #896864 is a reply to message #896832] Fri, 20 July 2012 07:52 Go to previous messageGo to next message
fahua jin is currently offline fahua jinFriend
Messages: 58
Registered: July 2011
Member
You could also try to use the 'create library/service from database wizard' provided by EDT to take a look how the wizard generated code handle such case.

Rocky
Re: SQLException [message #897034 is a reply to message #896864] Fri, 20 July 2012 21:15 Go to previous message
Nathan Reed is currently offline Nathan ReedFriend
Messages: 74
Registered: June 2012
Member
Thx.
Previous Topic:mathLIb.round
Next Topic:How-to compare two records
Goto Forum:
  


Current Time: Tue Apr 16 20:49:01 GMT 2024

Powered by FUDForum. Page generated in 2.39034 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top