Android Question how to using progressbar while running a Thread

manuaaa

Member
Licensed User
Longtime User
Hello all,

Iam using a function for fetching multiple tables data from mssql web database server and then insert same into the tables in my local database (SQLITE).
Things are going well .. now i want to start a progressbar when the thread starts and in the same way i want to hide or stop when the thread stops.
How?

Is there any one to help....

i am using code like this:

Sub Globals
pt as Thread
end sub

Sub button1_click
pt.Start("UPPER1", Null)
End Sub

from
manoj
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I don't understand threads well but I think this is what you want
Got it from threading demo
B4X:
Sub ThreadSub2
    Dim Count As Int
    Dim Params(1) As Object
    Do While Count < 1000
        ' instead of locking like Thread1 we could crudely just wait for the GUI to update
        ' some messages may be lost but this may not matter in some applications
        Count = Count + 1
        Params(0) = Count
        Thread2.RunOnGuiThread("Update2", Params)
        Thread2.Sleep(10)
    Loop
End Sub

Sub Update2(count As Int)
    EditText2.Text = count
    ProgressBar1.Progress = count /10
    Lock2.Unlock
End Sub
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
Thanks for the quick reply Sir,
But for me this code is not sufficient... iam using below given function to fetch the data from mssql
i know its a long method but i dont know another way to fetch data the same and insert into amy local sqlite database.. it takes too much time...
but it is fetching data for me.... Now including this function i want to add a progressbar so that i know how much data will be fetched..

Sub UPPER1
SQL1.ExecNonQuery("delete from TAB_TEAM ") 'the table in my local database
Dim L1 As List
Dim L2 As List
Dim L3 As List
Dim L4 As List
Dim L5 As List
Dim L6 As List
Dim L7 As List
Dim L8 As List
Dim L9 As List
Dim L10 As List
Dim L11 As List
Dim L12 As List
Dim col1 As String
Dim col2 As String
Dim col3 As String
Dim col4 As String
Dim col5 As String
Dim col6 As String
Dim col7 As String
Dim col8 As String
Dim col9 As String
Dim col10 As String
Dim col11 As String
Dim col12 As String


Dim i As Int
L= a.Query("select ID from FS WHERE LC = " &Login.TEXT & "")
For i = 1 To L.Size -1
Msgbox(i,"record")
L1= a.Query("select fsid from FS WHERE LC = " &Login.TEXT & "")
col1 = L1.Get(i)
col1 = col1.Replace("[","").Replace("]","").Replace(",","").Replace("FSID","")

L2= a.Query("select Name from FS WHERE LC = " &Login.TEXT & "")
col2 = L2.Get(i)
col2 = col2.Replace("[","").Replace("]","").Replace(",","").Replace("Name","")

L3= a.Query("SELECT DESIGNATION FROM FS where [lc] = "& Login.TEXT &"")
col3 = L3.Get(i)
col3 = col3.Replace("[","").Replace("]","").Replace(",","").Replace("Designation","")

L4= a.Query("SELECT HQ FROM FS where [lc] = "& Login.TEXT &"")
col4 = L4.Get(i)
col4 = col4.Replace("[","").Replace("]","").Replace(",","").Replace("HQ","")

L5= a.Query("SELECT Division FROM FS where [lc] = "& Login.TEXT &"")
col5 = L5.Get(i)
col5 = col5.Replace("[","").Replace("]","").Replace(",","").Replace("Division","")

L6= a.Query("SELECT Statename FROM FS where [lc] = "& Login.TEXT &"")
col6 = L6.Get(i)
col6 = col6.Replace("[","").Replace("]","").Replace(",","").Replace("Statename","")

L7= a.Query("SELECT MobileNO FROM FS where [lc] = "& Login.TEXT &"")
col7 = L7.Get(i)
col7 = col7.Replace("[","").Replace("]","").Replace(",","").Replace("MobileNO","")

L8= a.Query("SELECT RPTO FROM FS where [lc] = "& Login.TEXT &"")
col8 = L8.Get(i)
col8 = col8.Replace("[","").Replace("]","").Replace(",","").Replace("RPTO","")

