嵌入式数据库实验

合集下载

数据库实验 通过嵌入式SQL访问数据库

数据库实验 通过嵌入式SQL访问数据库

数据库原理课程实验报告1. 实验题目:实验五通过嵌入式SQL访问数据库2.实验目的熟悉通过嵌入式SQL(主语言C语言)编程访问数据库3实验平台3.1 操作系统:Windows 2000或者Windows XP注:使用Professional版的操作系统建议安装数据库管理系统的教学版,Server 版的操作系统建议安装数据库管理系统的企业版。

3.2 数据库管理系统:SQL Server 2000数据库管理系统4 实验内容及要求内容:熟悉RDBMS的预编译程序。

掌握SQL Server 2000的预编译程序NSQLPREP.EXE 的使用(以课本例题1进行调试)。

要求:在本报告中列出程序代码及注释,保证程序能正确编译运行。

5. 实验内容与完成情况:嵌入式SQL的C语言应用程序在VC++6.0、SQL Server 2000环境下的调试可分为五步:第一步环境初始化;第二步预编译;第三步编译;第四步连接;第五步运行。

1、环境初始化(1) 将文件夹devtools复制到SQL Server的系统目录C:\Program Files\Microsoft SQL Server\(或在安装Microsoft SQL Server 2000时选择安装Development Tools,为使用嵌入式SQL语言准备必要的头文件和库文件。

)(2)初始化Visual C++ 6.0编译器环境。

在命令行方式下运行文件\Microsoft VisualStudio\VC98\Bin\vcvars32.bat。

运行文件\Microsoft Visual Studio\VC98\Bin\vcvars32.bat。

本人直接是由附件里的运行程序直接运行(3)初始化SQL Server的预编译环境。

在命令行方式下运行文件: C:\Program Files\Microsoft SQL Server\DEVTOOLS\SAMPLES\ESQLC\setenv.bat。

嵌入式SQL实验指导

嵌入式SQL实验指导

实验6 嵌入式SQL通过这个实验,我们首先熟悉了嵌入式SQL编程,并可以自己动手编写一个小型的数据库应用程序。

而且能够大体了解我们平时在日常生活中看到的一些数据库应用程序是如何开发出来的。

做完这个实验,你会发现那些数据库程序也并不是十分高深。

这是我们最后一个实验,也是工作量最大的一个实验,大约需要2-3次实验课的时间。

希望同学们认真完成。

实验平台1.OS:WindowsXP2.DBMS:SQLServer2000piler:Visual C++ 6.0(大家可能没有接触过VC++,但并不妨碍我们做这个实验,因为在这个实验中我们只利用它的编译功能。

)预备知识1)嵌入式SQL编程:嵌入式SQL由SQL语句和C/C++代码组成。

其中SQL语句由预处理器翻译成C或C++的源代码。

对预处理后的源代码进行编译、连接生成可执行程序后方可运行。

●SQL预处理器SQLServer的预处理程序是nsqlprep.exe。

其常用的语法格式如下:nsqlprep 程序文档名⏹要求程序文档名的后缀为.sqc,可以省略。

⏹预编译后得到的文档,与程序文档同名,后缀为.c;放在与程序文档名同一个路径下nsqlprep.exe在SQLServer的安装目录的MSSQL\Binn下。

在本机中SQLServer的安装目录是C:\Program Files\Microsoft SQL Server,nsqlprep.exe在C:\Program Files\Microsoft SQL Server\MSSQL\Binn。

由于默认的安装方式(典型安装)并没有安装应用程序nsqlprep.exe,因此,需要你把我提供的binn文件夹,拷贝到该目录下覆盖原来的Binn。

●连接方式经预处理后的c文件就可以用c的编译器进行编译连接了。

使用Visual C++ 6.0进行编译连接,连接方式是动态连接,用到动态链接库SQLakw32.dll,sqlaiw32.dll;此两文件已经随同binn.rar的其他内容,被拷贝到C:\Program Files\Microsoft SQL Server\MSSQL\Binn下;但仍然需要把该路径加到系统的路径变量中,以使得程序运行时能找到这两个文件。

基于ARM-Linux的SQLite嵌入式数据库的研究.

基于ARM-Linux的SQLite嵌入式数据库的研究.

基于ARM-Linux的SQLite嵌入式数据库的研究摘要:开放源码的SQLite可实现基于文件系统的嵌入式关系数据库。

首先,论文分析Linux下的常见数据库技术,详细分析了SQLite嵌入式数据库的内部结构和开发技术,着重介绍SQLite数据库在ARM-Linux平台上的应用开发、交叉编译和移植过程,并给出一个具体的例子进行说明。

