移动设备上 sqlDB 的全局访问

发布于 2024-11-26 13:17:07 字数 411 浏览 2 评论 0原文

我正在为我的移动应用程序创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⊕婉儿 2024-12-03 13:17:07

将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文