Android Question Generate a row of numbers and store them into SQLite

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello forum community,

I would like to generate
a row of numbers and store them into SQLite
in each line.

Does anyone know why this is NOT going with this code:
B4X:
    Cursor = SQL1.ExecQuery("SELECT Feld_006 FROM Abrechnung")
        For i = 0 To Cursor.RowCount -1
            Cursor.Position = i
           
            Dim Abrechnung_IDNR As String
            Abrechnung_IDNR = i +1        '-- Position of Cursor +1 --
           
        '-- Save to SQLite --
            SQL1.ExecNonQuery("UPDATE Abrechnung SET Feld_006 = '"&Abrechnung_IDNR&"' ") 'WHERE Feld_006 = '"&Cursor.Position&"' +1 ")
                    Log("-- 3196 -- Abrechnung-IDNR: "&Abrechnung_IDNR&"")
        Next
        Cursor.Close

In the log file the count are displayed , but in SQLite only the " last " IDNR is stored the same in all the rows .

Can anybody give advice?
 

Mahares

Expert
Licensed User
Longtime User
But, my friend, Mahares
I amended the code in post#12.
Although @JOTHA has already solved his problem and no longer pursuing this thread, I would like to pursue it out of curiosity. Why both of your solution codes have to be so complicated.
Here is my solution. Even if rows were deleted later, the numbers will still be unique and ascending:
B4X:
SQL1.ExecNonQuery("update Abrechnung SET Feld_006= rowid")
What is wrong with this approach.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Although @JOTHA has already solved his problem and no longer pursuing this thread, I would like to pursue it out of curiosity. Why both of your solution codes have to be so complicated.
Here is my solution. Even if rows were deleted later, the numbers will still be unique and ascending:
B4X:
SQL1.ExecNonQuery("update Abrechnung SET Feld_006= rowid")
What is wrong with this approach.
When a record is deleted, its rowid is kept. This is why we have to renumber.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
When a record is deleted, its rowid is kept. This is why we have to renumber.
Apparently the exact renumbering was not that important to the guy who posted the thread, as long as they are unique and ascending, if you check one of his posts.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Here is my solution. Even if rows were deleted later, the numbers will still be unique and ascending:
B4X:
SQL1.ExecNonQuery("update Abrechnung SET Feld_006= rowid")
What is wrong with this approach.
Nothing, I agree with you !
 
Upvote 0
Top