Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
New Contributor
zeno
Posts: 8
Registered: ‎03-23-2011
My Device: developer
My Carrier: developer

copy a SQLite db in JavaScript

Hello,

 

I would like to do read pre-loaded data and display it on an html page, something very simple

But how can I copy the database from the installation directory to the storage directory. The example I found is for Java.

var origDB : File = File.applicationDirectory.resolvePath("db1.sqlite" );   
var destDB
: File = File.applicationStorageDirectory.resolvePath("db1.sqlite");
  
origDB
.copyTo(destDB);

My understanding is that I have to do the above to read the sqlite db.

How can I do it in JavaScript ?

 

Thank you

 

 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<title>Database test</title>
<script type="text/javascript">
 function startapp() {

try
   {

        var origDB : File = File.applicationDirectory.resolvePath( "db.sqlite" );
   //      var destDB : File = File.applicationStorageDirectory.resolvePath("db.sqlite");
  //       origDB.copyTo(destDB);
   }
   catch ( Error )
   {
      alert ( Error );
   }

//just hardcoded the results to make sure the html file works

  var buffer = "";
  for ( var i = 0; i < 4; i++) {
   //Create a div to insert into the results
   var aDiv = document.createElement("div");

   // This part where you want to process the result and wrap it with HTML tag
   buffer += '<p>Loop iteration: ' + (i+1) + '<br />';
            buffer += 'Customer name: ' + 'current.NAME1' + '<br />';
            buffer += 'Customer address: ' + 'current.ADDRESS1' + '<br />';
            buffer += 'Customer phone: ' + 'current.PHONE</p>';
  
   aDiv.innerHTML = buffer;
  
   document.getElementById("resultContent").appendChild(aDiv);

   buffer = "";  
  }
 }
</script>
</head>

<body onload="startapp()">
 <div id="resultContent"></div>
</body>
</html>

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: copy a SQLite db in JavaScript

If you're using WebWorks, you should be asking in the Web Development forum instead.

 

If you're using AIR, you should do the copying using ActionScript3 (it's not Java... I guess that was just a typo) as you showed in your post.

 

JavaScript does not have access to the filesystem that way, as far as I know, at least not yet.  I seem to recall that even the Web Works environment doesn't expose filesystem access to you yet, though that might have changed in the most recent SDK.  (I'm not a Web Works user.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.