关键词:嵌入式数据库;SQLite;ARM-Linux平台;交叉编译Abstract :SQLite is an open source embedded SQL database engine. At first,descripe some general databases’ technology in this paper, and then Internal architecture and developing method of SQLite are analyzed. The application developing ,cross compiling and porting in ARM-Linux platform are also introduced and a detailed example is given for presentation.Keywords :Embedded Databese; SQLite; ARM-Linux platform; cross compiling引言随着嵌入式系统的广泛应用和用户对数据处理和管理需求的不断提高,各种智能设备和数据库技术的紧密结合已经得到了各方面的重视。

不久的将来嵌入式数据库将无处不在。

纵观目前国际、国内嵌入式数据库的应用情况,目前基于嵌入式数据库应用的市场已经进入加速发展的阶段。

1 嵌入式数据库1.1 嵌入式数据库的设计嵌入式数据库系统是指支持某种特定计算模式或移动计算的数据库管理系统,它通常与操作系统和具体应用集成在一起,运行在智能型嵌入式设备或移动设备上。

《嵌入式软件设计》实验报告-12基于qt的嵌入式数据库设计_1107082116_陈堃霖

《嵌入式软件设计》实验报告-12基于qt的嵌入式数据库设计_1107082116_陈堃霖
签名:
日期:
成绩
硬件:PC机;PXA270试验箱
软件:PC机操作系统linux
三、实验内容
1.利用sqlite命令行界面实现数据库管理操作;
2.使用sqlite的API接口实现对数据库的访问操作。
四、步骤
1.利用sqlite命令行界面实现数据库管理操作;
2.使用sqlite的API接口实现对数据库的访问操作。
五、教师评语
《嵌入式系统软件设计》实验报告
实验序号:12实验项目名称:嵌入式数据库设计
学 号
XXX
姓 名
XXX
专业、班
物联网
实验地点实1ຫໍສະໝຸດ 318指导教师XXX
实验时间
2013-12-27
一、实验目的
1.熟悉sqlite用户命令行管理界面使用方法。
2.掌握sqlite数据库程序设计的主要API。
二、实验设备(环境)及要求

嵌入式数据库系统查询机制研究与实现

嵌入式数据库系统查询机制研究与实现

摘要作为移动计算、移动商务和信息电器的核心技术,嵌入式数据库管理系统是最近几年才兴起的一项新的数据管理技术。

它以目前成熟的数据库技术为基础,针对具体的嵌入式设备与系统特点,结合实际应用需求,主要实现对嵌入式设备上数据的存储、组织和管理,以及同后台主数据源的数据交换。

本文分析了嵌入式数据库系统的特点和技术发展现状,并根据嵌入式系统的应用需求和嵌入式系统普遍特征指出:基于内存操作的嵌入式数据库性能的决定因素是系统运行时资源开销而非传统的数据I/O操作次数。

在这个思想的指导下,本文重点考虑了基于内存的嵌入式数据库管理系统的体系结构,对嵌入式数据库系统的查询机制以及实现技术做了详细的探讨,以及对嵌入式数据系统查询优化技术进行了细致的讨论和研究。

针对具体的嵌入式系统环境及其应用特点,嵌入式数据库所提供的查询系统,在不同的嵌入式数据库系统中其处理的方式都不一样,本文提了一套类似于SQL 的面向对象的查询机制,采取该机制可以更加有效的、快速的对数据库中的数据进行查询。

采取这样的一套机制不仅可以提高整个数据库的性能,另外对嵌入式系统开发人员也提供了很大的便利。

对于查询优化,与传统的关系数据库管理系统执行查询相比,当所有的数据存在内存中时,查询的执行速度时非常快速的。

另外也不产生庞大的查询中间结果,只产生指向查询对象的指针,这样也大大提高了系统性能。

很显然对于传统数据库系统的查询优化技术在嵌入式数据库系统中不再适用。

目前对于嵌入式数据库系统查询优化技术没有统一完备的查询优化算法。

针对不同的数据库系统特别是存储方式的不同上一般会选择适合自身系统特点的查询优化机制。

一个好的存储机制对查询速度的提高有很大的帮助。

本文主要从查询实现上通过只取出指向查询结果的指针减少查询中间结果,以及采取一种智能索引的方式和通过并行查询这些技术来进行优化实现。

