在移动设备上全局访问sqlDB [英] Global access for sqlDB on mobile device
问题描述
我用来打开数据库的代码是
var sqlConnection:SQLConnection = new SQLConnection();
sqlConnection.addEventListener(SQLEvent.OPEN,sqlOpenSuccess);
sqlConnection.open(DBFile,SQLMode.CREATE,false,1024,null);
谢谢
JaChNo
将您的SQLConnection信息封装到一个类中;并将引用传递给每个需要它的视图组件的自定义连接类。
你也可以看看RobotLegs或SWIZ这样的框架,它使用依赖注入来根据需要添加自定义连接类到视图中。
你也可以使用一个单例,例如Cairngorm ModelLocator,在多个视图中共享你的自定义连接实例。
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
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.
这篇关于在移动设备上全局访问sqlDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!