Getting nil value from sqlite3

Hi,

I wanted to implement a database into my app so I’m using sqlite3 and it seems to connect fine but I only get nil values back. 

I followed this guide:

http://developer.coronalabs.com/content/data-storage

And when I copy his code straight off it works.

My code is like this:

require ("sqlite3") local path = system.pathForFile("languagepic.db", system.ResourceDirectory) local db = sqlite3.open( path )

function loadWords() words = {} imageLocation = {} local counter = 1 for row in db:nrows("SELECT \* FROM Words") do print(row.content) end end

I have tried changing to row.content2, row.content3, inserting the column etc.

The thing when I query this particular database I get two nil values, which is the amount of rows in that particular table so it seems that it retrieves data but I can’t extract it.

Can anyone help me with this?

Best regards,

Tomas

Sorry to state the obvious but are you 110% sure the case is correct? Particularly “content”, “Words” and “languagepic”?

That is a fair enough question to ask!

I have double checked it several times:

http://i39.tinypic.com/20a2flh.png

Also, here you can see that two “nil” are printed out (with two records in the database):

http://i43.tinypic.com/r0e6v6.png

And after that I removed one record from the database and only one “nil” got printed out:

http://i42.tinypic.com/b8mq00.png

Not it says row.content3 but I have tried row.content and row.content2 as well.

Thanks for your assistance.

Best regards,

Tomas

I think you are misunderstanding the row.content1,2,3 thing (or maybe you just did that in the example?). You should have your column name there. row.Word / row.ImageLocation for example.  

Ha! You’re right!

It seems that there have been a little to many hours in front of the computer tonight, coding and reading tutorials! Maybe time to hit the sack, come back fresh and not embarrass myself! :wink:

Thanks again!

Best regards,

Tomas

Happens to everyone :slight_smile: Good post anyway so it got resolved quickly.

Sorry to state the obvious but are you 110% sure the case is correct? Particularly “content”, “Words” and “languagepic”?

That is a fair enough question to ask!

I have double checked it several times:

http://i39.tinypic.com/20a2flh.png

Also, here you can see that two “nil” are printed out (with two records in the database):

http://i43.tinypic.com/r0e6v6.png

And after that I removed one record from the database and only one “nil” got printed out:

http://i42.tinypic.com/b8mq00.png

Not it says row.content3 but I have tried row.content and row.content2 as well.

Thanks for your assistance.

Best regards,

Tomas

I think you are misunderstanding the row.content1,2,3 thing (or maybe you just did that in the example?). You should have your column name there. row.Word / row.ImageLocation for example.  

Ha! You’re right!

It seems that there have been a little to many hours in front of the computer tonight, coding and reading tutorials! Maybe time to hit the sack, come back fresh and not embarrass myself! :wink:

Thanks again!

Best regards,

Tomas

Happens to everyone :slight_smile: Good post anyway so it got resolved quickly.