实例介绍
【实例简介】
aSQLiteManager是一款适用于Android平台的SQLite 管理器。SQLite是一个软件库,用于实现自包含、非服务式、零配置、事务化的SQL数据库引擎。
SQLite是一个嵌入式SQL数据库引擎,与其它大多数SQL数据库不同的是,SQLite没有独立的服务进程。SQLite直接读写原始的磁盘文件,一个拥有多个表、索引、触发器和视图的完整SQL数据库就包含在一个独立的磁盘文件中。数据库文件的格式是跨平台的,你可以在32位和64位系统之间、甚至在Big-Endian和Little-Endian(译者注:这是两种不同的字节排序方式,Big-Endian是指一个word中的高位Byte是放在内存word区域的低地址处,而Little-Endian则与之相反)两种不同的架构间自由地拷贝数据库,这一特性让SQLite成为应用文件格式的一种流行选择。SQLite不能替代Oracle,但可以考虑作为fopen()的替代方法。
SQLite已经是世界上布署得最广泛的SQL数据库引擎,被用在无以计数的桌面电脑应用中,还有消费电子设备中,如移动电话、掌上电脑和MP3播放器等。SQLite的源码就放在公有领域(即WikiPedia的public domain)中。
该应用主要功能:
- 支持打开来自aSQLiteManager和其它文件管理器的数据库。(包括OI File Manager,Adao Teams File Manager,以及 Simplest File Manager )。
- 列出表单,视图,和索引。
- 显示表单和视图的数据单元格的内容可以拷贝到剪贴板上执行'Drop' / 'Create' SQL语句。
- 将所有可执行语句存储在开放式的数据库里(在一个称为aSQLiteManager的表单)
- 从查询表格中可以查询SQL历史记录。
- 开始事务,提交和回滚。
- 导出数据库的SQL脚本,支持脚本的数据库恢复。
- 导出为ASCII文件的查询结果。
- 开放式的数据库,无需重置配置。
- 执行SQL脚本,全脚本或单行脚本。
- 良好的排错功能。
- 支持编辑按钮来编辑数据表单表浏览器。
- 通过数据浏览器中的标题栏按钮来添加数据项。
- SQLite的数据录入过程中不validata数据类型。
新版本可能提供的功能:
- 通过点击标题可以对数据和查询结果进行分类。
- 支持对数据项进行更好的验证。
- 嵌入SQLites . 命令。
- 嵌入BLOBS字段。
- 支持脚本的编译器。
【实例截图】
【核心代码】
/** * Part of aSQLiteManager (http://sourceforge.net/projects/asqlitemanager/) * a a SQLite Manager by andsen (http://sourceforge.net/users/andsen) * * The mail class of the aSQLiteManager * * @author andsen * */ package dk.andsen.asqlitemanager; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import dk.andsen.utils.NewFilePicker; import dk.andsen.utils.Utils; public class aSQLiteManager extends Activity implements OnClickListener { /** * True to enable functions under test */ private static final int MENU_OPT = 1; private static final int MENU_HLP = 2; private static final int MENU_RESET = 3; final String WelcomeId = "ShowWelcome2.0b"; private Context _cont; private String _recentFiles; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button open = (Button) this.findViewById(R.id.Open); open.setOnClickListener(this); Button about = (Button) this.findViewById(R.id.About); about.setOnClickListener(this); Button newDatabase = (Button) this.findViewById(R.id.NewDB); newDatabase.setOnClickListener(this); Button recently = (Button) this.findViewById(R.id.Recently); recently.setOnClickListener(this); TextView tv = (TextView) this.findViewById(R.id.Version); tv.setText(getText(R.string.Version) " " getText(R.string.VersionNo)); _cont = this; final SharedPreferences settings = getSharedPreferences("aSQLiteManager", MODE_PRIVATE); // Show welcome screen if not disabled //TODO change how the welcome screen is displayed. Store version no in // in "VersionNo" and show welcome if versionNo has changed if(settings.getBoolean(WelcomeId, true)) { final Dialog dial = new Dialog(this); dial.setContentView(R.layout.welcome); dial.setTitle(R.string.Welcome); Button _btOK = (Button)dial.findViewById(R.id.OK); _btOK.setOnClickListener(new OnClickListener() { public void onClick(View v) { CheckBox _remember = (CheckBox) dial.findViewById(R.id.ShowAtStartUp); android.content.SharedPreferences.Editor edt = settings.edit(); edt.putBoolean(WelcomeId, _remember.isChecked()); edt.commit(); dial.hide(); } }); dial.show(); } } /* (non-Javadoc) * @see android.view.View.OnClickListener#onClick(android.view.View) */ public void onClick(View v) { int key = v.getId(); if (key == R.id.Open) { Intent i = new Intent(this, NewFilePicker.class); Utils.logD("Calling NewFilepicker"); // Utils.logD("Calling NewFilepicker for result"); // startActivityForResult(i, 1); startActivity(i); } else if (key == R.id.About) { showAboutDialog(); } else if (key == R.id.NewDB) { Utils.logD("Create new database"); newDatabase(); } else if (key == R.id.Recently) { // Retrieve recently opened files SharedPreferences settings = getSharedPreferences("aSQLiteManager", MODE_PRIVATE); _recentFiles = settings.getString("Recently", null); if (_recentFiles == null) { Utils.showMessage("Recently files: ", _recentFiles, _cont); } else { String[] resently = _recentFiles.split(";"); Utils.logD(_recentFiles); AlertDialog dial = new AlertDialog.Builder(this) .setTitle(getString(R.string.Recently)) .setSingleChoiceItems(resently, 0, new ResentFileOnClickHandler() ) .create(); dial.show(); } } } /** * Open a the database clicked on from the recently opened file menu */ public class ResentFileOnClickHandler implements DialogInterface.OnClickListener { public void onClick(DialogInterface dialog, int which) { String[] files = _recentFiles.split(";"); String database = files[which]; //Utils.toastMsg(_cont, database); dialog.dismiss(); Intent i = new Intent(_cont, DBViewer.class); i.putExtra("db", database); startActivity(i); } } /** * Display the about dialog */ private void showAboutDialog() { Dialog dial = new Dialog(this); dial.setContentView(R.layout.about); dial.show(); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { Utils.logD("MainDriver main-activity got result from sub-activity"); if (resultCode == Activity.RESULT_CANCELED) { Utils.logD("WidgetActivity was cancelled or encountered an error. resultcode == result_cancelled"); Utils.logD("WidgetActivity was cancelled - data =" data); } else switch (requestCode) { case 1: String msg = data.getStringExtra("returnedData"); Utils.showMessage("Returned file", msg, _cont); break; } Utils.logD("MainDriver main-activity got result from sub-activity"); } /** * Create a new empty database */ private void newDatabase() { final Dialog newDatabaseDialog = new Dialog(this); newDatabaseDialog.setContentView(R.layout.new_database); newDatabaseDialog.setTitle(getText(R.string.NewDBSDCard)); final EditText edNewDB = (EditText)newDatabaseDialog.findViewById(R.id.newCode); edNewDB.setHint(getText(R.string.NewDBPath)); TextView tvMessage = (TextView) newDatabaseDialog.findViewById(R.id.newMessage); tvMessage.setText(getText(R.string.Database)); newDatabaseDialog.show(); final Button btnMOK = (Button) newDatabaseDialog.findViewById(R.id.btnMOK); btnMOK.setOnClickListener(new OnClickListener() { public void onClick(View v) { String path; if (v == btnMOK) { if (Utils.isSDAvailable()) { String fileName = edNewDB.getEditableText().toString(); path = Environment.getExternalStorageDirectory().getAbsolutePath(); path = "/" fileName; if (fileName.equals("")) { Utils.showMessage((String)getText(R.string.Error), (String)getText(R.string.NoFileName), _cont); } else { if (!path.endsWith(".sqlite")) path = ".sqlite"; SQLiteDatabase.openOrCreateDatabase(path, null); // Ask before?? Intent i = new Intent(_cont, DBViewer.class); i.putExtra("db", path); newDatabaseDialog.dismiss(); startActivity(i); } } Utils.logD("Path: " edNewDB.getText().toString()); } } }); } /* * Creates the menu items */ public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_OPT, 0, R.string.Option).setIcon(R.drawable.ic_menu_preferences); menu.add(0, MENU_HLP, 0, R.string.Help).setIcon(R.drawable.ic_menu_help); menu.add(0, MENU_RESET, 0, R.string.Reset).setIcon(R.drawable.ic_menu_close_clear_cancel); return true; } /* (non-Javadoc) Handles item selections * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) */ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_OPT: startActivity(new Intent(this, Prefs.class)); return true; case MENU_HLP: Intent i = new Intent(this, Help.class); startActivity(i); return true; case MENU_RESET: // Reset all settings to default SharedPreferences settings = getSharedPreferences("aSQLiteManager", MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("FPJustOpen", false); editor.putBoolean("JustOpen", false); editor.putBoolean(WelcomeId, true); editor.putString("Recently", null); editor.commit(); settings = getSharedPreferences("dk.andsen.asqlitemanager_preferences", MODE_PRIVATE); editor = settings.edit(); //TODO have had problems using Int but RecentFiles seens to work editor.putInt("RecentFiles", 5); editor.putString("PageSize", "20"); editor.putBoolean("SaveSQL", false); editor.commit(); return false; } return false; } }
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论