3 Replies Latest reply on Aug 3, 2008 9:46 PM by anirudhs

    inserting and retrieving images from db

      Hi all,
      Is there a specified format for retrieving and inserting images into sqlite using air. I have made connections to sqlite. It returned successful. Here is my code except;

      <script language="javascript" type="text/javascript">
      var insertStmt = new air.SQLStatement();
      var selectImg = new air.SQLStatement();
      //var data = new ByteArray();
      var img;
      var imgSelected;
      function uploadImage() {
      try {
      img = document.getElementById("upload").value;
      var imgfile = new air.File(img);
      var filepath = imgfile.url;
      insertStmt.sqlConnection = conn;
      // the SQL query
      insertStmt.text = "INSERT into adverts (banner) VALUES (\"" + img + "\")";
      // register listeners for the result and failure (status) events
      insertStmt.addEventListener(air.SQLEvent.RESULT, insertResult);
      insertStmt.addEventListener(air.SQLErrorEvent.ERROR, insertError);
      }catch(e) {
      function insertResult(event) {
      alert("a new record has been inserted" );
      function insertError(event) {
      alert("records unsuccessful" + event.error.details + event.error.message);

      function downloadImg() {
      //imgSelected = document.getElementById("dbimg").value;
      selectImg.sqlConnection = conn;
      selectImg.text = "select stage_name, pix from artiste WHERE pix = ? and stage_name = 'dbanj'";
      selectImg.addEventListener(air.SQLEvent.RESULT, resultHandler);
      selectImg.addEventListener(air.SQLErrorEvent.ERROR, errorHandler);
      selectImg.parameters[0] = resultHandler(event);
      //selectImg.parameters[1] = document.getElementById("dbimg").value;
      function resultHandler(event) {
      var result = selectImg.getResult();
      if(result == null)
      alert("result:" + " "+ result);
      var colResults = result.data;
      //if(colResults == "undefined")
      alert("colResults:"+ " "+ colResults);
      for (i = 0; i < colResults; i++) {
      var row = result.data ;
      var output = "banner: " + row.banner;
      function errorHandler(event) {
      alert("the image was not retrieved" + event.error.details +" "+ event.error.message);

      //then the HTML code

      <table width="591" border="0" cellpadding="0" cellspacing="0">
      <td width="60" height="28"> </td>
      <td width="351"> </td>
      <td width="99"> </td>
      <td width="81"> </td>
      <td height="45"> </td>
      <td colspan="2" valign="top"><form id="form1" name="upload" enctype="multipart/form-data" method="post" action="#">
      <label>Image upload
      <input type="file" name="upload" id="upload"/>
      <input name="upload" type="submit" value="Upload" onclick="uploadImage()" />
      <td> </td>
      <td height="24"> </td>
      <td rowspan="2" valign="top"><div id="dbimg">
      <script language="javascript">
      <td valign="top"><input type="submit" name="dnbtn" id="dnbtn" value="download" onclick="downloadImg()" /></td>
      <td> </td>

      I want to know if there are any special way of doing this