Skip to main content



      Home
Home » Archived » EGL Development Tools » SQLException(Cannot trap exception)
SQLException [message #896708] Thu, 19 July 2012 09:04 Go to next message
Eclipse UserFriend
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 11:39 Go to previous messageGo to next message
Eclipse UserFriend
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 12:39 Go to previous messageGo to next message
Eclipse UserFriend

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 13:42 Go to previous messageGo to next message
Eclipse UserFriend
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 13:58 Go to previous messageGo to next message
Eclipse UserFriend

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] Thu, 19 July 2012 20:53 Go to previous messageGo to next message
Eclipse UserFriend
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 03:52 Go to previous messageGo to next message
Eclipse UserFriend
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 17:15 Go to previous message
Eclipse UserFriend
Thx.
Previous Topic:mathLIb.round
Next Topic:How-to compare two records
Goto Forum:
  


Current Time: Thu Jun 12 15:53:21 EDT 2025

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

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

Back to the top