Hello,
I am trying sort my database alphabetically based on the data stored in the columns, but not sure how to do it.
Here is how I have created my database (well it's a example on how my database is setup):
As you will see I have a heap of columns (header1, header2.. header256)
The item_status is a string that will store the status of that item (something I am going to do with it later on)
I need to only select 1 row and log each of the 256 headers alphabetically.
However, I also need to map the item_status with the header that we sorted alphabetically (so that they match up)
The only thing I was going to use was using the code from post 9 from this link: http://www.b4x.com/android/forum/th...hms-teaching-with-basic4android.8548/#content
However, based on the code from post 9 from that link I am not sure how to do it (or if it's even the best way to do it)
Does anyone have any ideas on how I can log the items in my database alphabetically as I can't seem to work it out ?
I do plan to work with the values it logs later on in my app, so by storing them in the app to use later would be a bonus. (one of the reasons I looked at the post from that link above)
I am trying sort my database alphabetically based on the data stored in the columns, but not sure how to do it.
Here is how I have created my database (well it's a example on how my database is setup):
B4X:
Sub Process_Globals
Dim SQL_Database As SQL
End Sub
Sub Globals
Dim item_status(257) As String ' This is set on Activity_Create 0=green | 1=red | 2=yellow
End Sub
Sub Activity_Create(FirstTime As Boolean)
File.Delete(File.DirDefaultExternal, "MyDatabase.db") ' Delete the MyDatabase.db while testing (so it always has a default database while testing)
' create database and load table
SQL_Database.Initialize(File.DirDefaultExternal, "MyDatabase.db", True)
Dim data As String
data = "CREATE TABLE items (id INTEGER PRIMARY KEY"
For k = 1 To 256
data = data & ", header" & k & " TEXT"
Next
data = data & ")"
SQL_Database.execNonQuery(data) ' create the table
data = ""
' Load dummy names into the database for testing
data = "INSERT INTO items VALUES (NULL"
For k1 = 1 To 5
data = data & ",'" & "item " & k1 & "'"
item_status(k1) = "0" ' 0=green | 1=red | 2=yellow
Next
For k1 = 6 To 20 ' no names for items 6-20
data = data & ",'" & "" & "'"
item_status(k1) = "0" ' 0=green | 1=red | 2=yellow
Next
For k1 = 21 To 256
data = data & ",'" & "item " & k1 & "'"
item_status(k1) = "1" ' 0=green | 1=red | 2=yellow
Next
data = data & ")"
SQL_Database.execNonQuery(data) ' load the default data into this table
data = ""
End Sub
As you will see I have a heap of columns (header1, header2.. header256)
The item_status is a string that will store the status of that item (something I am going to do with it later on)
I need to only select 1 row and log each of the 256 headers alphabetically.
However, I also need to map the item_status with the header that we sorted alphabetically (so that they match up)
The only thing I was going to use was using the code from post 9 from this link: http://www.b4x.com/android/forum/th...hms-teaching-with-basic4android.8548/#content
However, based on the code from post 9 from that link I am not sure how to do it (or if it's even the best way to do it)
Does anyone have any ideas on how I can log the items in my database alphabetically as I can't seem to work it out ?
I do plan to work with the values it logs later on in my app, so by storing them in the app to use later would be a bonus. (one of the reasons I looked at the post from that link above)