Android Question UltimateListView and SQLite

JGiunta

Member
Hello,

I am trying to create an UltimateListView using data from a SQLite database.
How do i achieve this?

I thought about executing the query in the Activity_Create, like this:

Activity_Create:
    Dim ConnessioneDB As SQL
    ConnessioneDB.Initialize(File.DirInternal, "DatabaseListino.sqlite",False)
    Cursore = ConnessioneDB.ExecQuery("SELECT * FROM Giacenza where Barcode =" )
    Cursore.Position = 0

Then scroll the cursor in the RowContentFiller, like this:

RowContentFiller:
If( Cursore.Position <= Cursore.RowCount - 1) Then
    Dim Oggetto As OggettoCarrello
    Oggetto.Barcode = Cursore.GetString("Barcode")
    Oggetto.Quantita = Cursore.GetString("Quantita")
    
    CellPanel.GetView(0).As(Label).Text = Oggetto.Barcode
    CellPanel.GetView(1).As(Label).Text = Oggetto.Quantita    
        Cursore.Position = Cursore.Position + 1   
    End If

This prompts a few questions:
How do i tell it how many items are there (In the SQL Table or in a hypothetical list?)
How else can i code this?

Thank you for your time.
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hello,

I am trying to create an UltimateListView using data from a SQLite database.
How do i achieve this?

I thought about executing the query in the Activity_Create, like this:

Activity_Create:
    Dim ConnessioneDB As SQL
    ConnessioneDB.Initialize(File.DirInternal, "DatabaseListino.sqlite",False)
    Cursore = ConnessioneDB.ExecQuery("SELECT * FROM Giacenza where Barcode =" )
    Cursore.Position = 0

Then scroll the cursor in the RowContentFiller, like this:

RowContentFiller:
If( Cursore.Position <= Cursore.RowCount - 1) Then
    Dim Oggetto As OggettoCarrello
    Oggetto.Barcode = Cursore.GetString("Barcode")
    Oggetto.Quantita = Cursore.GetString("Quantita")
   
    CellPanel.GetView(0).As(Label).Text = Oggetto.Barcode
    CellPanel.GetView(1).As(Label).Text = Oggetto.Quantita   
        Cursore.Position = Cursore.Position + 1  
    End If

This prompts a few questions:
How do i tell it how many items are there (In the SQL Table or in a hypothetical list?)
How else can i code this?

Thank you for your time.
Use this:

Do While Cursore.NextRow

Loop

RBS
 
Upvote 0

JGiunta

Member
Use this:

Do While Cursore.NextRow

Loop

RBS
Thank you for your answer, @RB Smissaert , but i need a bit of clarification:
Where should i use the snippet? Because if i use it on the RowContentFiller, won't it just end up giving me the last row for every row?
From what i understand, the RowContentFiller is called everytime a row is created, so looping everytime will just give me the last row


At the same time, though, another question comes to mind: where do i close the connection?
In Activity_Create i create the connection and connect to the SQL database, and i execute the query, but does the connection need to be open for the cursor to work?
If not i could just execute the query and then just close the connection.
If it needs to be open, then should i check for the last row in my "RowContentFiller" and then close it there?
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
need a bit of clarification:
UtlimateListView was a great library by Informatix, but it was developed several years ago. Since, you are relatively new to the forum, as an alternative, you will be very pleased if you embark in learning and using xCLV. You will get instant help whm you ask because of its popularity. You can use it with or without SQLite.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
UtlimateListView was a great library by Informatix, but it was developed several years ago. Since, you are relatively new to the forum, as an alternative, you will be very pleased if you embark in learning and using xCLV. You will get instant help whm you ask because of its popularity. You can use it with or without SQLite.
???
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Thank you for your answer, @RB Smissaert , but i need a bit of clarification:
Where should i use the snippet? Because if i use it on the RowContentFiller, won't it just end up giving me the last row for every row?
From what i understand, the RowContentFiller is called everytime a row is created, so looping everytime will just give me the last row


At the same time, though, another question comes to mind: where do i close the connection?
In Activity_Create i create the connection and connect to the SQL database, and i execute the query, but does the connection need to be open for the cursor to work?
If not i could just execute the query and then just close the connection.
If it needs to be open, then should i check for the last row in my "RowContentFiller" and then close it there?

> From what i understand, the RowContentFiller is called everytime a row is created

OK, wasn't aware of that and if that is the case Do While Cursore.NextRow won't work as it will process the whole resultset on every creation of a new row.
In that case something like your posted code should be OK.
You can get the number of rows in the resultset from Cursore.RowCount
I don't think the SQL connection needs to be open to process the resultset, but you could test for that.
Can't you just keep the SQL connection open till the app exits?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Won't keeping the Connection open prevent me from operating on the db?
For example, if i have the connection open, i can't use other connections in other activities to do other operations.
You will need to explain a bit more what your app does. Are you multi-threading?

RBS
 
Upvote 0

JGiunta

Member
You will need to explain a bit more what your app does. Are you multi-threading?

RBS
Nope, not multithreading.
Unfortunately that is quite outside my scope, so i haven't approached it yet.

Basically what my app does is take rows from a CSV downloaded from FTP, inputs them in a SQLite db, then i want to get the SQLite into the UltimateListView.
Then, i basically have another table into the db where i put my "Cart", so i can't have it open.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Won't keeping the Connection open prevent me from operating on the db?
For example, if i have the connection open, i can't use other connections in other activities to do other operations.
I have now downloaded and installed the UltimateListview and have run all the provided examples.
If you run one of these examples, for example WordCount_demo, you will see how data is loaded from
a SQLite database.
Nope, not multithreading.
Unfortunately that is quite outside my scope, so i haven't approached it yet.

Basically what my app does is take rows from a CSV downloaded from FTP, inputs them in a SQLite db, then i want to get the SQLite into the UltimateListView.
Then, i basically have another table into the db where i put my "Cart", so i can't have it open.
That sounds all simple. Just open the connection to the DB on startup (as you are doing now) and close on exit of the app. The examples that come with the ULV download will show you how to get the data from SQLite showing in the ULV.

What do you mean with this:
"so I can't have it open."

RBS
 
Upvote 0

JGiunta

Member
If you run one of these examples, for example WordCount_demo, you will see how data is loaded from
a SQLite database.

That sounds all simple. Just open the connection to the DB on startup (as you are doing now) and close on exit of the app. The examples that come with the ULV download will show you how to get the data from SQLite showing in the ULV.
Thank you for your answer.
I have totally glossed over that when i looked at the examples. I have now copied the basic functioning and now it seems to work properly.
 
Upvote 0
Top