Page 2 of 2

Posted: 13 Dec 2010, 01:21
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.
:)

Posted: 13 Dec 2010, 02:09
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. :)

Posted: 13 Dec 2010, 18:43
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?

Posted: 13 Dec 2010, 18:55
by rjgtav
Thats because ur friend used SELECT COUNT(NAME) FROM blabla.....

Posted: 13 Dec 2010, 20:38
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.

Posted: 16 Dec 2010, 04:05
by coolboy714cp
Does anyone know any way in which my problem can be resolved?

Posted: 16 Dec 2010, 17:35
by rjgtav
what is ur current extension code?

Posted: 16 Dec 2010, 20:50
by BigFIsh
Do something like this:

Select COUNT(Name) AS total FROM..

then you can access the data by using getItem("total")

Posted: 17 Dec 2010, 04:12
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
}