Hi
I have many subs where this is workign but all of a sudden , this does not work. I have checked the strings are the same and still it does not pick up that there are records already in the database. If there is already the same date (String) in the database then it should do nothing. If the result is equal to 0 then it should insert...
This is from the log
Today is: 05/20/2017
05/20/2017
and the fields in the database are TEXT for the Date and Numberic for the Rate
Here is the snip of code
Thank you
B4X:
txtDte.Text=DateTime.Date(DateTime.Now)
Log(txtDte.Text)
If sql1.ExecQuerySingleResult("SELECT count(*) FROM xrate WHERE Date = "&txtDte.text) <> 0 Then
Else
sql1.ExecNonQuery2("INSERT INTO xrate VALUES (?,?)", Array As Object(txtDte.text, xrate)) ' add field
End If
I updated the code to include what you suggested and it does not count any , even though it is in the database. It gives an error that the data is already in and connot add due to duplication
java.sql.SQLException: [SQLITE_CONSTRAINT] Abort due to constraint violation (column Date is not unique)
B4X:
Dim counter As Int = sql1.ExecQuerySingleResult("SELECT count(*) FROM xrate WHERE Date = "&txtDte.text)
If counter = 1 Then
Log("already in DB")
Else
sql1.ExecNonQuery2("INSERT INTO xrate VALUES (?,?)", Array As Object(txtDte.text, xrate)) ' add field
End If
this is to check in your logs, what value is holding the counter variable
B4X:
Dim counter As Int = sql1.ExecQuerySingleResult("SELECT count(*) FROM xrate WHERE Date = "&txtDte.text)
log("dates in db " &counter)
this is just a change.
B4X:
Dim counter As Int = sql1.ExecQuerySingleResult2("SELECT count(*) FROM xrate WHERE Date = ?",array as string(txtDte.text))
log("dates in db " &counter)
this is to check in your logs, what value is holding the counter variable
B4X:
Dim counter As Int = sql1.ExecQuerySingleResult("SELECT count(*) FROM xrate WHERE Date = "&txtDte.text)
log("dates in db " &counter)
this is just a change.
B4X:
Dim counter As Int = sql1.ExecQuerySingleResult2("SELECT count(*) FROM xrate WHERE Date = ?",array as string(txtDte.text))
log("dates in db " &counter)