Page 1 of 1

Unable to FTP an sqlite file, even tho it's closed.

Posted: Wed Aug 14, 2013 10:44 am
by paulsr
Greetings:

I have an app running in LC 6.1.1(rc2) on XP which seems to be unable to copy an sqlite database which has been used in the app, even tho it has been closed.

The following code is a snippet I've been using for testing

Code: Select all

revCloseDatabase gDBid --closes newsapp.sqlite
   
put "binfile:" & g_sfp_docs & "/airnews/sqlite/test.sqlite" into tTestDB  
put g_ftp_sqlite & "test.copy" into g_ftp_sqlulpath

--copies test.sqlite to test.copy on server
put url tTestDB into url g_ftp_sqlulpath 
   
put "binfile:" & g_sfp_docs & "/airnews/sqlite/newsapp.sqlite" into tRealDB   
put g_ftp_sqlite & "newsapp.copy" into g_ftp_sqlulpath

--creates empty file newsapp.copy on server
put url tRealDB into url g_ftp_sqlulpath 

The var g_sfp_docs is my local /Documents directory.

The var g_ftp_sqlulpath contains all the ftp info, my username, password, path, etc., and must be correct, because...

The first test, copying a file called test.sqlite to the server works just fine.

The second test, an attempt to copy newsapp.sqlite fails. It logs into the correct path and creates an empty file, but does not upload.

newsapp.sqlite _was_ open in the app, but the revCloseDatabase does close it. I've tried to access it after the close, and correctly get an error.

Can anyone plz explain to me how to FTP a database that has been used but is now closed... Or, can you see an error in my code?

Many thanks...

--paul

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Wed Aug 14, 2013 11:48 am
by Dixie
Paul...

An example of sending a file to the public_html folder on your server...

Code: Select all

constant FTPHOST = "ftp.someserver.com"
constant FTPUSER = "someuser"
constant FTPPASS = "987654321"

on mouseUp
    # Start by getting the file to upload
    local tFileForUpload, tFileName
    answer file "Select a file to upload"
    put it into tFileForUpload
    
    # Get the name of the file for upload
    set the itemdel to "/"
    put the last item of tFileForUpload into tFileName
    put empty into field 1
    
    # Connect the start the upload
    local tDestination
    put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST & "/public_html/" & tFileName into tDestination
    libURLSetStatusCallback "uploadProgress", the long ID of me
    libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
end mouseUp

on uploadComplete pURL, pStatus
    put "Status Update:" && pStatus && return after field 1
end uploadComplete

on uploadProgress pURL, pStatus
    put "Status Update:" && pStatus && return before field 1
end uploadProgress

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Wed Aug 14, 2013 12:01 pm
by paulsr
Thanks Dixie,

I did try using libURLftpUploadFile but it didn't make any difference.

If my code is wrong, which I'm happy to accept, then why does the first upload work? i.e. the file that has not been opened by my code.

--paul

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Mon Aug 19, 2013 12:52 am
by Simon
Hi Paul,
Have you proved that this has to do with you opening the DB?
What happens if you don't open either of them does it work? (you didn't mention this)

Simon

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Mon Aug 19, 2013 8:00 am
by paulsr
Simon wrote:Hi Paul,
Have you proved that this has to do with you opening the DB?
What happens if you don't open either of them does it work? (you didn't mention this)
Simon
Yes Simon, it is related to opening the DB.

I think tho I am somehow managing to open the same DB more than once, but only closing it one time. So, it is in fact open and can not be copied.

I discovered with my test code I could not even make a copy on my own PC, so it had nothing to do with FTP.

Clearly I have a bug, but I'm not yet sure where!

--paul

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Mon Aug 19, 2013 8:14 am
by Simon
Have you used revOpenDatabases()

Simon

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Mon Aug 19, 2013 9:38 am
by paulsr
Simon wrote:Have you used revOpenDatabases()

Simon
Yes, but I think it's getting executed more than once. Am in bug-hunting mode :-)

--paul

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Mon Aug 19, 2013 9:51 am
by Simon
Note the "s"
revOpenDatabases()
Will tell you if any are still open.

Simon

Re: Unable to FTP an sqlite file, even tho it's closed.

Posted: Mon Aug 19, 2013 11:04 am
by paulsr
Oh! Sorry. I thought the 's' was a typo!

Useful. Thanks,

--paul