关键词:嵌入式数据库系统,查询,查询处理,查询优化ABSTRACTAs the core technique of mobile-computing,mobile-commerce and informative electrical appliances,the Embedded Database Management System appears recently which is a newly data management technology.The EDBMS which based on the mature technology of DBMS and aimed at the idiographic embedded system and device, implements the embedded system data store,data organize,data management and data exchange with the background data source according practical requirement.The particularity and the advanced technology of the embedded system and EDBMS are introduced firstly.This dissertation proposes that the capability of EDBMS is decided by the spending of system resource but not the traditional numbers of I/O operations according to the peculiarity of embedded system and the appliances requirement.In this dissertation,the system architecture of the EDBMS based on the EMS memory is pinpointed.Those pivotal techniques in the development of the system, including query process and query optimization are further discussed.In view of the embedded system environment and its application characteristics, the embedded database system provides one set of query subsystems.Different EDBMS has its own way of query processing.An object-oriented query mechanism has proposed in this dissertation,which is similar to the SQL and can query data from the database rapidly and effectively.Not only enhance the entire database performance,this method also can provide the convenience to the developers of embedded application systems.The execution of queries,when all data is present in memory,is very fast, compared with the time for query execution in a traditional RDBMS.But EDBMS even more increases the speed for query execution by applying several optimizations:using indices,inverse references and query parallelization.Keywords:Embedded Database Management System(EDBMS),query,query process,query optimization1绪论1.1研究背景数据库技术是应数据管理任务的需要而产生的。

数据库-实验2-通过嵌入式SQL进行MIS系统开发

数据库-实验2-通过嵌入式SQL进行MIS系统开发

实验二通过嵌入式SQL进行MIS系统开发1、实验目的:熟悉通过高级语言连接SQL Server 数据库的过程,通过嵌入式SQL对数据库进行操作,实现简单的MIS系统2、实验环境:1)使用SQL Server数据库2)自选高级语言开发工具如Powerbuider,VC++等3)举例介绍Powerbuilder连接SQL Server ODBC数据库的过程:打开SQL Server 2008的配置管理SQL Server Configuration Manager,查看右边的服务(如:SQL Server Browser)是否启动,如果没有则手动启动。

打开Powerbuilder选择tools菜单下Database Profile选择ODB ODBC 的Utilities下的ODBC Administrator,双击后选择添加数据源,选择SQL Server Native Client配置数据源名,服务器选择local选择认证方式修改默认链接数据库添加完成后,在Database Profiles对话框中,选中ODB ODBC,右键添加New ProfileData Source选则刚刚建立的数据库源完成后,即可连接新建的ODBC数据库3、实验内容:1)MIS系统的题目和内容自选(如学生学籍管理系统,医疗档案管理系统,图书管理系统等等)。

2)至少包含4个以上的库表。

3)有交互式界面,能通过界面插入、修改和删除数据,能够实现一些简单的查询操作。

4、实验报告列出所设计的数据库表结构。

截屏给出程序界面,操作界面和操作结果其中quit为退出,而hello与SQLcall是内部测试。

