B4J Question SQLite not updating value - what am I doing wrong?

kostefar

Active Member
Licensed User
Longtime User
Dear All,

The code below:

B4X:
Log (d)
                Log (rs.GetInt ("rowid"))
                sql3.ExecNonQuery ("UPDATE table2 Set difference = " & d & " WHERE rowid = " & rs.GetInt ("rowid"))
                Log (sql3.ExecQuerySingleResult ("SELECT difference FROM table2 LIMIT 1 OFFSET " & (rs.GetInt ("rowid"))))

Shows the following in the log:

B4X:
1.000723
516
(null string)

When logging the content of "difference" in the given rowid, it shows (null string) and not as expected 1.000723, any idea why that is?

FYI, "difference" is defined as REAL in table2.

Thanks in advance!
 

kostefar

Active Member
Licensed User
Longtime User
B4X:
sql3.ExecNonQuery2 ("UPDATE table2 Set difference =? WHERE rowid = ?",array(diffvalue,rowidvalue))

Thanks, but the result is the same. The code now looks like this:

B4X:
                Log (d)
                Log (rs.GetInt ("rowid"))
                'sql3.ExecNonQuery ("UPDATE table2 Set difference = " & d & " WHERE rowid = " & rs.GetInt ("rowid"))
                sql3.ExecNonQuery2 ("UPDATE table2 Set difference =? WHERE rowid = ?", Array (d, rs.GetInt ("rowid")))
                Log (sql3.ExecQuerySingleResult ("SELECT difference FROM table2 LIMIT 1 OFFSET " & (rs.GetInt ("rowid"))))


And the log says:

B4X:
1.00051814
497
(null string)
 
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
Thanks, but the result is the same. The code now looks like this:

B4X:
                Log (d)
                Log (rs.GetInt ("rowid"))
                'sql3.ExecNonQuery ("UPDATE table2 Set difference = " & d & " WHERE rowid = " & rs.GetInt ("rowid"))
                sql3.ExecNonQuery2 ("UPDATE table2 Set difference =? WHERE rowid = ?", Array (d, rs.GetInt ("rowid")))
                Log (sql3.ExecQuerySingleResult ("SELECT difference FROM table2 LIMIT 1 OFFSET " & (rs.GetInt ("rowid"))))


And the log says:

B4X:
1.00051814
497
(null string)
What is the data type of the difference field in the database?
The record with number 497 is available in the database??
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Log (sql3.ExecQuerySingleResult ("SELECT difference FROM table2 LIMIT 1 OFFSET " & (rs.GetInt ("rowid"))))
Not sure why you use OFFSET to check.

Can you try check using rowid?
B4X:
Log(sql3.ExecQuerySingleResult2("SELECT difference FROM table2 WHERE rowid = ?", Array As String(rs.GetInt("rowid"))))
 
Last edited:
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
Not sure why you use OFFSET to check.

Can you try check using rowid?
B4X:
Log(sql3.ExecQuerySingleResult2("SELECT difference FROM table2 WHERE rowid = ?", Array As String(rs.GetInt("rowid"))))
Thanks mate, that worked!
Well, it´s been 8 years since I fiddled with SQL the last time, so I´m patching my knowledge with some code here and there, and apparently the OFFSET way of doing this was the wrong one. Any idea btw. why that´s not working? Then perhaps I could learn a bit.

Also, why not use

B4X:
Log (sql3.ExecQuerySingleResult("SELECT difference FROM table2 WHERE rowid = " & (rs.GetInt("rowid"))))

Are there any advantages of the suggested method?
 
Last edited:
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
What is the data type of the difference field in the database?
The record with number 497 is available in the database??
The datatype is REAL, and the record was available indeed.
The problem was something else, aeric gave me the solution.
But just out of curiosity: Is there a reason to believe that the Execnonquery2 way of doing things is more reliable, correct, efficient etc. than the original one with Execnonquery?
 
Upvote 0
Top