Page 1 of 1

FileTransfer can not store data into SQLite

Posted: Mon Dec 23, 2013 5:05 pm
by Ivan6481911

Hello. I can not store data into data base.

  1. //INSERT NEW in POI - works

  2. // VIDEO - works

  3. // AUDIO - not working

    The difference is the 1 and 3 SQL queries are called not in FileTransfer.

    In AUDIO, consol stop showing on console.log('fileName: ' + value.audiofilename); - this is right before SQL query. Everything works, when there is no SQL query. Are there any limitations or smt? Please, tell me how can I store data in DB in fileTransfer.
    Thanks!

    Here is my code:

    function downloadMedia() {
    console.log('downloadMedia()');
    db.transaction(function(tx) {
    var isUpToDateBool = localStorage.getItem('isUpToDate');
    if (isUpToDateBool == "true") {
    //alert("poi isUpToDate == true");
    } else {
    //alert("poi isUpToDate == false");

    Code: Select all

         //INSERT NEW in POI 
         tx.executeSql('INSERT INTO "poi" (id, nid, title, body, created, changed, latitude, longitude, createdAt, updatedAt) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [value.nid, value.title, value.body, value.created, value.changed, value.latitude, value.longitude, Date.now(), Date.now()]); 
    
         // AUDIO 
         if (value.audiopath) { 
             console.log('audio'); 
             try { 
                 //download audio 
                 var fileTransfer = new FileTransfer(); 
                 var pathStr = value.audiopath; 
                 var encodedUri = encodeURI(pathStr); 
    
                 var filePath = window.rootFS.fullPath + "/" + value.audiofilename; 
                 console.log('fullPath in audio: ' + filePath); 
    
                 fileTransfer.download( 
                     encodedUri, 
                     filePath, 
    
                     function(entry) { 
    
                         console.log('nid: ' + value.nid); 
                         console.log('UrlPath: ' + value.audiopath); 
                         console.log('filePath: ' + filePath); 
                         console.log('entry fullpath: ' + entry.fullPath); 
                         console.log('fileName: ' + value.audiofilename); 
    
                         tx.executeSql('INSERT INTO "poi_media" ( nid, type, UrlPath, filePath, fileName ) VALUES ( ?, ?, ?, ?, ? )', [value.nid, "audio", value.audiopath, filePath, value.audiofilename]); 
                         console.log("audio download complete into entry.fullPath: " + entry.fullPath); 
                         console.log("audio download complete into filePath: " + filePath); 
    
                     }, 
    
                     function(error) { 
                         console.log("download error source " + error.source); 
                         console.log("download error target " + error.target); 
                         console.log("upload error code" + error.code); 
                     }); 
             } catch (e) { 
    
                 // test only 
                 console.log('audio download exception: ' + e.message); 
                 tx.executeSql('INSERT INTO "poi_media" ( nid, type, UrlPath, filePath, fileName ) VALUES ( ?, ?, ?, ?, ? )', [value.nid, "audio", value.audiopath, value.audiopath, value.audiofilename]); 
                 console.log("2 audio download complete into entry.fullPath: " + value.audiopath); 
             } 
    
         } // end if 
    
         // VIDEO 
         if (value.youtubevideo) { 
             console.log('video'); 
             tx.executeSql('INSERT INTO "poi_media" ( nid, type, UrlPath, filePath, fileName ) VALUES ( ?, ?, ?, NULL, NULL )', [value.nid, "video", value.youtubevideo]); 
             //console.log("videoUrl: " + value.youtubevideo); 
         } // end if 
     } 

});
}


FileTransfer can not store data into SQLite

Posted: Mon Dec 23, 2013 7:22 pm
by Maryna Brodina

Hello! Please check are there any errors in console?


FileTransfer can not store data into SQLite

Posted: Tue Dec 24, 2013 10:01 am
by Ivan6481911

I found the solution, but I am not sure it is correct.
Everything works, when I make each query within transaction.

db.transaction(function(tx) {
tx.executeSql('INSERT INTO "poi_media" ( nid, type, UrlPath, filePath, fileName ) VALUES ( ?, ?, ?, ?, ? )', [value.nid, "audio", value.audiopath, filePath, value.audiofilename]);
});

What can you say?


FileTransfer can not store data into SQLite

Posted: Tue Dec 24, 2013 10:34 am
by Kateryna Grynko

Hi Ivan,

If it works for you - that's OK.