当前位置: 首页 > news >正文

麻章网站建设公司郑州高端网站建设

麻章网站建设公司,郑州高端网站建设,企业电子商务网站开发,中英文网站建设需要懂英语吗目录 一.数据库基本概念(理解) 1.数据 2.数据库 二.常用的数据的数据库(了解) 1.大型数据库 2.中型数据库 3.小型数据库 三.基于嵌入式的数据库(了解) 四.SQLite基础(了解)…

目录

一.数据库基本概念(理解)

1.数据

2.数据库

二.常用的数据的数据库(了解)

1.大型数据库

2.中型数据库

3.小型数据库

三.基于嵌入式的数据库(了解)

四.SQLite基础(了解)

五.创建数据库(熟练)

1.手工创建

2.代码创建

六.SQLite编程接口

七.代码示例(学生管理系统)

八.水果店铺管理系统


一.数据库基本概念(理解

1.数据

        能够输入计算机并能够计算机程序识别和处理的信息集合。(不只是数字)

2.数据库

        数据库是在数据库管理系统管理和控制之下,存放在存储介质上的数据集合。

二.常用的数据的数据库(了解)

1.大型数据库

        Oracle公司是最早开发关系数据库的厂商之一,其产品支持最广泛的操作系统平台。目前Oracle关系数据库产品的市场占有率名列前茅。 IBM 的DB2是第一个具备网上功能的多媒体关系数据库管理系统,支持包Linux在内的一系列平台。

2.中型数据库

        Server是微软开发的数据库产品,主要支持windows平台。

3.小型数据库

        mySQL是一个小型关系型数据库管理系统,开发者为瑞典MySQL AB公司,2008年被Sun公司收购,开放源码。

        

三.基于嵌入式的数据库(了解)

        基于嵌入式Linux的数据库主要有SQLite, Firebird, Berkeley DB, eXtremeDB

        Firebird是关系型数据库,功能强大,支持存储过程、SQL兼容等

        SQLite关系型数据库,体积小,支持ACID事务

        Berkeley DB中并没有数据库服务器的概念,它的程序库直接链接到应用程序中

        eXtremeDB是内存数据库,运行效率高

四.SQLite基础(了解)

        SQLite的源代码是C,其源代码完全开放。SQLite第一个Alpha版本诞生于2000年5月。 他是一个轻量级的嵌入式数据库。

SQLite有以下特性:

         零配置一无需安装和管理配置;

        储存在单一磁盘文件中的一个完整的数据库;

        数据库文件可以在不同字节顺序的机器间自由共享;

        支持数据库大小至2TB;

        足够小,全部源码大致3万行c代码,250KB;

        比目前流行的大多数数据库对数据的操作要快;

五.创建数据库(熟练)

1.手工创建

        使用SQLite3工具,通过手工输入SQL命令行完成数据库创建. 用户在Linux的命令行界面中输入SQLite3可启动SQLite3工具

       数据库的安装

 sudo dpkg -i  *.deb  //本地安装包安装sudo apt-get install sqlite3  //在线安装

        数据库常用命令

        (1) 系统命令都以“ . ”开头

.exit //退出
.quit //退出
.table //查看表
.schema <table_name> //查看表的结构 
.help //显示所有命令
.database //显示当前打开的数据库文件

打开数据库文件 

在终端下运行sqlite3   <*.db>,出现如下提示符
SQLite  version  3.7.2
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite>
<*.db> 是要打开的数据库文件。若该文件不存在,则自动创建

         (2)sql执行语句,都以“ ;”结尾

创建一张表

create  table  <table_name>  (f1  type1, f2  type2,…);crerate table stuinfo(id integer ,name char ,age intger,score float);

插入一条记录 

insert  into  <table_name>  values (value1, value2,…);insert into stuinfo values(1001, 'zhangsan', 18, 80);
insert into stuinfo (id, name, score) values(1002, 'lisi', 90);

 查看数据库记录(where后面是条件)

select  *  from  <table_name>  where  <expression>;select * from stuinfo;
select * from stuinfo where score = 80;
select * from stuinfo where score = 80 and name= 'zhangsan';
select * from stuinfo where score = 80 or name='wangwu';
select name,score from stuinfo;  查询指定的字段
select * from stuinfo where score >= 85 and score < 90;

 删除一条记录

sqlite>delete  from  <table_name>  where  <expression>;delete from stuinfo where id=1003 and name='zhangsan';

更新一条记录 

sqlite>update  <table_name>  set  <f1=value1>, <f2=value2>… where<expression>;  update stuinfo set age=20 where id=1003;
update stuinfo set age=30, score = 82 where id=1003;

 删除一张表

drop  table  <table_name>drop table stuinfo;

 增加一列

alter table <table> add column <field> <type> default  …; alter table stuinfo add column sex char;

 删除一列(通过创建新的表来删除)

create table stu as select id, name, score from stuinfo;
drop table stuinfo;
alter table stu rename to stuinfo;

2.代码创建

        在程序运行过程中,当需要进行数据库操作时,应用程序会首先尝试打开数据库,此时如果数据库并不存在,程序则会自动建立数据库,然后再打开数据库

六.SQLite编程接口

        1.打开(创建)sqlite数据库

int   sqlite3_open(char  *path,   sqlite3 **db);path:数据库文件路径(数据库名称)
db:指向sqlite句柄的指针
返回值:成功返回0,失败返回错误码(非零值)

        2.关闭sqlite数据库       

int   sqlite3_close(sqlite3 *db);返回值:成功返回0,失败返回错误码

        3.得到错误信息的描述

const  char  *sqlite3_errmg(sqlite3 *db);         
返回值:返回错误信息

        4.执行SQL语句操作 

Int sqlite3_exec(
sqlite3 *db,
const  char  *sql, 
sqlite3_callback callback, 
void *, char **errmsg
);db:数据库句柄
sql:SQL语句
callback:回调函数
errmsg:错误信息指针的地址
返回值:成功返回0,失败返回错误码/* Callback function */
功能:查询语句执行之后,会回调此函数
查询回调函数:int (*callback)(void* arg,int ncolumns ,char** f_value,char** f_name);参数:arg   接收sqlite3_exec 传递来的参数ncolumns 列数(记录中包含的字段数目)f_value 列的值的地址(包含每个字段值的指针数组)f_name   列的名称(包含每个字段名称的指针数组)
返回值:成功返回0,失败返回-1

        5. 不使用回调函数执行SQL操作查询

不使用回调函数执行SQL语句
int   sqlite3_get_table(sqlite3 *db, const  char  *sql,  char ***resultp,  int*nrow,  int *ncolumn, char **errmsg);db:数据库句柄
sql:SQL语句
resultp:用来指向sql执行结果的指针
nrow:满足条件的记录的数目
ncolumn:每条记录包含的字段数目
errmsg:错误信息指针的地址
返回值:成功返回0,失败返回错误码

七.代码示例(学生管理系统)

        管理学生的信息

八.水果店铺管理系统

        管理水果种类,重量,价格等信息和信息变动记录

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>
#include <time.h>#define  DATABASE  "fruit.db"
#define TABLES "fruit"
#define  N  128int do_insert(sqlite3 *db,char *buf);
int do_update_weight(sqlite3 *db,char *buf);
int do_update_price(sqlite3 *db);
int do_query(sqlite3 *db);
int callback(void *arg, int f_num, char ** f_value, char ** f_name);int main(int argc, const char *argv[])
{sqlite3 *db;char *errmsg;int n;char sql[128] = {};char buf[128] = {};time_t t;struct tm *tp;if(sqlite3_open(DATABASE, &db) != SQLITE_OK){printf("%s\n", sqlite3_errmsg(db));return -1;}else{printf("open DATABASE success.\n");}sprintf(sql,"create table if not exists '%s' (id integer primary key autoincrement,name char,weight float,price float,time char);",TABLES);if(sqlite3_exec(db, sql,NULL, NULL, &errmsg) != SQLITE_OK){printf("%s\n", errmsg);}else{printf("Create or open table success.\n");}time(&t);tp = localtime(&t);sprintf(buf,"%d-%02d-%02d %02d:%02d:%02d\n",tp->tm_year+1900, tp->tm_mon+1,tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);printf("%s",buf);while(1){puts("-----------------------------------------");do_query(db);puts("-----------------------------------------");puts("");printf("********************************************\n");printf("1: insert 插入  2:query 查询 3:trade 交易 4:update 更新 5:quit 退出系统\n");printf("********************************************\n");printf("Please select:");scanf("%d", &n);switch(n){case 1:do_insert(db,buf);break;case 2:do_query(db);break;case 3:do_update_weight(db,buf);break;case 4:do_update_price(db);break;case 5:printf("main exit.\n");sqlite3_close(db);exit(0);break;default :printf("Invalid data n.\n");}}return 0;
}int do_insert(sqlite3 *db,char *buf)
{char name[32] = {};float weight;float price;char sql[N] = {};char *errmsg;printf("Input fruit name:");scanf("%s", name);getchar();printf("Input weight:");scanf("%f", &weight);printf("Input price:");scanf("%f", &price);sprintf(sql, "insert into '%s' (name,weight,price,time)values('%s', '%.3f', '%.3f','%s')",TABLES, name, weight, price,buf);if(sqlite3_exec(db, sql, NULL, NULL, &errmsg) != SQLITE_OK){printf("%s\n", errmsg);}else{printf("Insert done.\n");}return 0;
}int do_update_weight(sqlite3 *db,char *buf)
{int id;char sql[N] = {};char *errmsg;float weight;printf("Input id:");scanf("%d", &id);printf("Input weight:");scanf("%f", &weight);sprintf(sql, "update '%s' set weight='%f',time='%s' where id=%d",TABLES, weight,buf,id);if(sqlite3_exec(db, sql, NULL, NULL, &errmsg) != SQLITE_OK){printf("%s\n", errmsg);}else{printf("Delete done.\n");}return 0;
}int do_update_price(sqlite3 *db)
{float price;int id;char sql[N] = {};char *errmsg;printf("Input id:");scanf("%d", &id);printf("Input alter price:");scanf("%f", &price);sprintf(sql, "update '%s' set price='%f' where id=%d",TABLES , price,id);if(sqlite3_exec(db, sql, NULL, NULL, &errmsg) != SQLITE_OK){printf("%s\n", errmsg);}else{printf("update done.\n");}return 0;
}int callback(void *arg, int f_num, char ** f_value, char ** f_name)
{int i = 0;for(i = 0; i < f_num; i++){//	printf("%-8s %s", f_value[i], f_name[i]);printf("%-8s", f_value[i]);}putchar(10);puts("-----------------------------------------");return 0;
}int do_query(sqlite3 *db)
{char *errmsg;char sql[N] = {};sprintf(sql,"select * from '%s';",TABLES);if(sqlite3_exec(db, sql, callback,NULL , &errmsg) != SQLITE_OK){printf("%s", errmsg);}else{printf("select done.\n");}return 0;
}

http://www.hrbkazy.com/news/19145.html

相关文章:

  • 小米路由器3 做网站seo优化软件免费
  • 企业建设网站流程图品牌策略
  • 服务器域名已有做网站成人技能培训
  • 家庭网做网站上海百度关键词优化公司
  • 云梦做网站的优势百度推广介绍
  • 直播带货代运营公司杭州seo推广服务
  • 思途建站建站系统软件有哪些
  • 网站开发 h5简单的个人主页网站制作
  • 东莞大朗疫情最新消息windows优化大师手机版
  • 梧州论坛蒙山奇零seo赚钱培训
  • 做网站至少多少钱精准客源app
  • wordpress支持latex湖南专业关键词优化服务水平
  • 哪个网站查企业信息免费槐荫区网络营销seo
  • 新闻头条免费下载安装seo关键词外包
  • 做网站需要写那些xmind聊城优化seo
  • 学ui的网站软件外包网站
  • wordpress500错误解决西安seo关键词推广
  • wordpress 搜索 分类北京云无限优化
  • wordpress简介企业做网站seo优化
  • 唐山做网站口碑好的世界新闻最新消息
  • 商城网站素材网络游戏推广员
  • 网站开发制作费入会计科目seo和sem哪个工资高
  • 网站图怎么做企业网站seo贵不贵
  • 做门户网站需要学什么软件产品优化是什么意思
  • 郑州网站建设公司百度指数平台
  • jiasale wordpress东莞seo优化公司
  • 传业做微采商城网站商丘网络推广公司
  • 移动端网站开发视频广告外链购买交易平台
  • 做兼职编辑的网站品牌软文
  • 松江信息科技有限公司网站百度一下百度官网