getDataAsList is broken?

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

Moderators: Lapo, Bax

flarb
Posts: 131
Joined: 15 Oct 2007, 21:07
Location: Home of the Body Bag
Contact:

getDataAsList is broken?

Postby flarb » 14 Mar 2008, 20:19

I don't get getDataAsList. I've retrieved a DataRow which has stuff in it. I can grab the elements by name by using getItem on the DataRow. But getDataAsList returns null. Is that function broken?

BTW there are some null values in the DataRow--can that cause getDataAsList to break?
User avatar
Lapo
Site Admin
Posts: 20216
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Mar 2008, 10:35

There are 2 methods in the DataRow which are used internally:

getDataAsList()
getDataAsMap()

getDataAsList should be used only when your DataRow contains columns with numeric indexes. It returns a java.util.List

getDataAsMap should be used when your DataRow contains columns with string indexes. It returns a java.util.Map

(check my other response to your other DataRow-related post)
Lapo
--
gotoAndPlay()
...addicted to flash games
flarb
Posts: 131
Joined: 15 Oct 2007, 21:07
Location: Home of the Body Bag
Contact:

Postby flarb » 15 Mar 2008, 19:02

What if it has both types?
User avatar
Lapo
Site Admin
Posts: 20216
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Mar 2008, 07:23

It's not possible with the DbManager, you choose one of the two methods before executing the query. So you either get back a list or a map.
As I said in another post if you need more advanced interaction with the database you can use the getConnection() method (see the docs) and access the entire JDBC set of methods.

A few resources that might help:
http://www.cs.unc.edu/Courses/wwwp-s98/ ... c/183.html
http://www.onjava.com/pub/a/onjava/exce ... ndex1.html
Lapo

--

gotoAndPlay()

...addicted to flash games
Mhollow
Posts: 24
Joined: 22 Feb 2012, 06:29
Location: Russia

Re: getDataAsList is broken?

Postby Mhollow » 16 Nov 2016, 15:02

Hi!
Could you please explain me the following:
There is a table that consists of 4 fields, and a simple query: "select * from table_name"

List<DataRow> queryRes = (ArrayList<DataRow>)db.executeQuery(sqlStr, DataRow.DATAROW_INTKEY);
DataRow row = queryRes.get(0);
List <String> list = row.getDataAsList();
System.out.println("size = " + list.size());
for (int i = 0; i < list.size(); i++)
System.out.format("list[%d] = %s\n", i, list.get(i));

I I get the following:
size = 5
INFO | jvm 1 | 2016/11/16 18:00:18 | list[0] =
INFO | jvm 1 | 2016/11/16 18:00:18 | list[1] = 8
INFO | jvm 1 | 2016/11/16 18:00:18 | list[2] = 1
INFO | jvm 1 | 2016/11/16 18:00:18 | list[3] = 31796
INFO | jvm 1 | 2016/11/16 18:00:18 | list[4] = 1.1

My questions is:
Why the size of the list is wrong (5 instead of 4), and what is the very first an empty element in the list with index 0 ?
Thanks!
User avatar
Lapo
Site Admin
Posts: 20216
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: getDataAsList is broken?

Postby Lapo » 16 Nov 2016, 15:42

Hi,
column indexes start at index = 1, so you can simply ignore index = 0.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Mhollow
Posts: 24
Joined: 22 Feb 2012, 06:29
Location: Russia

Re: getDataAsList is broken?

Postby Mhollow » 16 Nov 2016, 17:30

Let me pay your attention.
It's absolutely inappropriate behaviour! :cry:
Arrays indexes always begin at index = 0, so why column indexes have to start at index=1??? It's a mess! :x :oops: :shock:
And we've got a stupid empty element in a column List and a discouraging wrong array size as a "bonus"..
......
User avatar
Lapo
Site Admin
Posts: 20216
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: getDataAsList is broken?

Postby Lapo » 17 Nov 2016, 08:57

You can always write your own JDBC code and totally bypass the server's API, if you so desire.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 6 guests