TrisectDevelopment Active Member Licensed User Longtime User Nov 26, 2015 #1 I'm using DBUtils.ExecuteMap to get an ID from the database like this. Code: Copy findID = DBUtils.ExecuteMap(SQL, "SELECT ID FROM GemteLokationer ORDER BY ID DESC", Null) I use this to get the newest ID and increment it for the next post. The first time I run this where the App create the database and table it works okay. But when delete all posts in the table and start the App again i crasches. It crasches in DBUtil on line 214 Code: Copy cur = SQL.ExecQuery(Query) Is there method to check if a table is empty? Or another way to do what I do? P.S. I deleted the posts in a SQLIte App on the phone not in my App. Last edited: Nov 26, 2015
I'm using DBUtils.ExecuteMap to get an ID from the database like this. Code: Copy findID = DBUtils.ExecuteMap(SQL, "SELECT ID FROM GemteLokationer ORDER BY ID DESC", Null) I use this to get the newest ID and increment it for the next post. The first time I run this where the App create the database and table it works okay. But when delete all posts in the table and start the App again i crasches. It crasches in DBUtil on line 214 Code: Copy cur = SQL.ExecQuery(Query) Is there method to check if a table is empty? Or another way to do what I do? P.S. I deleted the posts in a SQLIte App on the phone not in my App.
M Mahares Expert Licensed User Longtime User Nov 26, 2015 #2 TrisectDevelopment said: Is there method to check if a table is empty? Click to expand... Code: Copy Query="SELECT * FROM GemteLokationer" cur = SQL.ExecQuery(Query) If Cur.RowCount=0 Then Msgbox("Table is empty","") End If Upvote 0
TrisectDevelopment said: Is there method to check if a table is empty? Click to expand... Code: Copy Query="SELECT * FROM GemteLokationer" cur = SQL.ExecQuery(Query) If Cur.RowCount=0 Then Msgbox("Table is empty","") End If
TrisectDevelopment Active Member Licensed User Longtime User Nov 26, 2015 #3 Mahares said: Code: Copy Query="SELECT * FROM GemteLokationer" cur = SQL.ExecQuery(Query) If Cur.RowCount=0 Then Msgbox("Table is empty","") End If Click to expand... Does that work with DBUtils? Upvote 0
Mahares said: Code: Copy Query="SELECT * FROM GemteLokationer" cur = SQL.ExecQuery(Query) If Cur.RowCount=0 Then Msgbox("Table is empty","") End If Click to expand... Does that work with DBUtils?
M Mahares Expert Licensed User Longtime User Nov 26, 2015 #4 TrisectDevelopment said: Does that work with DBUtils? Click to expand... That is part of SQLite native commands. DBUtils will not interfere with it. You will be fine. Upvote 0
TrisectDevelopment said: Does that work with DBUtils? Click to expand... That is part of SQLite native commands. DBUtils will not interfere with it. You will be fine.
TrisectDevelopment Active Member Licensed User Longtime User Nov 26, 2015 #5 Your code works just fine thanks. But I found out that the problem was because I did not initialize SQL. So both ways to do it works now. Upvote 0
Your code works just fine thanks. But I found out that the problem was because I did not initialize SQL. So both ways to do it works now.
klaus Expert Licensed User Longtime User Nov 26, 2015 #6 To get the number of rows in a table you can use this: Code: Copy Dim RowNb As Int RowNb = SQL1.ExecQuerySingleResult("SELECT count(*) FROM GemteLokationer") If the table is empty the result is 0. To get the highest rowID from a table you can use this: Code: Copy Dim MaxRowID As Long MaxRowID = SQL1.ExecQuerySingleResult(SELECT "max(rowID) FROM GemteLokationer") If the table is empty this will through an error, you must check if the table is empty. Code: Copy Dim RowNb As Int Dim MaxRowID = 0 As Long RowNb = Starter.SQL1.ExecQuerySingleResult("SELECT count(*) FROM Stock") If RowNb > 0 Then MaxRowID = Starter.SQL1.ExecQuerySingleResult("SELECT max(rowID) FROM Stock") End If Upvote 0
To get the number of rows in a table you can use this: Code: Copy Dim RowNb As Int RowNb = SQL1.ExecQuerySingleResult("SELECT count(*) FROM GemteLokationer") If the table is empty the result is 0. To get the highest rowID from a table you can use this: Code: Copy Dim MaxRowID As Long MaxRowID = SQL1.ExecQuerySingleResult(SELECT "max(rowID) FROM GemteLokationer") If the table is empty this will through an error, you must check if the table is empty. Code: Copy Dim RowNb As Int Dim MaxRowID = 0 As Long RowNb = Starter.SQL1.ExecQuerySingleResult("SELECT count(*) FROM Stock") If RowNb > 0 Then MaxRowID = Starter.SQL1.ExecQuerySingleResult("SELECT max(rowID) FROM Stock") End If