2013-02-05 100 views
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) 

回答

3

你嘗試使用運營商?

db.transaction(function(tx) { 
    tx.executeSql("INSERT INTO OrderPhotos(PhotoID, PictureFile, Longitude, 
        Latitude, Timestamp) VALUES 
       (1904010821 , ? , 39.10, -84.50, 190401082)", 
    [PictureFile], 
    function(tx, res) { 
     .... 
    }); 
}); 

運營商?,比使用字符串快級聯。

你的榜樣:

db.transaction(function (tx) 
{tx.executeSql('INSERT INTO Photos(PhotoID, PictureFile, Longitude, Latitude, Timestamp) 
VALUES(?,?,?,?,?)')},[photoid, small photo, longitud, latitude, timestamp])} 

每個?對應在同一順序每個變種。

相關問題