Receive and Output H2 Database Column Value

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

Just as an update, I thought I'd post just to say that BigFish's advice helped again. xD
I suggest starting again from scratch, using the tutorials as a template.
:)
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

Actually, I just now tried the executeQuery function again. Before I tested the database by using the executeCommand function.

Anyway, this is my extension now:

Code: Select all

	if (cmd=="getData") {
		var zone=_server.getCurrentZone();
		var dbase=_server.getDatabaseManager();
		var sql="SELECT * FROM inventory";
		var queryRes=dbase.executeQuery(sql);
		var response={};
		response._cmd="showData";
		response.db=[];
		if (queryRes!=null) {
			for (var i=0; i<queryRes.size(); i++) {
				var tempRow=queryRes.get(i);
				var item={};
				item.id=tempRow.getItem("id");
				item.itemname=tempRow.getItem("itemname");
				response.db.push(item);
			}
		}
		_server.sendResponse(response, -1, null, [user]);
	}
All the tables and database names are correct because I used the exact same case in the executeCommand testing I did earlier today and it worked fine. When I get a response in the client, it comes out as a lot of characters.
[Received]: <msg t="xt"><body action="xtRes" r="-1"><dataObj><obj o=&apos;db&apos; t=&apos;a&apos;><obj o=&apos;2&apos; t=&apos;a&apos;></obj><obj o=&apos;1&apos; t=&apos;a&apos;></obj><obj o=&apos;0&apos; t=&apos;a&apos;></obj></obj><var n=&apos;_cmd&apos; t=&apos;s&apos;>showData</var></dataObj></body></msg>
I am needing it to come out as what it says directly in the database. How can I achieve this?

Thanks for any help in advance. :)
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

I don't know if this would help any, but my friend recently emailed me an extension which has these two lines of coding in it:

Code: Select all

var Row = queryRes.get(0)
			result = Row.getItem("COUNT(NAME)")
People have been telling me to use this:

Code: Select all

var Row = queryRes.get(0)
			result = Row.getItem("TABLE NAME")
But in the extension my friend gave me, who says it works fine for him, he uses ("COUNT(NAME)") in his extension when the table name is just NAME.

Which one is the correct use, or does it matter which one you use?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Thats because ur friend used SELECT COUNT(NAME) FROM blabla.....
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

Oh alright. So does anyone know what the problem is with my extension as when it traces out, it traces out as undefined.
coolboy714cp
Posts: 323
Joined: 06 Feb 2010, 02:45
Contact:

Post by coolboy714cp »

Does anyone know any way in which my problem can be resolved?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

what is ur current extension code?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Do something like this:

Select COUNT(Name) AS total FROM..

then you can access the data by using getItem("total")
Smartfox's forum is my daily newspaper.
Rutter
Posts: 99
Joined: 12 Dec 2007, 16:21
Location: Canada
Contact:

Post by Rutter »

The data you received back was the raw record data describing the row and not the actual data inside the record. The part of your code :

if (queryRes!=null) {
for (var i=0; i<queryRes.size(); i++) {
var tempRow=queryRes.get(i);
var item={};
item.id=tempRow.getItem("id");
item.itemname=tempRow.getItem("itemname");
response.db.push(item);
}

didn't run. Test for null failed so you didn't create item{} object and therefore didn't push that into the response object.

To test you have to build trace statements within each condition statement to see if the condition was successful or not. You may have to go to something like

if (queryRes.size()> 0) {
//do something
}
Post Reply