SQLITE and strftime function (No Output)

ashchopra

Member
Licensed User
Longtime User
Hi,

The Following Query in the code below is executed without error in an external program but fails to produce any output in B4A (No Errors Either)

Dim SQLDataBase As SQL
SQLDataBase.Initialize(File.DirRootExternal, "MyData.db", False)

Dim SEHrs As String

SQLDataBase.ExecQuery("SELECT SUM(strftime('%H',SE_Hours)) As SEHrs From LogBook" )
Log(SEHrs)

Where MyData.db is the database, SE_Hours is a column containing time in hh:mm format, LogBook is the table within the database.

Even a simple query like
SQLDataBase.ExecQuery("SELECT strftime('%H','20:30:45'))
shows no output and no errors either but executes in an external program.

What am I missing here ??
Do help.

Thanks
:sign0085:
 

ashchopra

Member
Licensed User
Longtime User
Figured Out

Okay, Got this figured out :

I need to use
SEDayHrs = SQLDataBase.ExecQuerySingleResult("SELECT SUM(strftime('%H',SE_Hours)) From LogBook" )

instead of

SQLDataBase.ExecQuery("SELECT SUM(strftime('%H',SE_Hours)) As SEHrs From LogBook" )

Thanks !!
:D
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I am glad it worked for you. But the code you had initially could have worked for you if you dimed a cursor. See below:
B4X:
Dim Cursor1 as Cursor
Dim SEhrs as string
Cursor1=SQLDataBase.ExecQuery("SELECT SUM(strftime('%H',SE_Hours)) As SEHrs From LogBook" )
Cursor1.position=0
SEhrs=GetString("SE_Hours")
 
Upvote 0
Top