移动设备上 sqlDB 的全局访问
我正在为我的移动应用程序创建一个 sqlite 数据库。一旦用户提供了正确的密码,数据库就会打开。应用程序的各个屏幕都需要从数据库读取和写入数据。有没有一种方法可以在打开连接时将其设置为全局连接,以便可以从任何视图访问它?
我用来打开数据库的代码是
var sqlConnection:SQLConnection = new SQLConnection();
sqlConnection.addEventListener(SQLEvent.OPEN,sqlOpenSuccess);
sqlConnection.open(DBFile, SQLMode.CREATE, false, 1024,null);
谢谢
JaChNo
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 SQLConnection 信息封装到单个类中;并将对该自定义连接类的引用传递给每个需要它的视图组件。
您还可以研究 RobotLegs 或 SWIZ 等框架,它们使用依赖项注入根据需要将自定义连接类添加到视图中。
您还可以考虑使用 Singleton(例如 Cairngorm ModelLocator)来跨多个视图共享自定义连接实例。
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.