Trouble getting data from SQLite
Posted: Thu Mar 11, 2021 11:50 pm
Good evening. I cannot figure out why this code is not returning the correct information. This is a simple procedure to execute a SQL statement and count the number of rows in the database.
1. No errors are thrown when executing the code.
2. The SQL syntax works fine when using a SQLite Studio.
3. Tried results as both Long and String with the associated library functions GetDatabaseLong and GetDatabaseString
4. Tried both 0 and 1 as the column number (there is only 1 column to return) since I didn't know how it was indexed.
5. I've put in Debug statements to see the SQL and Database name, both variables are populating as intended.
Any ideas? TIA. Jack
1. No errors are thrown when executing the code.
2. The SQL syntax works fine when using a SQLite Studio.
3. Tried results as both Long and String with the associated library functions GetDatabaseLong and GetDatabaseString
4. Tried both 0 and 1 as the column number (there is only 1 column to return) since I didn't know how it was indexed.
5. I've put in Debug statements to see the SQL and Database name, both variables are populating as intended.
Any ideas? TIA. Jack
Code: Select all
UseSQLiteDatabase() ;SQL Lite library
Procedure ExecCountLines(DatabaseName$,Sql$)
;2021-03-03 Jack Phillips
;Returns number of lines in query
result.l ;Results variable Long
;Open database this is a library command built into the sqllite library
OpenDatabase(1, DatabaseName$, "", "", #PB_Database_SQLite)
;SetDatabaseString(1, 0, DatabaseName$)
Debug Sql$ ;works as intended
If DatabaseQuery(1, Sql$,#PB_Database_DynamicCursor)
result=GetDatabaseLong(1, 1) ;tried both column as 0 and as 1, same result each time
Debug result
FinishDatabaseQuery(1)
EndIf
CloseDatabase(1)
EndProcedure
;MAIN
Sql.s ;SQL string For commands
DBName.s ;Database name
; Result.l ; result count
;Get row count
Sql="Select count(PersonName) As RowCount from Test_names"
DBName="Test.sqlite" ;works As inteded
Debug DBName ;works As inteded
ExecCountLines(DBName,Sql)