db:exec runs sql code, and returns 0 if it succeeds.
db:nrows is an iterator that will return a table with named columns for each item.
so for one item you'd do something like this.
1
2
3
4
| for a in db:nrows('SELECT timestamp FROM table WHERE something= '1' LIMIT '1'')
do
output = a[timestamp]
end |
Sean, remember that SQlite restart bug we spoke about? Seems to be limited to the simulator, not been able to replicate it on device yet.
Hi ,
Is there any other way that..without for loop we can get the single record from sql statement?
Thanks,
Krunal
@Krunal
What have you tried that hasn't worked? Maybe it can serve as a starting point for others to try out.
Hi Luna,
Thankx for reply.
I am tried with,
for row in db:nrows("SELECT * FROM Employee where Id ="..id) do
detailScreenText.text = "ID = ".. row.Id.."\nName :"..row.Name
end
Its working fine for me.
but i want to do somethings like,
row = db:[function name]("SELECT * FROM Employee where Id ="..id)
so after that i can use row.Id easily...
Now you can understand what i want.
Thanks.
Krunal
@Krunal try this link:
http://luasqlite.luaforge.net/lsqlite3.html#examples
There are samples there that might do what you want.
@ Luna:
I knw about this but there i hv describe this b'cas u told me that what u want so thats y i hv just write this db:[function]....
now u getting...what i want...
@ seanh
Sean I tried your for loop but I can not get this to work:
1
2
3
4
5
6
7
8
9
10
| local db = getDatabase()
local stmt = db:prepare("SELECT count(id) FROM ? LIMIT 1")
stmt:bind( 1, inTable.tableName )
for row in stmt:rows() do
print(row[1])
end
db:close() |
just coming back to the first post...
i really don't know how that should work just with a single row
row = db:first_row("SELECT count(*) AS count FROM test")
print(row.count)
just a single command, (no loop) and a simple result (amount of rows)
but it does not work...i also looked into the sqlite documentation,
there not even a command "first_row" ... so what ?
till now i still have to work with
for row in mdfunc.db:nrows("SELECT count(*) AS count FROM data LIMIT 1") do
print (row.count)
end
till now its still the fastest solution I found
chris
views:2223 update:2011/10/5 8:48:05