I suggest starting again from scratch, using the tutorials as a template.
Receive and Output H2 Database Column Value
-
coolboy714cp
- Posts: 323
- Joined: 06 Feb 2010, 02:45
- Contact:
-
coolboy714cp
- Posts: 323
- Joined: 06 Feb 2010, 02:45
- Contact:
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:
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.
Thanks for any help in advance.
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]);
}I am needing it to come out as what it says directly in the database. How can I achieve this?[Received]: <msg t="xt"><body action="xtRes" r="-1"><dataObj><obj o='db' t='a'><obj o='2' t='a'></obj><obj o='1' t='a'></obj><obj o='0' t='a'></obj></obj><var n='_cmd' t='s'>showData</var></dataObj></body></msg>
Thanks for any help in advance.
-
coolboy714cp
- Posts: 323
- Joined: 06 Feb 2010, 02:45
- Contact:
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:
People have been telling me to use this:
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?
Code: Select all
var Row = queryRes.get(0)
result = Row.getItem("COUNT(NAME)")Code: Select all
var Row = queryRes.get(0)
result = Row.getItem("TABLE NAME")Which one is the correct use, or does it matter which one you use?
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.
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:
-
coolboy714cp
- Posts: 323
- Joined: 06 Feb 2010, 02:45
- Contact:
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.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
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
}
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
}