Re: [sqlite] How do you access a specific row of a resultset?
On 16 May 2012, at 11:14pm, Goatjugsoupwrote: > Well, a new thought just came to me, if I use the same sql statement will the > resultset be in the same order each time because if that is the case I > imagine I could use a for statement and an index to move through it the way > I want to with next inside of that as many times as it takes to get to where > I need. SQLite is free to return rows in any order which satisfies your ORDER BY clause. It is possible for the same SELECT statement, run twice in a row, with the same data in the table, to return its rows in a different order. Two ways I can think of to make this happen are to create a new index, and to do an ANALYZE, but there are probably others which I haven't thought of. If you want your rows to be returned in the same order every time, use an ORDER BY clause for your SELECT statement, and make sure the order you've asked for the rows gives every row a unique value. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How do you access a specific row of a resultset?
> if I use the same sql statement will the > resultset be in the same order each time Only if you use ORDER BY clause, and the set of columns in this clause have unique values for each row, and all these values don't change between query executions. Pavel On Wed, May 16, 2012 at 6:14 PM, Goatjugsoupwrote: > > Well, a new thought just came to me, if I use the same sql statement will the > resultset be in the same order each time because if that is the case I > imagine I could use a for statement and an index to move through it the way > I want to with next inside of that as many times as it takes to get to where > I need. > -- > View this message in context: > http://old.nabble.com/How-do-you-access-a-specific-row-of-a-resultset--tp33856419p33861287.html > Sent from the SQLite mailing list archive at Nabble.com. > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How do you access a specific row of a resultset?
Well, a new thought just came to me, if I use the same sql statement will the resultset be in the same order each time because if that is the case I imagine I could use a for statement and an index to move through it the way I want to with next inside of that as many times as it takes to get to where I need. -- View this message in context: http://old.nabble.com/How-do-you-access-a-specific-row-of-a-resultset--tp33856419p33861287.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How do you access a specific row of a resultset?
The other thing you are not thinking about is that you never know the order of data in a set. You may think that you want the 5th record that was ever inserted into the table, but you have no guarantee that a select statement will return records in the order in which they were inserted. The 5th oldest record could come up first in the result set, or last, or anywhere else. So, you either have to walk through the set from the beginning, checking every record to see if it's the one you want, or you're going to have to build a more precise select statement. RobR ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How do you access a specific row of a resultset?
Goatjugsoupwrote: > Hi, I want to know how to go about getting a specific row from a resultset > (or if there is a different way to do it Im all for that too) That rather depends on what "it" is. What's the point of the exercise? Are you looking to implement something like this, by any chance: http://www.sqlite.org/cvstrac/wiki?p=ScrollingCursor -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How do you access a specific row of a resultset?
On 16 May 2012, at 9:04am, Goatjugsoupwrote: > Hi, I want to know how to go about getting a specific row from a resultset > (or if there is a different way to do it Im all for that too) > > My code goes something like this, stat being a statement variable already > initialised previously. I thought perhaps absolute sounds like it might give > the required row but it doesnt seem to have. s is a string declared already > previously and picPath is a column of the table. I hope I have made what I > am trying to do clear and would appreciate any help. > > ResultSet rs = stat.executeQuery("select * from table1;"); > rs.absolute(index); > s = rs.getString("picPath"); What programming language and API are you using ? My guess is that you can't do what you want. You have to iterate through the result set using .next() . The results of the query aren't all loaded up in an array waiting for you, they're not ready for you until you have used .next() to fetch them. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users