点击Insert:点击Select:四个按钮分别对应选择四个表的内容:选择Update:附上主要源代码#-File: dialog_SQL.pyimport mysql.connectorimport sys, osfrom tkinter import *class MyDialog:def __init__(self, root):frame = Frame(root)self.root = rootframe.pack()# SQL related initialization #########################user = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-courtDB.dat'create_database = "CRATE DATABASE courtDB"create_table_sql1 = "\CREATE TABLE IF NOT EXISTS cases ( \case_id int AUTO_INCREMENT PRIMARY KEY, \case_describe varchar(100)) \CHARACTER SET utf8\"create_table_sql2 = "\CREATE TABLE IF NOT EXISTS lawsuits ( \lawsuit_id int AUTO_INCREMENT PRIMARY KEY, \case_id int,\judge_id int,\plaintiff varchar(20), defendant varchar(20) ) \CHARACTER SET utf8\"create_table_sql3 = "\CREATE TABLE IF NOT EXISTS judges ( \judge_id int AUTO_INCREMENT PRIMARY KEY, \name varchar(20), age int ) \CHARACTER SET utf8\"create_table_sql4 = "\CREATE TABLE IF NOT EXISTS outcomes ( \outcome_id int AUTO_INCREMENT PRIMARY KEY, \lawsuit_id int UNIQUE,\lawsuit_winner varchar(20)) \CHARACTER SET utf8\"# SQL hello function #########################self.hi_there = Button(frame, text="Hello", command=self.say_hi, activebackground = 'green',activeforeground = 'white')# SQL goodbye function #########################self.quit = Button(frame, text="Quit", fg="red", underline = 0, command=self.bye_bye, activebackground = 'green',activeforeground = 'white') # SQL test function #########################self.sql_test_call = Button(frame, text="SQL call", command=self.sql_test_call, activebackground = 'green',activeforeground = 'white') # SQL call function #########################SQL_inserter = Button(frame, text="insert", command=self.SQL_insert)SQL_selecter = Button(frame, text="select", command=self.SQL_select)SQL_updateer = Button(frame, text="update", command=self.SQL_update)# gridSQL_inserter.grid(row=0,column=1,padx=10,pady=3)SQL_selecter.grid(row=1,column=1,padx=10,pady=3)SQL_updateer.grid(row=2,column=1,padx=10,pady=3)self.quit.grid(row=0,column=2,rowspan=3,padx=10,pady=9)self.hi_there.grid(row=4,column=1)self.sql_test_call.grid(row=4,column=2)# SQL table definition test #########################sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(create_table_sql1)except mysql.connector.Error as err:print("create table 'cases' failed.")print("Error: {}".format(err.msg))sys.exit()try:cursor.execute(create_table_sql2)except mysql.connector.Error as err:print("create table 'cases' failed.")print("Error: {}".format(err.msg))sys.exit()try:cursor.execute(create_table_sql3)except mysql.connector.Error as err:print("create table 'cases' failed.")print("Error: {}".format(err.msg))sys.exit()try:cursor.execute(create_table_sql4)except mysql.connector.Error as err:print("create table 'cases' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def sql_test_call(self):# SQL related initialization #########################user = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'create_table_sql = "\CREATE TABLE IF NOT EXISTS std_test ( \id int(10) AUTO_INCREMENT PRIMARY KEY, \name varchar(20), age int(4) ) \CHARACTER SET utf8\"insert_sql = "\INSERT INTO std_test(name, age) V ALUES ('Jay', 22 ), ('杰', 26)\"select_sql = "\SELECT id, name, age FROM std_test\"# SQL related definition #########################sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()# SQL standard create #########################try:cursor.execute(create_table_sql)except mysql.connector.Error as err:print("create table 'std_test' failed.")print("Error: {}".format(err.msg))sys.exit()# SQL standard insert #########################try:cursor.execute(insert_sql)except mysql.connector.Error as err:print("insert table 'std_test' failed.")print("Error: {}".format(err.msg))sys.exit()if os.path.exists(data_file):myfile = open(data_file)lines = myfile.readlines()myfile.close()for line in lines:myset = line.split()sql = "INSERT INTO std_test (name, age) V ALUES ('{}', {})".format(myset[0], myset[1])try:cursor.execute(sql)except mysql.connector.Error as err:print("insert table 'std_test' from file 'mysql-test.dat' --failed.")print("Error: {}".format(err.msg))sys.exit()# SQL standard select #########################try:cursor.execute(select_sql)for (id, name, age) in cursor:print("ID:{} Name:{} Age:{}".format(id, name, age)) except mysql.connector.Error as err:print("query table 'mytable' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_insert(self):# topwindow1 #########################top = self.top = Toplevel(root)self.insert_table = Entry(top)self.insert_attri = Entry(top)self.insert_value = Entry(top)self.insert_op = Button(top, text="INSERT",command=lambda:self.SQL_insert_operate(TAB=self.insert_table.ge t(),ATR=self.insert_attri.get(),V AL=self.insert_value.get()), activebackground = 'green',activeforeground = 'white')Label(top, text="insert").grid(row = 0,column=2)Label(top, text="TABLE ").grid(row=1,column=1)Label(top, text="ATTRIBUTE").grid(row=1,column=2)Label(top, text="V ALUE ").grid(row=1,column=3)self.insert_table.grid(row=2,column=1)self.insert_attri.grid(row=2,column=2)self.insert_value.grid(row=2,column=3)self.insert_op.grid(row=3,column=3)# Entry #########################def SQL_insert_operate(self,TAB,ATR,V AL):print(TAB,ATR,V AL)# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'insert_sql = "INSERT INTO "+TAB+"("+ATR+") V ALUES ("+V AL+")"print(insert_sql);sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(insert_sql)except mysql.connector.Error as err:print("insert table "+TAB+" failed.")print("Error: {}".format(err.msg))sys.exit()if os.path.exists(data_file):myfile = open(data_file)lines = myfile.readlines()myfile.close()for line in lines:myset = line.split()sql = "INSERT INTO "+TAB+" ("+ATR+") V ALUES ('{}',{})".format(myset[0], myset[1])try:cursor.execute(sql)except mysql.connector.Error as err:print("insert table "+TAB+" from file 'mysql-test.dat' -- failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_select(self):# topwindow1 #########################top = self.top = Toplevel(root)self.select_cases = Button(top,text="CASES",command=self.SQL_select_cases,activebackground = 'green',activeforeground = 'white')self.select_lawsuits = Button(top,text="LAWSUITS",command=self.SQL_select_lawsuits,activebackgroun d = 'green',activeforeground = 'white')self.select_judges = Button(top,text="JUDGES",command=self.SQL_select_judges,activebackground = 'green',activeforeground = 'white')self.select_outcome = Button(top,text="OUTCOMES",command=self.SQL_select_outcomes,activebackgro und = 'green',activeforeground = 'white')self.select_cases.pack(padx=10,pady=5)self.select_lawsuits.pack(padx=10,pady=5)self.select_judges.pack(padx=10,pady=5)self.select_outcome.pack(padx=10,pady=5)# Entry #########################def SQL_select_cases(self):# topwindow1 #########################top = self.top = Toplevel(root)self.S_C_ID = Entry(top)Label(top, text="ID of the Case").pack()self.S_C_ID.pack(padx=20,pady=40)self.select_cases_op = Button(top, text="SELECT FROM CASES",command=lambda:self.SQL_S_C_op(ID=self.S_C_ID.get()), activebackground = 'green',activeforeground = 'white').pack()def SQL_S_C_op(self,ID):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT case_id, case_describe FROM cases WHERE case_id = "+str(ID)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (id, describe) in cursor:print("ID:{}\ndescribe:{}".format(id, describe))except mysql.connector.Error as err:print("query table 'cases' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_select_lawsuits(self):# topwindow1 #########################top = self.top = Toplevel(root)# case_idself.S_L_CID = Entry(top)Label(top, text="ID of the Case").grid(row=0,column=1)self.S_L_CID.grid(row=1,column=1)self.select_lawsuits_op = Button(top, text="SELECT",command=lambda:self.SQL_S_L_CID(CID=self.S_L_CID.get()), activebackground = 'green',activeforeground = 'white').grid(row=2,column=1) # lawsuit_idself.S_L_LID = Entry(top)Label(top, text="ID of the Lawsuit").grid(row=0,column=2)self.S_L_LID.grid(row=1,column=2)self.select_lawsuits_op = Button(top, text="SELECT",command=lambda:self.SQL_S_L_LID(LID=self.S_L_LID.get()), activebackground = 'green',activeforeground = 'white').grid(row=2,column=2) def SQL_S_L_CID(self,CID):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT * FROM lawsuits WHERE case_id = "+str(CID)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (lawsuit_id,case_id,judge_id,plaintiff,defendant) in cursor:print("Lawsuit_ID:{} Case_ID:{} Judge_ID:{} plaintiff:{} defendant:{}".format(lawsuit_id,case_id,judge_id,plaintiff,defendant))except mysql.connector.Error as err:print("query table 'lawsuit' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_S_L_LID(self,LID):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT * FROM lawsuits WHERE lawsuit_id ="+str(LID)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (lawsuit_id,case_id,judge_id,plaintiff,defendant) in cursor:print("Lawsuit_ID:{} Case_ID:{} Judge_ID:{} plaintiff:{} defendant:{}".format(lawsuit_id,case_id,judge_id,plaintiff,defendant))except mysql.connector.Error as err:print("query table 'lawsuit' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_select_judges(self):# topwindow1 #########################top = self.top = Toplevel(root)# judge_idself.S_J_JID = Entry(top)Label(top, text="ID of the Judge").grid(row=0,column=1)self.S_J_JID.grid(row=1,column=1)self.select_judges_CID = Button(top, text="SELECT",command=lambda:self.SQL_S_J_JID(JID=self.S_J_JID.get()), activebackground = 'green',activeforeground = 'white').grid(row=2,column=1) # ageself.S_J_AGE = Entry(top)Label(top, text="Age of the Judge").grid(row=0,column=2)self.S_J_AGE.grid(row=1,column=2)self.select_judges_op = Button(top, text="SELECT",command=lambda:self.SQL_S_J_AGE(AGE=self.S_J_AGE.get()), activebackground = 'green',activeforeground = 'white').grid(row=2,column=2) def SQL_S_J_JID(self,JID):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT * FROM judges WHERE judge_id = "+str(JID)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (judge_id,name,age) in cursor:print("Judge ID:{} name:{},age:{}".format(judge_id,name,age)) except mysql.connector.Error as err:print("query table 'judges' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_S_J_AGE(self,AGE):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT * FROM judges WHERE age = "+str(AGE)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (judge_id,name,age) in cursor:print("Judge ID:{} name:{},age:{}".format(judge_id,name,age)) except mysql.connector.Error as err:print("query table 'judges' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_select_outcomes(self):# topwindow1 #########################top = self.top = Toplevel(root)# case_idself.S_O_OID = Entry(top)Label(top, text="ID of the Outcome").grid(row=0,column=1)self.S_O_OID.grid(row=1,column=1)self.select_outcome_OID = Button(top, text="SELECT",command=lambda:self.SQL_S_O_OID(OID=self.S_O_OID.get()), activebackground = 'green',activeforeground = 'white').grid(row=2,column=1) # lawsuit_idself.S_O_LID = Entry(top)Label(top, text="ID of the Lawsuit").grid(row=0,column=2)self.S_O_LID.grid(row=1,column=2)self.select_outcome_LID = Button(top, text="SELECT",command=lambda:self.SQL_S_O_LID(LID=self.S_O_LID.get()), activebackground = 'green',activeforeground = 'white').grid(row=2,column=2) def SQL_S_O_OID(self,OID):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT outcome_id, lawsuit_id, lawsuit_winner FROM outcomes WHERE outcome_id = "+str(OID)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (outcome_id,lawsuit_id,lawsuit_winner) in cursor:print("outcome_ID:{} Lawsuit_ID:{} lawsuit_winner:{}".format(outcome_id,lawsuit_id,lawsuit_winner))except mysql.connector.Error as err:print("query table 'outcome' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_S_O_LID(self,LID):# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'# Entry #########################select_sql = "\SELECT outcome_id, lawsuit_id, lawsuit_winner FROM outcomes WHERE lawsuit_id = "+str(LID)+"\"sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(select_sql)for (outcome_id,lawsuit_id,lawsuit_winner) in cursor:print("outcome_ID:{} Lawsuit_ID:{} lawsuit_winner:{}".format(outcome_id,lawsuit_id,lawsuit_winner))except mysql.connector.Error as err:print("query table 'outcome' failed.")print("Error: {}".format(err.msg))sys.exit()sql_mit()cursor.close()sql_cnx.close()def SQL_update(self):# topwindow1 #########################top = self.top = Toplevel(root)self.update_table = Entry(top)self.update_set_attri = Entry(top)self.update_set_value = Entry(top)self.update_lim_attri = Entry(top)self.update_lim_value = Entry(top)self.update_op = Button(top, text="UPDATE",command=lambda:self.SQL_update_operate(TAB=self.update_table .get(),SET_ATR=self.update_set_attri.get(),SET_V AL=self.update_set_value.get(),LI M_ATR=self.update_lim_attri.get(),LIM_V AL=self.update_lim_value.get()), activebackground = 'green',activeforeground = 'white')Label(top, text="update").grid(row = 0,column=2)Label(top, text="TABLE ").grid(row=1,column=1)Label(top, text="UPDATE ATTRIBUTE").grid(row=1,column=2)Label(top, text="UPDATE V ALUE ").grid(row=1,column=3)Label(top, text="LIMIT ATTRIBUTE").grid(row=1,column=4)Label(top, text="LIMIT V ALUE ").grid(row=1,column=5)self.update_table.grid(row=2,column=1)self.update_set_attri.grid(row=2,column=2)self.update_set_value.grid(row=2,column=3)self.update_lim_attri.grid(row=2,column=4)self.update_lim_value.grid(row=2,column=5)self.update_op.grid(row=3,column=5)# Entry #########################def SQL_update_operate(self,TAB,SET_ATR,SET_V AL,LIM_ATR,LIM_V AL): print(TAB,SET_ATR,SET_V AL,LIM_ATR,LIM_V AL)# SQL related argumentuser = 'root'pwd = 'harbin141421'host = '127.0.0.1'db = 'courtDB'data_file = 'mysql-court.dat'update_sql = "UPDATE "+TAB+" SET "+SET_ATR+"="+str(SET_V AL)+" WHERE "+LIM_ATR+"="+str(LIM_V AL);print(update_sql);sql_cnx = mysql.connector.connect(user=user, password=pwd, host=host, database=db)cursor = sql_cnx.cursor()try:cursor.execute(update_sql)except mysql.connector.Error as err:print("update table "+TAB+" failed.")print("Error: {}".format(err.msg))# sys.exit()if os.path.exists(data_file):myfile = open(data_file)lines = myfile.readlines()myfile.close()for line in lines:myset = line.split()sql = "INSERT INTO "+TAB+" ("+SET_ATR+") V ALUES ('{}',{})".format(myset[0], myset[1])try:cursor.execute(sql)except mysql.connector.Error as err:print("insert table "+TAB+" from file 'mysql-test.dat' -- failed.")print("Error: {}".format(err.msg))# sys.exit()sql_mit()cursor.close()sql_cnx.close()def say_hi(self):print("hi there, everyone!")def bye_bye(self):print ("see you sir")self.root.destroy()root = Tk()root.update()d = MyDialog(root)root.mainloop()####################。