L9= a.Query("SELECT RPTOID FROM FS where [lc] = "& Login.TEXT &"")
col9 = L9.Get(i)
col9 = col9.Replace("[","").Replace("]","").Replace(",","").Replace("RPTOID","")

L10= a.Query("SELECT DOB FROM FS where [lc] = "& Login.TEXT &"")
col10 = L10.Get(i)
col10 = col10.Replace("[","").Replace("]","").Replace(",","").Replace("DOB","")

L11= a.Query("SELECT EMAIL FROM FS where [lc] = "& Login.TEXT &"")
col11 = L11.Get(i)
col11 = col11.Replace("[","").Replace("]","").Replace(",","").Replace("EMAIL","")

L12= a.Query("SELECT lvl FROM FS where [lc] = "& Login.TEXT &"")
col12 = L12.Get(i)
col12 = col12.Replace("[","").Replace("]","").Replace(",","").Replace("LVL","")

SQL1.ExecNonQuery("INSERT INTO TAB_TEAM VALUES(" & col1 & ", '" & col2 & "', '" & col3 & "', '" & col4 & "', '" & col5 & "', '" & col6 & "', '" & col7 & "', '" & col8 & "', " & col9 & ", '" & col10 & "', '" & col11 & "', " & col12 & ")")

Next
End Sub
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
sorry for the trouble sir.....
this is my code:

B4X:
Sub Process_Globals
Dim a As MSSQL
Dim SQL1 As SQL 
End Sub

Sub Globals
Dim pt As Thread
Dim TeamBtn as Button
Dim TeamLV as Spinner
Dim L as LIST
End Sub

Sub Activity_Create(FirstTime As Boolean)
If File.Exists(File.DirDefaultExternal,"Database.sql") = False Then
File.Copy(File.DirAssets,"Datbase.sql",File.DirDefaultExternal, "Database.sql")
End If
a.setDatabase("xxx.xxx.xxx.xxx","Database Name","UserID","Password")
If SQL1.IsInitialized = False Then
SQL1.Initialize(File.DirDefaultExternal, "Database.sql", False)
End if
Activity.LoadLayout ("Main")
End Sub

Sub TeamBtn_Click
pt.Start("UPPER1", Null)
End Sub

Sub UPPER1
SQL1.ExecNonQuery("delete from TAB_TEAM ")
Dim L1 As List
Dim L2 As List
Dim L3 As List
Dim L4 As List
Dim L5 As List
Dim L6 As List
Dim L7 As List
Dim L8 As List
Dim L9 As List
Dim L10 As List
Dim L11 As List
Dim L12 As List
Dim col1 As String
Dim col2 As String
Dim col3 As String
Dim col4 As String
Dim col5 As String
Dim col6 As String
Dim col7 As String
Dim col8 As String
Dim col9 As String
Dim col10 As String
Dim col11 As String
Dim col12 As String
Dim i As Int

L= a.Query("select ID from FS WHERE LC = " &Login.TEXT & "")
For i = 1 To L.Size -1
Msgbox(i,"record")
L1= a.Query("select fsid from FS WHERE LC = " &Login.TEXT & "")
col1 = L1.Get(i)
col1 = col1.Replace("[","").Replace("]","").Replace(",","").Replace("FSID","")

L2= a.Query("select Name from FS WHERE LC = " &Login.TEXT & "")
col2 = L2.Get(i)
col2 = col2.Replace("[","").Replace("]","").Replace(",","").Replace("Name","")

L3= a.Query("SELECT DESIGNATION FROM FS where [lc] =  "& Login.TEXT &"")
col3 = L3.Get(i)
col3 = col3.Replace("[","").Replace("]","").Replace(",","").Replace("Designation","")

L4= a.Query("SELECT HQ FROM FS where [lc] =  "& Login.TEXT &"")
col4 = L4.Get(i)
col4 = col4.Replace("[","").Replace("]","").Replace(",","").Replace("HQ","")

L5= a.Query("SELECT Division FROM FS where [lc] =  "& Login.TEXT &"")
col5 = L5.Get(i)
col5 = col5.Replace("[","").Replace("]","").Replace(",","").Replace("Division","")

L6= a.Query("SELECT Statename FROM FS where [lc] =  "& Login.TEXT &"")
col6 = L6.Get(i)
col6 = col6.Replace("[","").Replace("]","").Replace(",","").Replace("Statename","")

