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

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

问题描述

我正在为我的移动应用程序创建一个sqlite数据库。一旦用户提供了正确的密码,数据库就会被打开。应用程序的各种屏幕将需要从数据库中读取和写入数据。有什么办法可以使我的连接全球打开它,所以它可以从任何视图访问?



我用来打开数据库的代码是

  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屋!

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