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