Android Question database sul server

SalentoFC

Member
Licensed User
Salve a tutti.
Volevo sapere come fare ad aggiornare un file .db esistente sul server. È un file di classifica per gioco. Io scarico il file con ftp.download... poi il file che ho scaricato lo popolo con i miei dati e all'atto di effettuare l'upload sul server non mi da errori ma noto dal file di log "java.net.unknownhostexception: ftp.... etc cioè non riconosce il nome del server immagino. Cosa devo fare? Sto impazzendo.. grazie a tutti!
 

LucaMs

Expert
Licensed User
Intanto dovresti scrivere in inglese o nel forum italiano ;)

You should write in english or in the italian forum.

Se il download funziona, dovrebbe funzionare anche l'upload. Ti conviene pubblicare il codice, se puoi.
 

SalentoFC

Member
Licensed User
Yes ;-)
I just saw both download and upload not work. The server is on altervista.org.

ftp.robertodaniele altervista.org
the file .db should download from path sMg/database.db but not work.
Tks

p.s. the code is that download from b4a with ftp.downloadfile and ftp.uploadfile and library net
 

SalentoFC

Member
Licensed User
Have you tried: "robertodaniele.altervista.org" ?

FTP.Initialize("FTP", "robertodaniele.altervista.org", 21, "User", "PW")
Yes it's strange infact..
if you like to prove the db is avaible at robertodaniele.altervista.org/sMg/sMg_21hz133.db

ps i tried it throw android emulator and no too with real device.
my scope is to download db, popolated it with news datas and upload the final file on server. But, repeat, the error is about name of server (unknownhostexception: ftp.robertodaniele.altervista.org
 

LucaMs

Expert
Licensed User
B4X:
mServerAddr = "robertodaniele.altervista.org"
  
mFTPServerUserFolder = "/sMg/"

If FirstTime Then
     FTP.Initialize("FTP", mServerAddr, 21, "robertodaniele", "curbikegko33")
End If

FTP.DownloadFile(File.Combine(mFTPServerUserFolder,"sMg_21hz133.db"), False, File.DirRootExternal, "sMg_21hz133.db")
 

SalentoFC

Member
Licensed User
B4X:
mServerAddr = "robertodaniele.altervista.org"

mFTPServerUserFolder = "/sMg/"

If FirstTime Then
     FTP.Initialize("FTP", mServerAddr, 21, "robertodaniele", "curbikegko33")
End If

FTP.DownloadFile(File.Combine(mFTPServerUserFolder,"sMg_21hz133.db"), False, File.DirRootExternal, "sMg_21hz133.db")
I never used file.combine
what's utility of it?
Ps have you tried if work the above code? Tks Luca
 
Last edited:

LucaMs

Expert
Licensed User
Yes i tried and it works.

File.Combine... combines (joins-merge-link) path & filename (or path & path) and you do not need to take care of the slash or backslash

If you had:

path1 = "source/"
fileName = "/MyFile"

FullFileName = path1 & fileName - is wrong! [source//MyFile]

FullFileName = File.Combine(path1, fileName) - is correct!
 

SalentoFC

Member
Licensed User
I'll attach here the code.
the scope is:
1. Download db from server and using it insert into a record;
2. Show it on device throw sub fillscrollview2 and delete record if count > 1000
3. Upload on server db and delete local file.

error: no such table..

I've correctly created db with sqlite manager db browser and upload it on my server.

what's the problem? Why not work?
I've got a week to finish this app. Pls help as you can.
tks.
 

Attachments

LucaMs

Expert
Licensed User
The error is that you try to open the db immediately after starting the download, then the file is not Already available.

You should "wait" for the Sub FTP_DownloadCompleted event (open the db there).

B4X:
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
   Log(ServerPath & ", Success=" & Success)

   If Success Then
     Try
       SQL1.Initialize(File.DirDefaultExternal, "sMg_21hz133.db", False)
     Catch
       Log("Error opening the db")
     End Try

     FillSimpleData
     LogTable1
     Log("Number of rows = " & SQL1.ExecQuerySingleResult("SELECT count(*) FROM table1 ORDER BY Punteggio DESC"))
   Else
     Log(LastException.Message)
   End If
End Sub
 
Last edited:

SalentoFC

Member
Licensed User
I'll try (but i have an version).

Just a little question: why do you delete records if they are more than 1000 ? Can you lose data so easily? :)
This is a prove. I don't know how much is the time for the user to download the online classifice and I think that 1000 should be more than sufficient.
when i try project on my emulator b4a sub routine ftp_downloadcompleted never started after command ftp.downloadfile.. It's normal?
Now should be working? Have you try if work ok with emulator?

Ps i've thinking to use a txt file but is very complicated to ordinate each single line throw punteggio field..
 

LucaMs

Expert
Licensed User
downloadcompleted "starts" when ... download is completed (quando ha finito di scaricare :)).

No, I've not tried with emulators, but if they have access to Internet, it should work.

SQLite dbs are text file, so there is no so much "weight" difference
 

SalentoFC

Member
Licensed User
Yes I know.. but in a txt the lines are not immediatly ordinate and then I must to insert two for cicles (the scolastic for I= 0 to n-1 and into a second for j = i+1 to n for ordinate the lines.
With db is a unic command order by :)
Then I'd like to use db for a question of logic.

ps I've got edge signal connection in my housr and not know if it is the problem about downloadcompleted not started
 
Top