Global access for sqlDB on mobile device

二次信任 提交于 2020-01-06 13:13:30

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6831481/global-access-for-sqldb-on-mobile-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!