Question

I am creating a sqlite database for my mobile app. once the user has supplied the correct password the database is opened. Various screens of the application will need to read and write data from the db. is there a way I can make the connection global when I open it, so it can be accessed from any view?

the code I am useing to open the DB is

var sqlConnection:SQLConnection = new SQLConnection();
                    sqlConnection.addEventListener(SQLEvent.OPEN,sqlOpenSuccess);

                    sqlConnection.open(DBFile, SQLMode.CREATE, false, 1024,null);

Thanks

JaChNo

Was it helpful?

Solution

Encapsulate your SQLConnection information into a single class; and pass a reference to that custom connection class around to every view component that needs it.

You could also look into a framework such as RobotLegs or SWIZ that uses dependency injection to add your custom connection class into views as needed.

You could also look into using a Singleton, such as the Cairngorm ModelLocator to share your custom connection instance across multiple views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top