How to replace old files with new files in android sqlite database? -


i have build application in getting files , folders server (using .net web services), have class broadcast reciever in want implement method app call services check whether new version there or not , if yes replace new 1 in local sqlite database, have created... question how replace old files new 1 server local sqlite database?

edit: replace new files old in phone storage.

if understand question correctly, trying update local files on local phone storage new files retrieved web server, right??

to update files locally, gonna assume have 2 arrays of filepaths oldfilepaths , newfilepaths

i iterate , delete old ones , put new ones this:

foreach(var oldfilepath in foldfilepaths) {     var oldfilename = path.getfilename(oldfilepath);     // assumes files (old , new ones have same name).      // , saving new files in temporary folder.     var newfilepath = newfilepaths.tolist().firstordefault(f => path.getfilename(f) == oldfilename);     if (newfilepath != null)     {         file.delete(oldfilepath);         file.copy(newfilepath, oldfilepath);     } } 

now update file paths in database. assuming have unique identifier file names in database. that, like:

const string selectsqlquery = "select fileid, filepath files"; var updatesqlquery = "update files set filepath = '{0}' fileid = '{1}'";  var oldfileslist = new list<myfile>(); // assuming have object of myfile {id, filepath};  using(var connection = new sqliteconnection(connectionstring)) {     connection.open();      // reading old files database     using (var command = connection.command())     {       command.commandtext = selectsqlquery;        idatareader reader = dbcmd.executereader();        while(reader.read())         {             oldfileslist.add(new myfile { id = reader["id"], filepath = reader["filepath"] });        }     }      // updating new filepaths, assuming have newfileslist calling web service     foreach(var oldfile in oldfileslist)     {         var newfile = newfileslist.tolist().firstordefault(f => f.id == oldfile.id);         if (newfile != null)         {             using (var command = connection.createcommand())             {                 command.commandtext = string.format(updatesqlquery, newfile.id, newfile.filepath);                 command.executenonquery();             }                }     } } 

// code above in c# (monodroid) because use, , not think far java


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -