insert image sqlite

2020-03-08 00:10发布

i have some pictures and i want to store it in sqlite

what i need to do

2条回答
贼婆χ
2楼-- · 2020-03-08 00:35

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>
查看更多
成全新的幸福
3楼-- · 2020-03-08 00:40

There are two schools of thought

  1. Put them in a directory and then store the path in a text field
  2. Store the image data in a blob field

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.

查看更多
登录 后发表回答