我正在使用这段代码来插入和选择数据库中的文本。如何为图像而不是文本实现此功能。我已经完成了我的远程谷歌(ing)我无法找到任何帮助。
var index_count = 0
var up_check = 0
function get_db(a, up_check) {
var db = LocalStorage.openDatabaseSync("DB5", "1.0", "The Example QML SQL!", 1000000);
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
for ( var z=0; z<1000; z++){
tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'Movie', z ]);
}
var rs = tx.executeSql('SELECT * FROM Greeting');
var r = ""
for(var i = 0; i < a; i++) {
if (i>index_count-1 && up_check ===0)
r += rs.rows.item(i).salutation + ": " + rs.rows.item(i).salutee + "\t\t"
if (up_check === 1){
var size_check =0
if (i >index_count-11 && size_check !==9) {
r += rs.rows.item(i).salutation + ": " + rs.rows.item(i).salutee + "\t\t"
size_check++
}
}
}
console.log(r);
index_count=a;
return r;
})}
答案 0 :(得分:1)
您需要将路径作为值传递给图像文件,以便存储图像。你的表格示例:
create table testblob (
image_id tinyint(3) not null default '0',
image blob not null
);
DB命令将是:
INSERT INTO testblob (ID,IMAGE) VALUES(1,LOAD_FILE('D:/test.txt'));
使用Javascript:
ImagePath_from_MyForm = 'C:\temp\test.jpg'
tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ z, ImagePath_from_MyForm ]);