L7= a.Query("SELECT MobileNO FROM FS where [lc] =  "& Login.TEXT &"")
col7 = L7.Get(i)
col7 = col7.Replace("[","").Replace("]","").Replace(",","").Replace("MobileNO","")

L8= a.Query("SELECT RPTO FROM FS where [lc] =  "& Login.TEXT &"")
col8 = L8.Get(i)
col8 = col8.Replace("[","").Replace("]","").Replace(",","").Replace("RPTO","")

L9= a.Query("SELECT RPTOID FROM FS where [lc] =  "& Login.TEXT &"")
col9 = L9.Get(i)
col9 = col9.Replace("[","").Replace("]","").Replace(",","").Replace("RPTOID","")

L10= a.Query("SELECT DOB FROM FS where [lc] =  "& Login.TEXT &"")
col10 = L10.Get(i)
col10 = col10.Replace("[","").Replace("]","").Replace(",","").Replace("DOB","") 

L11= a.Query("SELECT EMAIL FROM FS where [lc] =  "& Login.TEXT &"")
col11 = L11.Get(i)
col11 = col11.Replace("[","").Replace("]","").Replace(",","").Replace("EMAIL","") 

L12= a.Query("SELECT lvl FROM FS where [lc] =  "& Login.TEXT &"")
col12 = L12.Get(i)
col12 = col12.Replace("[","").Replace("]","").Replace(",","").Replace("LVL","") 

SQL1.ExecNonQuery("INSERT INTO TAB_TEAM VALUES(" & col1 & ", '" & col2  & "', '" & col3  & "', '" & col4  & "', '" & col5  & "', '" & col6  & "', '" & col7  & "', '" & col8  & "', " & col9  & ", '" & col10  & "', '" & col11  & "', " & col12  & ")")

Next
End Sub

By the help of this code i am able to copy fresh Data of Table 'FS' (which is at web server) to my Local Database Tabel 'TAB_TEAM' (SQLITE Databse) and when the data is updated in my local database i am calling 'NAME' Fields Data in a spinner 'TeamLV'.
I know its a time consuming and long method to insert each columns data one by one in my local database. Its a working code.. But i need to modify it so that i can fastly update my local database table. Is there any other way to do the same...
Secondly i want to show a progressbar when i clicked 'TeamBtn' Button or when this code is running...so that i know how much data is updated or when it get updated...
 
Last edited:
Upvote 0

manuaaa

Member
Licensed User
Longtime User
Please Help me to do that.... Actually i need it very much.. but i don't know the way to do it...
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
i had updated my code:

B4X:
Sub TeamBtn_Click
SQL1.ExecNonQuery("delete from TAB_TEAM")
Dim i as Int
L= a.Query ("Select * From FS Where LC  = " &Login.Text &"")
For i = 1 to L.size -1
SQL1.ExecNonQuery2("INSERT INTO TAB_TEAM VALUES (?,?,?,?,?)", Array as Object (L))
Next
End Sub

Its working very fast now...

As the result of this code i am getting complete data of a row including all columns seprated by commas & brackets in a single Field ... Just look at this----

Data of FS Table in Web Server is like this:

Name | Designation | HQ | Mobile | StateName
Thomas | SM | Rohini | 9898989898 | Delhi



But i Got result like this:

Data of my Local Database Table 'Tab_Team'

Name | Designation | HQ | Mobile | Statename
[Thomas,SM,Rohini,9898989898,Delhi] | Null |Null |Null | Null

Now How can i get it separate columns..?
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I think you have to pass values for every column(question mark)
B4X:
SQL1.ExecNonQuery2("INSERT INTO TAB_TEAM VALUES (?,?,?,?,?)", Array as String(column1value,column2value,column3value,column4value,column5value))

Add question mark (?) for any additional column
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
or you can set just the fields you need
B4X:
SQL1.ExecNonQuery2("INSERT INTO TAB_TEAM SET fielname1=?, fielname2=?, fielname3=?, fielname4=?, fielname5=?;", Array as String(column1value,column2value,column3value,column4value,column5value))
Note that the fieldname1-5 should be replaced with the real fieldnames for this table.

I prefer using this style.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…