嵌入式实验报告

嵌入式实验报告

嵌入式LINUX课程设计学号:0901********专业:电子信息工程班级:二班姓名:指导老师:嵌入式数据库SQLite的移植与使用一.嵌入式数据库及SQLite概述:随着计算机技术与其他学科不断交融渗透,数据库应用的范围更加深入和具体。

那些仅适用于PC机、体积庞大、延时较长的数据库技术已经不能满足嵌入式系统的开发需求。

数据库的目标是实现对数据库的存储,检索和增删等功能。

传统的数据库产品除提供基本的查询、添加、删除等功能外,也提供了很多高级特性,如触发器、存储过程、数据备份恢复等。

然而,在嵌入式系统中,由于软硬件资源有限,不可能安装庞大的数据库服务器,因此一个简单的基本磁盘文件的数据库系统就可以实现相应的用户需求,而这仅仅是利用了数据库的基本特性。

因此在这种特殊的应用场合下,传统的数据库就显得过于臃肿了。

嵌入式数据库与传统数据库的区别是:嵌入式数据库采用程序方式直接驱动,而传统数据库则采用引擎响应方式驱动;嵌入式数据库的体积通常比较小,而且具备功能齐全、可移植性强、健壮等特点,因此嵌入式数据库常常应用在移动设备上。

