1

I am relatively new to flex mobile environment. I'm using sqlite in flex mobile.

I have a basic app which has a welcome screen and registration.

In the welcome screen, tables are created if they dont exist in the local db (sqlite)

in welcome screen

<s:creationComplete>
  dbFile = File.applicationStorageDirectory.resolvePath("testDB.db");
  conn = new SQLConnection();
  conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);
  conn.addEventListener(SQLEvent.OPEN, openHandler);
  conn.openAsync(dbFile);
</s:creationComplete>

in scripts
    public var conn:SQLConnection;
    private var insertUser:SQLStatement;
    private var createUsersTable:SQLStatement = new SQLStatement();
    private var getUser:SQLStatement = new SQLStatement();
    public var dbFile:File;
    private function openHandler(event:SQLEvent):void {
        conn.removeEventListener(SQLEvent.OPEN, openHandler);
        conn.addEventListener(SQLEvent.BEGIN, beginHandler);
        conn.begin();
    }
    private function beginHandler(event:SQLEvent):void {
        conn.removeEventListener(SQLEvent.BEGIN, beginHandler);
        createUsersTable.sqlConnection = conn;
        createUsersTable.text ="CREATE TABLE IF NOT EXISTS users(first_name varchar(100),email VARCHAR(100))";
        createUsersTable.execute();
    }

The above works perfectly and the tables are created.

In registration screen should I have to initialize the db variables again like in s:creationComplete in welcome screen.

This is the error I get if I dont repeat and try to access the conn ( variable for SQLConnection)

TypeError: Error #1009: Cannot access a property or method of a null object reference.

But in future i will be having about 30 such screens, so should I have to repeat the code for all screen in their s:creationComplete ?

Finally I would like to easily open the db connection in other screens and do my sqlite operations.

Please correct me if im wrong or suggest better ways if any. Thank you very much

Dhiraj
  • 33,140
  • 10
  • 61
  • 78
  • Similar question has been addressed here: http://stackoverflow.com/questions/6831481/global-access-for-sqldb-on-mobile-device – SQLiteNoob Nov 13 '11 at 19:23

1 Answers1

0

I just posted a response to this today and it might help you
How to get a view to read data

I'm not sure how familiar you are with programming in general, but from what you posted above, you'll be able to figure out what's going on and pick up a few best practices (if you don't already know them =) ).

Community
  • 1
  • 1
Chaos7703
  • 691
  • 9
  • 18