Reputation: 307
i have some pictures and i want to store it in sqlite
what i need to do
Upvotes: 1
Views: 4357
Reputation: 31
For detail follow site: http://blog.developeronhire.com/create-sqlite-table-insert-into-sqlite-table/
<script type="text/javascript">
function createDatabase(){
try
{
if(window.openDatabase)
{
var shortName = 'db_edentiti';
var version = '1.0';
var displayName = 'Edentiti Information';
var maxSize = 65536; // in bytes
db = openDatabase(shortName, version, displayName, maxSize);
}
} catch(e) {
alert(e);
}
}
function executeQuery($query,callback){
try
{
if(window.openDatabase){
db.transaction(
function(tx){
tx.executeSql($query,[],function(tx,result){
if(typeof(callback) == "function"){
callback(result);
}else{
if(callback != undefined){
eval(callback+"(result)");
}
}
},function(tx,error){});
});
return rslt;
}
} catch(e){}
}
function createTable(){
var sql = 'drop table image';
executeQuery(sql);
var sqlC = 'CREATE TABLE image (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, image BLOB )';
executeQuery(sqlC);
}
function insertValue(){
var img = document.getElementById('image');
var sql = 'insert into image (name,image) VALUES ("sujeet","'+img+'")';
executeQuery(sql,function(results){alert(results)});
}
<input type="button" name='create' onClick="createDatabase()" value='Create Database'>
<input type="button" name='create' onClick="createTable()" value='create table'>
<input type="button" name='insert' onClick="insertValue()" value='Insert value'>
<input type="button" name='select' onClick="showTable()" value='show table'>
<input type="file" id="image" >
<div result></div>
Upvotes: 1
Reputation: 89142
There are two schools of thought
If the database is very large and the images are too, then the file system way is more performant.
If you just want something done quick, use a blob. It's ok, but doesn't scale as well.
Upvotes: 1