另外,由于其性能卓越,也应用于高性能数据处理场景。

SQLite是一款轻型数据库,设计目标主要针对嵌入式系统。

其占用资源少,在嵌入式设备中一般只需要几百K内存。

它能够支持Windows、Linux、Unix等主流的操作系统,并且能够和很多程序语言相结合,如Tcl、PHP、Java以及ODBC 接口。

与MYSQL、PostgreSQL这两款开源世界著名的数据库管理系统相比,他的处理速度更快。

SQLite虽然很小巧,但是支持的SQL语句不会逊色于其他开源数据库。

SQLitem的特点如下:1、ACID事务2、零配置———不需要安装和管理配置3、存储在单一磁盘文件中的一个完整的数据库4、数据库文件可以在不同字节顺序的机器之间自用共享5、支持数据库大小至2TB6、足够小,只有250KB7、速度比大部分的普通数据库操作都要快8、简单易学9、包含TCL绑定,通过Wrapper支持其他预言绑定10、良好的注释的源代码,并且有90%以上的测试覆盖率11、独立,没有额外依赖12、开源13、支持多种开发语言二、系统总设计:软件移植过程如下:三、实验步骤及结果分析:SQLite在ARM平台上的移植:SQlite发展到现在已经具有了多个版本,最新版本为 3.6.3。

