SqLite database persistence on mobile air application

Hi, I'm Fabio from Italy. I'm developing a flex mobile application running on iPad, that application stores user settings in a local sqlite database on documentsDirectory. I've noticed that folder is destroyed and recreated each time the application is updated, and this is not good for user data . Is there any way to store that database in a folder that's NOT involved in the application uninstall/update procedure?
Thank to all!

You can't write anything to the applicationDirectory.
Use File.applicationStorageDirectory instead
Also you get path and do not wrtite to it anyting
var jpgEncoder:JPGEncoder = new JPGEncoder(90);
var byteArray:ByteArray = jpgEncoder.encode( bitmapData );
// set an filename
var filename:String = "cool-wallpaper.jpg";
// get current path
var file:File = File.applicationDirectory.resolvePath( filename );
// get the native path
var wr:File = new File( file.nativePath );
// create filestream
var stream:FileStream = new FileStream();
//  open/create the file, set the filemode to write; because we are going to save
stream.open( wr , FileMode.WRITE);
// write your byteArray into the file.
stream.writeBytes ( byteArray, 0, byteArray.length );
// close the file. That’s it.
stream.close();
Try to use:
// get current path
var file:File = File.applicationDocumentsDirectory.resolvePath( filename );
//  open/create the file, set the filemode to write; because we are going to save
stream.open( file , FileMode.WRITE);

