1
嘿大家我一直在一个项目拍照并使用phonegap/jQuery/html5将它们存储在数据库中。数据库条目需要存储一些地理位置信息和相机拍摄的图像的BLOB。这是目前我正在使用的方法来试图做到这一点,而不是为我工作。 BLOB总是打破我的插入语句。如果我将smallImage设置为“1”而不是图像数据,则它工作正常。有没有更好的方法来插入这个blob?当我看着日志时,它看起来像是小图像被切断了。Phonegap将照片和插入图像(BLOB)到数据库SQLite
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 });
}
这里是我的错误,当我尝试输入BLOB:
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)
但我没有看到其余字段。有什么东西可以打破双引号?或者在这里发生了其他事情?
如果我把一个 “1” 在smallImage我的输出能正常工作,我得到:
INSERT INTO OrderPhotos(PhotoID, PictureFile, Longitude, Latitude, Timestamp)
VALUES(1904010821 , "1", 39.10, -84.50, 190401082)