实验五、通过嵌入式SQL访问数据库 (2)

实验五、通过嵌入式SQL访问数据库 (2)

实验报告单院(系):计算机学院专业:计算机科学与技术(嵌入式方向)班级:12计科5班姓名:陶昕星学号:34同组人:实验室:S4305组号:日期: 4.25课程:数据库原理指导教师:邱长春成绩:实验项目编号:05 实验项目名称:嵌入式SQL 一、实验目的1.熟悉通信区、游标的概念;2.理解嵌入式SQL的处理过程;3.For personal use only in study and research; not for commercial use4.5.掌握SQL与主语言之间的通信机制;6.熟悉通过嵌入式SQL访问数据库二、实验环境For personal use only in study and research; not for commercial useSQL Server2000三、实验学时2学时四、实验内容及步骤1. 查看SQL Server的参考文献,找出嵌入式SQL编程所需的各种组件,如下图所示:2.通过自定义的方式安装SQL Server,确保上述组件安装成功,并找出这些组件所在的目录路径,如下面的图示:3.创建一个数据库,本例的数据库为stu,并将其密码设置为sa;4.使用文本编辑器编写一个嵌入式SQL程序,扩展名为sqc。

本例的嵌入式SQL程序名称为EmbedSql.sqc,程序如下:#include <stdio.h>#include <stdlib.h>EXEC SQL INCLUDE sqlca;{EXEC SQL BEGIN DECLARE SECTION;//主变量char lname[40];char fname[20];EXEC SQL END DECLARE SECTION;printf("This is my Embedded SQL for C application\n");EXEC SQL CONNECT TO WIN-CF7AKA VRCJA.pubs USER sa.sa;//连接到数据库if (SQLCODE == 0){printf("Connection to SQL Server established\n");}else{// 连接DBMS错误printf("ERROR: Connection to SQL Server failed\n");return (1);}EXEC SQL DECLARE selCursor CURSOR FORSELECT au_lname, au_fnameFROM authors;EXEC SQL OPEN selCursor ;for ( ; ; ) {/* Fetch next row of the result table */EXEC SQL FETCH selCursor INTO :lname,:fname;if (SQLCODE == 0){printf("lname:%s/n",lname);printf("fname:%s/n",fname);}elsebreak;/* display data */}printf ("SQL error %d\n",sqlca->sqlcode);//若照书上写sqlca.sqlcode编译报语法错done:/* Close the cursor before completing*/EXEC SQL WHENEVER SQLERROR continue;EXEC SQL CLOSE providerCursor;EXEC SQL COMMIT WORK RELEASE;//断开连接EXEC SQL DISCONNECT ALL;return 0;}5. 实例工程的构建:(1)打开VC6.0,新建名为esqlea1的WIN32 Console Application工程文件;(2)把EmbedSql.sqc拷贝到工程的目录文件夹下;(3)将上述组件拷贝到工程的目录文件夹下;(4)在工具菜单下选择Options,再选择Directories,在Show Directories for 下拉框中选择Include files,在Directories编辑框中输入SQLServer开发工具的头文件路径;选择library files,在Directories编辑框中输入SQLServer开发工具的库文件路径;选择可执行文件,在Directories编辑框中输入SQLServer开发工具的可执行文件路径。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
嵌入式系统实验
嵌入式数据库设计
实验内容
SQLite交叉编译 SQLite应用验证 SQLite应用设计
SQLite交叉编译(1)
换成root用户登录sudo su 将src目录中的代码复制到/opt/workspace/ 进入/opt/workspace/ 解压sqlite源码
tar xzvf sqlite-autoconf-3071602.tar.gz
./sqlite_test test.db “select * from student;”
sqlite_test(1)
int main(int argc, char **argv){ sqlite3 *db; char *zErrMsg = 0; int rc; rc = sqlite3_open(argv[1], &db); if( rc ){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); return(1); } rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg); if( rc!=SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_close(db); return 0;
}
SQLite验证(4)
运行结果
SQLite应用设计(1)
在宿主机设计一个应用程序connector
连接目标板ip上的9999端口 连接建立后,以写方式打开当前文件夹下的test.txt,并网络发
送“ready”字符串 循环接收数据,每接收一次数据写入test.txt 接收到“ok”字符串后,关闭文件 关闭socket
进入源码目录sqlite-autoconf-3071602/ 新建一个build目录:mkdir build 进入该目录: cd build
SQLite交叉编译(2)
配置源码
../configure --disable-tcl --host=arm-none-linuxgnueabi
编译:make 将隐藏目录.libs/复制到/share/目录中
}
sqlite_test(2)
static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; for(i=0; i<argc; i++){ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0;
端端口、本地IP、本地端口、事件和内容 事件包括:侦听、连接、发送、接收、关闭 内容,针对发送和接收的具体内容 要求使用sqlite_test建立、查询和维护该数据库
谢 谢!
mount -t nfs -o nolock 10t 将库和链接均复制到/usr/lib/中
cp -raf lib* /usr/lib/
SQLite验证(2)
创建一个数据库文件并建立一张表
./sqlite_test test.db “create table student(name varchar, age integer);”
在表中插入一行记录
./sqlite_test test.db “insert into student values(\”pzw\”, 20);”
查询表中的所有记录
./sqlite_test test.db “select * from student;”
修改表中的记录
./sqlite_test test.db “update student set age=21 where name=\”pzw\””
在目标板上设计一个应用程序deamon
侦听9999端口 有连接进入后,建立连接 接收到“ready”后,打开test.txt,并按每64字节读取,发送给
宿主机,循环发送 发送完毕后,发送“ok”字符串 关闭文件
SQLite应用设计(2)
使用sqlite数据库记录网络日志 表的字段包含序号(自增)、时间、对端IP、对
SQLite验证(3)
再运行一次查询,查看修改的结果
./sqlite_test test.db “select * from student;”
删除表中的记录
./sqlite_test test.db “delete from student where name=\”pzw\””
再次运行查询语句, 查看删除后的结果
cp -raf .libs/* /share/
SQLite交叉编译(3)
进入/opt/workspace/sqlite_test/目录 编译:make 将生成的可执行程序sqlite_test复制到
/share/目录中
cp sqlite_test /share/
SQLite验证(1)
Local文件系统启动 挂载NFS到/mnt下
相关文档
最新文档