移动设备上 sqlDB 的全局访问 [英] Global access for sqlDB on mobile device

查看:22
本文介绍了移动设备上 sqlDB 的全局访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的移动应用创建一个 sqlite 数据库.一旦用户提供了正确的密码,就会打开数据库.应用程序的各个屏幕都需要从数据库读取和写入数据.有没有办法在打开连接时将其设为全局连接,以便可以从任何视图访问它?

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);

谢谢

JaChNo

推荐答案

将您的 SQLConnection 信息封装到单个类中;并将对该自定义连接类的引用传递给需要它的每个视图组件.

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.

您还可以研究一个框架,例如 RobotLegs 或 SWIZ,它们使用依赖注入将您的自定义连接类添加到需要的视图中.

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.

您还可以考虑使用单例(例如 Cairngorm ModelLocator)在多个视图之间共享您的自定义连接实例.

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

这篇关于移动设备上 sqlDB 的全局访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