Note that there are some explanatory texts on larger screens.

plurals
  1. POPhonegap take photo and insert image (BLOB) into database SQLite
    text
    copied!<p>Hey everyone Ive been working on a project to take photos and store them in a database using phonegap/jQuery/html5. The database entry needs to store some geolocation information and the BLOB of the image that is taken by the camera. This is the current method I am using to try to do this and its not working out for me. The BLOB always breaks my insert statement. If I set the smallImage to "1" instead of the image data it works fine. Is there a better way to insert this blob? When I look at the log it looks like the smallImage is cut off.</p> <pre><code>var cameraLat; var cameraLong; var cameraTimestamp; var destinationType; var cameraLocationID; function onGeoSuccess(position) { cameraLat = position.coords.latitude; console.log(cameraLat); cameraLong = position.coords.longitude; console.log(cameraLong); cameraTimestamp = position.timestamp; console.log(cameraTimestamp); } function geoFail(position) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } function onPhotoDataSuccess(imageData) { // Get image handle navigator.geolocation.getCurrentPosition(onGeoSuccess, geoFail); var smallImage = imageData; var Latitude = cameraLat; var longitude = cameraLong; var timestamp = cameraTimestamp; var LID = cameraLocationID; console.log(Latitude); //working console.log(longitude); //working console.log(timestamp); //working console.log(smallImage); // This cuts out and breaks my insert. var db = window.openDatabase("MobilePhotos", "1.0", "MobilePhotosData", 1000000); db.transaction(function (tx) {tx.executeSql('INSERT INTO Photos(PhotoID, PictureFile, Longitude, Latitude, Timestamp ) VALUES( '+ timestamp+LID+' ,' + smallImage + '", ' + longitude +', '+ Latitude +', "'+ timestamp +'")')}) } function take_pic(LocationID) { cameraLocationID=LocationID; navigator.camera.getPicture(onPhotoDataSuccess, function(ex) {alert("Camera Error!");}, { quality : 50, destinationType: Camera.DestinationType.DATA_URL }); } </code></pre> <p>Here is the error I get when I try to input the BLOB:</p> <pre><code>02-05 16:10:19.702: W/System.err(12028): android.database.sqlite.SQLiteException: no such column: undefined (code 1): , while compiling: INSERT INTO OrderPhotos(PhotoID, PictureFile, Longitude, Latitude, Timestamp ) VALUES( 1904010821 , "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABsS..(3825 characters) </code></pre> <p>But I don't see the rest of the fields. Could something be breaking the double quotes? Or is something else happening here? </p> <p>If I put a "1" in for smallImage my output works fine I get:</p> <pre><code>INSERT INTO OrderPhotos(PhotoID, PictureFile, Longitude, Latitude, Timestamp ) VALUES( 1904010821 , "1", 39.10, -84.50, 190401082) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload