nil value in sql help :(

Hi,
I have a problem with sql.

I’m trying to do is create a database and insert a perform conditional content. But “seems” that saves data so run a print to see what is stored and displayed on the console “nil”

This is the code:

[lua]

require “sqlite3”

– MAKE LOAD DDBB
local path = system.pathForFile(“dattalives.db”, system.DocumentsDirectory)
db = sqlite3.open( path )

local function onSystemEvent( event )
if( event.type == “applicationExit” ) then
db:close()
end
end
–MAKE TABLES
local tablesetup = [[CREATE TABLE IF NOT EXISTS base1 (id INTEGER PRIMARY KEY, valuebase1);]]
print(tablesetup)
db:exec( tablesetup )

tablesetup = [[CREATE TABLE IF NOT EXISTS base2 (id INTEGER PRIMARY KEY, valuebase2);]]
print(tablesetup)
db:exec( tablesetup )

valuebase1 = 2
valuebase2 = 2
tablesetup =[[INSERT INTO base1 VALUES (NULL, ‘]]…valuebase1…[[’);]]
db:exec( tablesetup )

tablesetup =[[INSERT INTO base2 VALUES (NULL, ‘]]…valuebase2…[[’);]]
db:exec( tablesetup )

–QUERY
for row in db:nrows(“SELECT valuebase2 FROM base2”) do

if valuebase2 == 2 then
print(“OK”)
else
print(“no OK”)
end

– I do not see as a result, I make a print to check that everything is OK
print(valuebase2) --I get nil value in console
end
[/lua]

from already thank you very much! :smiley: [import]uid: 192093 topic_id: 36371 reply_id: 336371[/import]

can anyone help me? please i badly need [import]uid: 192093 topic_id: 36371 reply_id: 144464[/import]

Sometimes it takes a little bit for people to respond to forum posts. In your case I don’t see an obvious error since you define valuebase2 to be 2, it should still be 2 inside your loop.

I ran your code and I got the following output:

2013-02-27 18:40:15.986 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base1 (id INTEGER PRIMARY KEY, valuebase1);  
2013-02-27 18:40:15.988 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base2 (id INTEGER PRIMARY KEY, valuebase2);  
2013-02-27 18:40:15.992 Corona Simulator[440:707] OK  
2013-02-27 18:40:15.993 Corona Simulator[440:707] 2  

Now I don’t believe you are accessing the data correctly. I think it should be:

row.valuebase2

as your regular valuebase2 is the simple variable you setup earlier and not from the data returned from the database.
[import]uid: 199310 topic_id: 36371 reply_id: 144474[/import]

Problem solved. I miss you indicate put it in the variable. It was a stupid mistake and forgetfulness.

Rob, if you do not mind could try to help me with this new problem. I spend so unexpected and more I look I find nothing. Thank you very much for everything!
http://developer.coronalabs.com/forum/2013/02/28/problem-addeventlistener-and-storyboard
Thanks! [import]uid: 192093 topic_id: 36371 reply_id: 144517[/import]

Duplicate post deleted, I’ll check out your other thread.
[import]uid: 199310 topic_id: 36371 reply_id: 144599[/import]

can anyone help me? please i badly need [import]uid: 192093 topic_id: 36371 reply_id: 144464[/import]

Sometimes it takes a little bit for people to respond to forum posts. In your case I don’t see an obvious error since you define valuebase2 to be 2, it should still be 2 inside your loop.

I ran your code and I got the following output:

2013-02-27 18:40:15.986 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base1 (id INTEGER PRIMARY KEY, valuebase1);  
2013-02-27 18:40:15.988 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base2 (id INTEGER PRIMARY KEY, valuebase2);  
2013-02-27 18:40:15.992 Corona Simulator[440:707] OK  
2013-02-27 18:40:15.993 Corona Simulator[440:707] 2  

Now I don’t believe you are accessing the data correctly. I think it should be:

row.valuebase2

as your regular valuebase2 is the simple variable you setup earlier and not from the data returned from the database.
[import]uid: 199310 topic_id: 36371 reply_id: 144474[/import]

Problem solved. I miss you indicate put it in the variable. It was a stupid mistake and forgetfulness.

Rob, if you do not mind could try to help me with this new problem. I spend so unexpected and more I look I find nothing. Thank you very much for everything!
http://developer.coronalabs.com/forum/2013/02/28/problem-addeventlistener-and-storyboard
Thanks! [import]uid: 192093 topic_id: 36371 reply_id: 144517[/import]

Duplicate post deleted, I’ll check out your other thread.
[import]uid: 199310 topic_id: 36371 reply_id: 144599[/import]

can anyone help me? please i badly need [import]uid: 192093 topic_id: 36371 reply_id: 144464[/import]

Sometimes it takes a little bit for people to respond to forum posts. In your case I don’t see an obvious error since you define valuebase2 to be 2, it should still be 2 inside your loop.

I ran your code and I got the following output:

2013-02-27 18:40:15.986 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base1 (id INTEGER PRIMARY KEY, valuebase1);  
2013-02-27 18:40:15.988 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base2 (id INTEGER PRIMARY KEY, valuebase2);  
2013-02-27 18:40:15.992 Corona Simulator[440:707] OK  
2013-02-27 18:40:15.993 Corona Simulator[440:707] 2  

Now I don’t believe you are accessing the data correctly. I think it should be:

row.valuebase2

as your regular valuebase2 is the simple variable you setup earlier and not from the data returned from the database.
[import]uid: 199310 topic_id: 36371 reply_id: 144474[/import]

Problem solved. I miss you indicate put it in the variable. It was a stupid mistake and forgetfulness.

Rob, if you do not mind could try to help me with this new problem. I spend so unexpected and more I look I find nothing. Thank you very much for everything!
http://developer.coronalabs.com/forum/2013/02/28/problem-addeventlistener-and-storyboard
Thanks! [import]uid: 192093 topic_id: 36371 reply_id: 144517[/import]

Duplicate post deleted, I’ll check out your other thread.
[import]uid: 199310 topic_id: 36371 reply_id: 144599[/import]

can anyone help me? please i badly need [import]uid: 192093 topic_id: 36371 reply_id: 144464[/import]

Sometimes it takes a little bit for people to respond to forum posts. In your case I don’t see an obvious error since you define valuebase2 to be 2, it should still be 2 inside your loop.

I ran your code and I got the following output:

2013-02-27 18:40:15.986 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base1 (id INTEGER PRIMARY KEY, valuebase1);  
2013-02-27 18:40:15.988 Corona Simulator[440:707] CREATE TABLE IF NOT EXISTS base2 (id INTEGER PRIMARY KEY, valuebase2);  
2013-02-27 18:40:15.992 Corona Simulator[440:707] OK  
2013-02-27 18:40:15.993 Corona Simulator[440:707] 2  

Now I don’t believe you are accessing the data correctly. I think it should be:

row.valuebase2

as your regular valuebase2 is the simple variable you setup earlier and not from the data returned from the database.
[import]uid: 199310 topic_id: 36371 reply_id: 144474[/import]

Problem solved. I miss you indicate put it in the variable. It was a stupid mistake and forgetfulness.

Rob, if you do not mind could try to help me with this new problem. I spend so unexpected and more I look I find nothing. Thank you very much for everything!
http://developer.coronalabs.com/forum/2013/02/28/problem-addeventlistener-and-storyboard
Thanks! [import]uid: 192093 topic_id: 36371 reply_id: 144517[/import]

Duplicate post deleted, I’ll check out your other thread.
[import]uid: 199310 topic_id: 36371 reply_id: 144599[/import]