




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本科毕业论文外文文献及翻译题目: 嵌入式数据库SQLite的应用研究学院: 电子信息工程学院 班级: 电信122班 姓名: 指导教师: 职称: 副教授 完成日期: 2016 年 06 月 16 日2009InternationalForumonInformationTechnologyandApplicationsApplication Research of Embedded Database SQLiteLv Junyan, Xu Shiguo, Li Yijie School of Economic Information Engineering, Liaoning technical University, Huludao, 125105 lvjunyan_2002163.comABSTRACT: The traditional database can not be used for the data management of embedded systems. However, the open-source embedded database SQLite can meet the needs of embedded systems better because of its advantages. Through the analysis of the characteristics of embedded database and SQLites characteristics, the internal structure and the function of API, it constructs the simulation environment of ARM-Linux and achieves the realization of SQLite in the ARM-Linux platform, including cross-compiling, transplant process and application development, it also achieves the graphical user interface design based on Qt/Embedded. The embedded database system meets the needs of data management of the system and has very good meaning of the guiding theory and practice for embedded systems development.KEYWORDS: embedded system; embedded database; SQLite; cross compilingINTRODUCTIONThe software and hardware resources of embedded systems are limited, the realization of embedded applications is comparatively single and specific, data processing and the ability to maintain are dont asked for much, so the traditional database can not be used for embedded data management systems. It must be used embedded database to meet the needs of embedded systems which is small, fast, simple, reliable and easy-to-port. Through the comparison of the number of embedded databases, we found that SQLite has such special advantages just as powerful, fast, simple interface as well as small footprint, so its especially suitable for applications in embedded environment. This paper will focus on how to simulate ARM-Linux operating system in the SkyEye platform, how to cross-compile SQLite3 in ARM-Linux platform and achieve the SQLite application development in the platform as well as the implementation of graphical user interface design based on Qt/Embedded. SQLite3 uses C language as its development language, so it has good portability. Methods mentioned here are also applicable on other OS platforms without much modification. SQLite is an open-source embedded database system, and has small overhead, efficient search features, so it is especially suitable for mobile phone, PDA, set-top boxes and other electrical equipments, and has good running ability in consumer applications which can be downloaded.CHARACTERISTICS OF EMBEDDED DATABASE Due to limited resources of hardware and software, it is not possible to install a huge database server in embedded database systems. However, users need may be meted with a database system which is just a simple document of diskbased. It just makes use of the basic characteristics of the database. Since the special restrictions of application environment, embedded database has its own characteristics compared to common database systems12 : Taking up little storage space, reliability, manageability and security, interoperability, tailoring, portability, high-performance, low cost, embedded, full-featured and other characteristics. Although SQLite is an extremely lightweight relational database, it has retained most of the features of database. Its main features are as follows 3: Transactions are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures. Zero-configuration, no setup or administration needed. A complete database is stored in a single cross-platform disk file. Supports terabyte-sized databases and gigabyte-sized strings and blobs. Small code footprint: less than 275KB fully configured. Faster than popular client/server database engines for most common operations. Simple, easy to use API. Self-contained: no external dependencies. Cross-platform and it is easy to port to other systems. Sources are in the public domain.The internal structure of SQLite is composed of the following components: SQL compiler, kernel, the back-end as well as the annex. Interface is a C language library which can receive API in a wide range of language, but the implementation in the bottom is the C language library. When a SQL statement containing the string is implemented, the interface programs pass the string to the Tokenizer. The Tokenizer decomposes the original string into the indicators identified by a parser and passes these indicators to the parser. After the parser collects the symbols, it converts them to full SQL statement, and then it calls the code generator to generate the virtual machine code and the virtual machine code is handed to the virtual machine to implement and complete the SQL statement. The core of the architecture of SQLite is the virtual database engine (VDBE). VDBE completes the entire task related to data processing and it is the intermediate unit of information exchange between and customers and the storage. SQLite database is maintained in the disk, implemented by B -tree which is in the source file btree.c and it searches and accesses data fast through the adjustable page cache (pager). In order to facilitate the transplant, the interface programs of SQLite operating system uses a layer extraction. Utilities mainly solute the memory allocation, string comparison, lexical analysis, the store of the symbol table in the grammar analysis as well as the professional printing function and the random number function of SQLite. More than half of the SQLite functions can be debugged with the test code and it simulates the recovery mechanism of SQLite when the system collapses.Embedded database SQLite provides API interface of C language, making operation of the database is very simple. Some of the functions will be introduced briefly in the following paper4:1) C/C+ common interface of SQLite3typedef struct sqlite3 sqlite3;int sqlite3_open(const char*, sqlite3*); /open the database, including documents and memory sqlite3_close(sqlite3*); /close the databaseint qlite3_last_insert_rowid(sqlite3*); /the line of inserting data finallyconst char *sqlite3_errmsg(sqlite3*); /get the corresponding introduction of error code. These error messages will be returned in UTF-8, and will be removed when it calls any SQLite API function next sqlite3_errcode(sqlite3*); / acquire the error code that calls the recent API interface.2) Different implementation ways of SQLite3Implement one or more lines of SQL statements andimplement the callback function on the each line ofquerying results: int sqlite3_exec();Structure the SQL statement dynamically:char *sqlite3_mprintf(const char*,.);char *sqlite3_vmprintf(const char*, va_list);/structure statements,executed by sqlite3_execint sqlite3_exec_printf();/structure querying statements and execute voidFigure 1.Internal structure of SQLite.sqlite3_free(char *z);/ release the memory allocatedby sqlite3_ (v)Pre-compile SQL statement, reduce the time of SQLanalysis:int sqlite3_prepare();/ pre-compileint sqlite3_step(sqlite3_stmt*); /execute once ormoreint sqlite3_reset ( sqlite3_ stmt*);/reset sqlite3_stmt(come from sqlite3_prepare()int sqlite3_finalize(sqlite3_stmt *pstmt); /releaseMake use of the encapsulation about sqlite3_exec ()and return all results:int sqlite3_get_table();void sqlite3_free_table(char *result);SQLITE IN THE ARM-LINUX PLATFORMThe system chose SQLite database after compared and studied different embedded database. SQLite releases the source code, can be transplanted in a large number of hardware platforms and the source code can be cross-compiled according to different platforms. Due to the ARM core processor widely used in the field of embedded systems, the ARM-Linux platform has become widely used in many embedded operating system. In order to save costs and improve the efficiency of development, firstly, ARM-Linux operating system is transplanted into SkyEye platform to simulate, after debugged and run well, SQLite is cross-compiled in the ARM-Linux platform.A. Construct simulation operating environment of ARM-LinuxSkyEye platform is the variation and extension of the hardware development board. It makes use of software technology to simulate the real hardware environment and you can lose sight of a large number of details of the hardware, improve higher design efficiency and shorten the design cycle of software products. ARM-Linux is an excellent real-time embedded operating system, so the ARM-Linux transplanted in the SkyEye platform has some practical significance.ARM-Linux will be structured in the SkyEye platform. In order to be able to run own applications in the ARM-Linux, it need to articulate NFS. Its realization includes the following steps:1) Install skyeye. Select the version skyeye1.2.4, first of all, extract the source package:#tar xzf skyeye-1.2.4_Rel.tar.gz #cd skyeye-1.2.4 In order to articulate NFS in the ARM-Linux which run on it, we need to amend device/net/dev_net_cs8900a.c, save the revised file as dev_net_cs8900a.c, replace the old file not revised with it, and then implement the compiler:#make NO_DBCT = 1 NO_BFD = 1. After compiled and generated skyeye is in binary, copy it to the /usr/local/bin/:#cp binary/skyeye/usr/local/bin2) Compile the kernel. Select the version Linux-2.6.14.tar.bz2,use the cross-compiler arm-linux-gcc 3.4.1, just as the following steps: Assume the core source package is in the directory /root, firstly, decompress the source:#cd /root#tar xjf linux-2.6.14.tar.bz2 Enter into the core directory: #cd linux-2.6.14, modify the Makefile in this directory. Generate the default kernel configuration file (for s3c2410): #make smdk2410_defconfig. Add cs8900 network card driver to the core to support the NFS mount. Revise the core document. Cut and custom the kernel. First of all, set up the command #make menuconfig, then followed by the parameters of the start-core and the support of CS8900, the initrd, NFS, ROM file system and the ext2. Compile #make. After compiled there will be a vmlinux in the current directory and this is the arm-linux kernel that needed.3) Make root file system initrd.img (initial RAM disk). Select the version Busybox-1.9.2.tar.bz2, compile it in a static manner.Through articulating NFS in the arm-linux, we can articulate the library files of the arm-linux-gcc compiler of the host to the directory /lib of arm-linux, then we can run our own procedures for the. The following steps are: extract the source package, amend Makefile, custom busybox, implement make compiling and make initrd.img.4) Run arm-linux. Run arm-linux. Config the file Skyeye.conf and run for the simulation of arm-linux.Run own procedures in the arm-linux. First of all, config NFS Server in the host of arm-linux, and then edit the file /etc/exports, config the ip of the host, restart nfs server, run arm-linux in the skyeye and config its ip, run arm-linux in the skyeye and demonstrate the nfs mounted.To confirm that arm-linux is able to communicate with the host, we can ping each other until they can communicate with each other.B.Realization of SQLite in ARM-Linux platformSQLite is compiled in ARM-Linux platform including the following steps 5-7: Download the sqlite-3.6.3.tar.gz from / to the /root directory, decompress it and extract files and directories from the pigeonholed files. Then it will generate the sqlite-3.6.3/ subdirectory in /root directory. Use the order echo$PATH to examine whether the cross-compiler tool arm-linux-gcc has been included in the PATH. Amend Makefile documents manually, can not configure a script to generate Makefile documents. First of all, through the order # cp Makefile.linux-gcc Makefile copy the example file of Makefile Makefile.linux-gcc under the directory sqlite-3.6.3/, rename the file Makefile and then open the file Makefile manually with vim and modify the Makefile documents. In principle, the changes to the Makefile mainly include two aspects: firstly, change the compiler, tools such as archiving into the corresponding tools in cross tool chain, such as gcc replaced by arm-linux-gcc, ar replaced by ar-linux-ar, ranlib replaced by arm-linux-ranlib, and so on; Secondly, remove the compiler options related to TCL. Because by default, the Tcl language binding of SQLite3 will be compiled, but it is not required when it is transplanted to ARM-Linux. So the two lines about TCL are noted out; it is also need to amend the document main.mk, replace theselect.o table.o tokenize.o trigger.o byselect.o table.o tclsqlite.o tokenize.o trigger.o. That means that tclsqlite.o on the line is removed, so that the Tcl language binding of SQLite3 will not be compiled when it compiles. Use the order # make to start to compile SQLite3, generate the documents of library function libsqlite3.a and header file sqlite3.h in the directory sqlite3.6.3/. Use the testing procedures of the quick start documentation in the SQLite official site to test the SQLite3 that transplanted to the ARM-Linux. After compiling the program, test procedures will be downloaded to the evaluation board through the NFS or FTP. If the test is passed then it indicates that the database is able to work properly.APPLICATION DEVELOPMENT OF SQLITE IN THEARM-LINUXAfter compiling the library documents and executable files of sqlite, we use the C language to call the interface function to manage the database on the platform including the creating database, creating tables, inserting data, inquiring data and so on. The main code of realizing the functions is as follows:#include #include #include sqlite3.h #define _DEBUG_ int main( void )sqlite3 *db=NULL; char *zErrMsg = 0; int rc;rc=sqlite3_open(June.db, &db);/Open the specified database file, if it isnt exist then create a database file of the same nameif(rc)fprintf(stderr, Cant open database: %s, sqlite3_errmsg(db);sqlite3_close(db); exit(1);else printf(You have opened a sqlite3 database named June.db successfully!);/Create a table, if the table exists then gives up and gives tips information stored in the zErrMsg.char *sql=CREATE TABLE PhoneData( Name VARCHAR(12) PRIMARY KEY, PhoneNumber VARCHAR(15),E-mail VARCHAR(35), ); sqlite3_exec( db ,sql , 0 , 0 , &zErrMsg ); #ifdef _DEBUG_printf(zErrMsg = %s, zErrMsg); #endif/Insert datasql = INSERT INTO PhoneData VALUES(J ); ;sqlite3_exec( db, sql , 0 , 0 , &zErrMsg );int nrow = 0, ncolumn = 0;char *azResult;/ Store the results of two-dimensional array/Query datasql = SELECT * FROM PhoneData; sqlite3_get_table( db , sql , &azResult , &nrow ,&ncolumn , &zErrMsg ); int i = 0 ;printf( row:%d column=%d , nrow , ncolumn ); printf( The result of querying is : );for( i=0 ; i( nrow + 1 ) * ncolumn ; i+ ) printf(azResult%d=%s,i, azResulti );/ Release thememory space of azResult sqlite3_free_table( azResult ); #ifdef _DEBUG_printf(zErrMsg = %ss, zErrMsg);#endifsqlite3_close(db); /Close the database return 0;After it is compiled and run, we can see the results. There is zErrMsg = (null) in output, it is the error message retained by zErrMs. zErrMsg is empty, then it shows that there is no error message in the course of implementation.GRAPHICAL USER INTERFACE DESIGNAfter calling the interface functions of SQLite to build database well, we design the graphical user interface of the database. With the development of SQLite, QT/E provides database-driven specifically for SQLite now. This is an open source project and has been developed maturely. It can be downloaded in the open source communities. QT/E is connected with SQLite through the database options in the left side when we design the forms. We need to notice two points mainly in the development of QT/E and SQLite8:1)Searching the library.Generally speaking, errors encountered in the application development are mainly logic errors or grammar errors or could not find the library. The former is easy to solve as long as we are circumspective. The latter is the key, as many of the problems are caused by it. We must set up the path of the library well in the period of compiling.2) Searching header files is mainly need to notice that adding sqlite3.h when we create the header files of QT/E.The main development process is divided into the following steps: Make use of the designer of QT/E to establish the graphical interface and set the corresponding attributes. Establish the source documents and header files of browsermain.cpp, sqlitedb.cpp and so on. Amend the document . HEADERS+=sqlitebrowsertypes.h sqlitedb.hsqlbrowser_util.h SOURCES+=browsermain.cpp sqlitedb.cppsqlbrowser_util.c LIBS+=./sqlite_soure/libsqlite_source.aLIBS+=-lsqlite3After QT/Embedded is installed and the environment is set up, QT/E application procedures are run on the development board and the graphics output of the procedures is through the Frame Buffer device.CONCLUSIONThis paper studies and analyzes the characteristics of embedded database and SQLites characteristics, the internal structure and the function of API. It constructs the simulation environment of ARM-Linux and achieves the realization of SQLite in the ARM-Linux platform. It also achieves the application development of SQLite in the ARM-Linu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 山西体育职业学院《C语言》2023-2024学年第二学期期末试卷
- 贵阳康养职业大学《微波测量技术及仪器》2023-2024学年第二学期期末试卷
- 宁波工程学院《成本会计学》2023-2024学年第二学期期末试卷
- 吉林城市职业技术学院《传感与检测技术》2023-2024学年第二学期期末试卷
- 九江职业技术学院《云计算和大数据技术》2023-2024学年第二学期期末试卷
- 南京城市职业学院《商务决策模型》2023-2024学年第二学期期末试卷
- 2024年发电机组、内燃发电机组及旋转式变流机项目资金需求报告代可行性研究报告
- 核磁共振成像设备维护保养培训
- 学生个人规划课件
- 小学生感恩教育主题班会
- 技术报告审签表
- GB∕T 25684.5-2021 土方机械 安全 第5部分:液压挖掘机的要求
- 大学无机化学(吉林大学、武汉大学、南开大学版) 第17章 卤素—— 内蒙古民族大学)
- 中国基层胸痛中心认证标准(第三版)
- 鸡的解剖步骤及病
- 喷涂件检验通用规范
- 石方爆破及安全施工工艺流程图
- 市场部经理年终总结PPT模板
- 医院版LIS操作手册(共84页)
- 优秀毕业设计精品]语音放大电路的设计
- MT103的栏位说明
评论
0/150
提交评论