Similar Messages

  • Including sqlite database in a windows air installer

    I am trying to create a cross platform air installer that uses a sqlite database.
    This is the code I use to copy the database from the installer to the users application directory:
    var dataFile:File = File.applicationDirectory.resolvePath("data/myDataStorage.db");
    var dataUserFile:File = File.documentsDirectory.resolvePath("myDataStorage.db");
    When using the database I access it here:
    var file:File = File.documentsDirectory.resolvePath("myDataStorage.db");
    This works great on a mac.  On a PC it does not work.  Can anyone recommend a resource or give me a tip or two?
    Thanks

    I have been looking into this problem.  It turns out that it is not just a Windows problem it also happens on a Mac.  Here is what is happening:
    I am trying to copy a sqlite .db from the read only application directory to the users documents directory.
    First I setup these vars:
        var dbFile:File =  File.applicationDirectory.resolvePath("db/myDataStorage.db");
         var dbWorkedFile:File =  File.documentsDirectory.resolvePath("myDataStorage.db");
    If I do this it works:
    dbFile.copyTo(dbWorkedFile, true);  //If I set the overwrite param to 'true' then it works.
    If I use this code:
    dbFile.copyTo(dbWorkedFile);
    or
    dbFile.copyTo(dbWorkedFile, false);
    I get the following error:
    Error #3012: Cannot delete file or directory.
        at flash.filesystem::File/copyTo()
    The funny thing is that I the destination documents directory will get a 4k blank file when the error occurs.  In addition if I try the same copy code on an image I get the same error but the whole image does get copied.
    In the end I want my code to do something like the following so that it copies the database over only if it does not exist.  If I run this code now I get a 4k .db file and a 3012 error.  Any ideas?
    public function copyDB():void
                    var dbFile:File = File.applicationDirectory.resolvePath("db/myDataStorage.db");
                    var dbWorkedFile:File = File.documentsDirectory.resolvePath("myDataStorage.db");
                    if(!dbWorkedFile.exists){
                        trace("db Does Not Exist");
                        dbFile.copyTo(dbWorkedFile);
                    } else { 
                        trace("db Exists so do nothing"); 
                    dbConn = new SQLConnection(); 
                    dbConn.openAsync(dbWorkedFile); 

  • Voice recognition support in mobile air application developed using Flash CS5.5

    I want to develop an android application via Flash CS5.5 which takes the command based on voice or convert voice in to text. Voice recognition support is available in android SDK but it is not available in latest Air SDK.
    I tried on Google to find out how to develop Voice recognition mobile application in Flash CS5.5 but did not find anything. There is some example/video which shows hack around native android code but this is for Flex not for the Flash.
    Waiting response?
    Thanks
    RTY

    Hi Rty,
    I think you should use  a native extension.
    Have a look at this link:
    http://extensionsforair.com/extensions/speech-recognition/

  • Distribute SQLite-DB with AIR Application?

    Hi!
    Is it possible to distribute an SQLite-DB along with an AIR
    Application? By distribute I mean passing along a premade database
    instead of creating it with code at application startup. Don't want
    to run alot of CREATE TABLE and such at startup, even if it should
    only occur once.
    Thanks!

    I just discovered this developer's github page yesterday and perhaps his air_amf_sync project may be beneficial to you.
    https://github.com/dima/air_amf_sync
    Let us know on your outcome.

  • SQLite error #3115 in Flex/Air App: with (')

    Hi,
    I am trying to do a simple SQLite query from inside and Air application:
    var sqls:SQLStatement = new SQLStatement();
    sqls.sqlConnection = sqlc;
    sqls.text = "UPDATE videos SET thumb = 'ram's' where id = 2";
    sqls.execute();
    I need to add ' same as ram's
    Error:
    SQLError: 'Error #3115: SQL Error.', details:'near 's': syntax error', operation:'execute', detailID:'2003'
    I'm using "addslashes()" but not working
    Not sure why it does not work. Please help me.
    Thanks,
    Dhaval

    The syntax for the update is incorrect, you can use the update statement as
    sqls.text = "UPDATE videos SET thumb = 'ram' + '''s' where id = 2";
    Let me know if this worked.

  • How to save the date in Sqlite in Adobe Air application

    hi friends,
    i am doing a flex Adobe AIR Application with SQLITE Data base,in that i want to save Date in the following format DD/MM/YYYY, but in my TABLE i gave the data type is DATE,
    So it store the value like this Sun Dec 2 00:00:00 GMT+0530 2012.i want to store the value in DD/MM/YYYY.How to do that?
    looking for useful suggession.
    Cheers,
    B.venkatesan.

    Hi, maybe cannot help much on this since I have not much experiense on handling SQLITE in AIR.
    But I know there are a command/example for reading SQL:
    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/data/SQLConnectio n.html
    http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d49.html
    And in mxml you should have an id for each individual TextInput component, also have a button:
    <Button click="updateSQLHandler(event)"/>
    When the button is click the handler function is launched.
    The updateSQLHandler(event:MouseEvent) is a script that read the each individual TextInput component by getting (id of textinput component).text.
    Then, you create a String varible that is an SQL commands with the texts in the form, and update the SQL database following the below using the execute() command (refer to http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d49.html ).
    Hope this help.

  • How to connect to and communicate with an SQLite database in AIR/Flex

    Hey guys,
    I recently decided I would try programming a vocabulary-training program in AIR, so I could use it on Linux as well. I got stuck pretty soon. I am trying to connect to a local SQLite database and I obviously fail epically. Posting the source code of the application here:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
       <mx:Script>
          <![CDATA[  
               import flash.filesystem.File;
              import flash.data.*;
             import mx.controls.Alert; 
                      private var dbFile:File;
                   private var conn:SQLConnection;
                   // -- AUTO INIT FUNCTIONS --------------------------------------------------- /
                   private function init():void {
                        // Create a File Reference to the Included DB
                        dbFile = File.applicationDirectory.resolvePath( "../slovniky.db" );
                        // Create SQL Connection
                        conn = new SQLConnection();
                        // Event Listener that will tell us when the DB is opened
                        conn.addEventListener(SQLEvent.OPEN, openSuccess);
                        // Event Listener that will tell us if an error occurs
                        conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
                   // -- EVENT HANDLERS -------------------------------------------------------- /
             private function starter() :void {
                  slovickoEn.enabled = true;
                  nazor.enabled = true;
                  odeslat.enabled = true;
                  zrusit.enabled = true;
                  start.enabled = false;
                  // Otevírám spojení s databází v asynchroním módu
                   conn.openAsync( dbFile );
             private function openSuccess( event:SQLEvent ):void {
                        // Pokud se spojení povede!
                        Alert.show("Spojení se zdařilo!");
               private function openFailure( event:SQLEvent ):void {
                        // Pokud spojení selže!
                        Alert.show("Spojení se nezdařilo!")
             private function kontrola() : void {
                  if (nazor.text != "") {
                       if (nazor.text == "Pes") {
                       Alert.show("Správně!");    
                       else {
                       Alert.show("Špatně!! " + "Napsané slovíčko bylo " + nazor.text);     
          ]]>   
       </mx:Script>
       <mx:VBox width="400" height="200"
                   horizontalCenter="0" verticalCenter="0" backgroundColor="#FFFFFF"
                   paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20"
       >
          <mx:HBox width="100%" verticalAlign="middle" horizontalAlign="center">
             <mx:Label text="Anglicky:"/>
             <mx:TextInput id="slovickoEn" editable="false" text="Dog" enabled="false"/>
          </mx:HBox>
          <mx:HBox width="100%" verticalAlign="middle" horizontalAlign="center">
             <mx:Label text="Česky:"/>
             <mx:TextInput id="nazor"  enter="kontrola()" enabled="false"/>
          </mx:HBox>
          <mx:HBox width="100%" horizontalAlign="center">
             <mx:Spacer width="50" height="10"/>
             <mx:Button id="odeslat" label="Odeslat" color="#0D8401" click="kontrola()" enabled="false"/>
             <mx:Button id="zrusit" label="Zrušit" color="#0D8401" enabled="false"/>
          </mx:HBox>
          <mx:HBox width="100%" horizontalAlign="center">
             <mx:Spacer width="50" height="10"/>
             <mx:Button id="start" label="Start" color="#0D8401" click="starter()" enabled="true"/>
          </mx:HBox>
       </mx:VBox>
    </mx:WindowedApplication>
    The Run of the program tells me this:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
         at pes/starter()[C:\air\projects\pes\src\pes.mxml:45]
         at pes/__start_click()[C:\air\projects\pes\src\pes.mxml:93]
    I would appreciate any help or a how-to. I am an absolute beginner with some experience from HTML, CSS, PHP and rarely JS. What am I doing wrong? File attached for easier manipulation as well.
    Erthy

    Hi,
    Here is the complete example for the same with the code.Let me know if you have any issue with this.
    http://shardulbartwal.wordpress.com/2008/04/14/adobe-air-and-sqlite-connectivity/
    with Regards,
    Shardul Singh Bartwal

  • How to embed SQLite database to Air app?

    Now I connect to a database file like this:
    var dbFile:File = File.applicationStorageDirectory.resolvePath("myDB.db");
    conn = new SQLConnection();
    conn.openAsync(dbFile);
    conn.addEventListener(SQLEvent.OPEN, openSuccess);
    conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
    Tell me please, how do I embed the DB file to the application? I need to have the database inside a swf.

    Here's info on encrypting a database in AIR:
    Creating an encrypted database
    Working with the encrypted local SQLite database
    flash.data.SQLConnection
    Chris

  • How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    If the data is on a remote server (for example, PHP running on a web server, talking to a MySQL server) then you do this in an AIR application the same way you would do it with any Flex application (or ajax application, if you're building your AIR app in HTML/JS).
    That's a broad answer, but in fact there are lots of ways to communicate between Flex and PHP. The most common and best in most cases is to use AMFPHP (http://amfphp.org/) or the new ZEND AMF support in the Zend Framework.
    This page is a good starting point for learning about Flex and PHP communication:
    http://www.adobe.com/devnet/flex/flex_php.html
    Also, in Flash Builder 4 they've added a lot of remote-data-connection functionality, including a lot that's designed for PHP. Take a look at the Flash Builder 4 public beta for more on that: http://labs.adobe.com/technologies/flashbuilder4/

  • Right way to code an AIR application that uses sqllite database

    I am developing an AIR application that uses sqllite database.I want to know the correct way in which I should create the connections and SQLstatements according to MVC pattern.For example,whether i should have a single SQLStatement object for all my sql operations or I should use separate objects for insert,delete,select etc.I know how to open connection,execute statements and all,but i want to know the professional way of writing it.

    Make a controller for connect to db and save the connection in global varible (in model). Use this connection variable whenever u wanna execute the sql statements. Create seperate dao's for each table. Queries should be executed under the daos. You can call the method under the dao for execute the query from controller and show the result in view.

  • Using database views in ADF mobile client application

    Hi,
    I am using Jdeveloper 11.1.1.4 and WLS 10.3.4.
    I have developed a POC in ADF mobile client application both with and without synchronization. However, both work with entity objects based on tables.
    I need to use database views instead of tables. When I try to include entity object (based on views) in the view object, it shows an error saying "Only the entity objects based on tables can be selected"
    Please guide me if there is a work around for this.
    Also, please let me know if there is way to develop an ADF mobile client application skipping the use of entity objects at all and using view objects directly to specify the database query and fetch data from the database.
    Thanks in advance.
    Ansh
    Edited by: ansh on Mar 28, 2011 5:40 AM

    Hi, Ansh:
    Currently, out of box, ADF Mobile Client does not support synchronization against Database Views. This is because Mobile Server imposes some schema restrictions to ensure synchronization with multi-table views would work correctly. This schema restriction requires, for example, the view must have a primary parent table with key defined, and also all base table must be included in the data publication. These dependencies requires manual resolution and advanced planning, and is managed outside of the ADF Mobile Client/JDeveloper project.
    To continue development, you would need to create server Entity Objects directly against the base tables. You can then create the mobile ADF Business Component (EOs, VOs, etc). You can then create View Objects in your ADF Mobile Client application based on the database views, in order to retrieve the data you need exactly. In other words, instead of basing EO on the database view, create View Objects in the mobile applicaiton to mimic what you had in the View Object.
    Is there any other reason why you would need to access data via database views, instead of directly against base tables?
    Thanks,
    Joe Huang

  • For Update framework of AIR Application,I want preserve databases value when i update lates download

    for Update framework of AIR Application, I want preserve databases when i update lates download ,Right now when i ta
    ke latest from server it will remove my database  value and i i want ot preserve my database value.
    Please any one can guide me in this?

    Ya it is in Application directory...
    in windows  :: D:\FlexWorkSpaceSVN\YSIPrototype\bin-debug\data\YSIDB.db
    Thanks
    Sunil

  • Air application (not for mobile) ?

    Hi
    How do we proceed to create a Air application (not for mobile) that works with Zend Server? "Flex and Php project" creates a web based application, isn't it?
    Thanks

    I have the same question.
    Is possible to debug the PHP side of an AIR application?
    Because for Web and Mobile applications there is an extra option for debugging ("Web (PHP) Application" and "Mobile (PHP) Application") but there isn't any option like that in Desktop Application.
    If is not possible with Flash Builder, does somebody know a workaround for debugging PHP in AIR apps?

  • AIR application and database connectivity (using JAVA)

    Hi
    I am creating AIR application and I want to connect with the database using java database connectivity (JDBC).
    Can any body give me the some suggestion on how to how to do that.
    Please give me any reference for creating AIR application for database connectivity with mysql/access.
    Thanks
    Sameer

    lots of serching on the google and found that For AIR applications either you use Webservices(JAVA/PHP/.Net) or you can use SQLLite.
    Not found any method for direct connectivity with the database using JDBC.
    If any one found direct connecivity withe database using JAVA then please reply.
    Thanks

  • Adobe Air application with Oracle??

    Hi there,
    I am a newbee on this forum as well as for developing Adobe
    Air applications. Can any one tell me whether i can use oracle as
    database for adobe air apps or not. What about SQL Server instead
    of SQLite.
    Thanx in advance. Awaiting for your quick & favourable
    reply.
    Regards,
    Harish

    You can use java and servlets to talk to the database. If you
    have your servlet setup, just have it output xml and your flex can
    process the results:
    <mx:HTTPService id="dbService" useProxy="false"
    method="GET" result="processResults" url="{servletURL}"/>
    Then you call something like this in Actionscript:
    private function init():void {
    var s:String = 'args';
    var params:Object = {};
    params[s] = s;
    params["password"] = password;
    params["user"] = user;
    dbService.send(params);
    You can then handle the results in a method:
    private function processResults(event:ResultEvent):void { }
    or access them directly in an object via
    dbService.lastResult.
    Hope that helps. It would take a lot of time to explain it
    more in depth and there are certainly other ways to accomplish
    this.

Maybe you are looking for