为什么不用txt代替数据库

为什么不用txt代替数据库,第1张

txt文本文件, 和 数据库 的共同点, 就是都能存储数据.  但是使用范围却有很大不同.

txt在部分情景下是可以替代数据库,:

数据量少, 无安全性要求, 不考虑并发, 速度要求不高, 数据不怕丢失和损坏。

比如 软件使用的次数, 皮肤外观, 默认的字体等,  可以使用文本文件等来做配置文件. 如下图,

窗口音效, 按钮点击音效 等, 在文本文件里存储的样式如下

soundwin=1

soundclick=0

数据库的优势在于: 数据存储量大, 高效, 检索速度快,  可靠,数据控制能力强 。

一条SQL语句能做的事情, 如果是通过 *** 作文本,可能要编写大量的代码才能实现,并且速度还慢得很...

如下图。 左边是数据库存储的数据 ,上万条数据, 并且每小时递增上千条数据,右边是文本文件存的数据。

将这个登录表文件,用一条链表来管理,实现功能:

bool chk_people(string id)

bool chk_people(string id,string pwd)

bool add_people(string id,string pwd)

bool del_people(string id)

bool read_file(string filename)

bool write_file(string filename)

链表中的数据可以手动添加几个,也可以从文件读入,总之先初始化链表,然后让用户 *** 作。

每一次将用户的 *** 作都先保存在链表里,在用户退出时就把链表中的数据全部写入到外部文件,将文件覆盖就行了,以后读入时就是新的内容了。

答应过你,把源码贴上来,调试运行过,得到预期结果

#include <iostream>

#include <fstream>

#include <string>

using namespace std

struct guest{

string id

string pwd

guest(string i,string p):id(i),pwd(p){next = NULL}

guest* next

}

class guest_mgr{

private:

guest* head

public:

guest_mgr()

bool chk_people(string id)

bool chk_people(string id,string pwd)

bool add_people(string id,string pwd)

bool del_people(string id)

bool read_file(string filename)

bool write_file(string filename)

void print_people()

~guest_mgr()

}

guest_mgr::guest_mgr(){

head = new guest("admin","123")

head->next = NULL

}

bool guest_mgr::read_file(string filename){

ifstream inobj(filename.c_str())

if(!inobj){

cout<<"open file failed.\n"

return false

}

guest *t,*p

string sid,spwd

p = head

while(!inobj.eof()){

inobj>>sid>>spwd

t = new guest(sid,spwd)

p->next = t

p = t

}

t->next = NULL

return true

}

bool guest_mgr::write_file(string filename){

ofstream outobj(filename.c_str())

if(!outobj){

cout<<"file open failed."

return false

}

guest* p = head

while(NULL!=p){

outobj<<p->id<<" "<<p->pwd<<"\n"

p=p->next

}

return true

}

bool guest_mgr::add_people(string id,string pwd){

if(NULL==head)

return false

guest* p = head

while(NULL!=p->next){

p = p->next

}

guest* newguest = new guest(id,pwd)

p->next = newguest

newguest->next = NULL

return true

}

bool guest_mgr::chk_people(string id){

if(NULL==head)

return false

guest *p = head

while(NULL!=p->next&&id!=p->id){

p = p->next

}

if(NULL!=p->next){

return true

}

else if(NULL==p->next&&id==p->id)

return true

return false

}

bool guest_mgr::chk_people(string id,string pwd){

if(NULL==head)

return false

guest *p = head

while(NULL!=p->next&&id!=p->id){

p = p->next

}

if(NULL!=p->next){

if(pwd==p->pwd)

return true

}

else if(NULL==p->next&&id==p->id)

if(pwd==p->pwd)

return true

return false

}

bool guest_mgr::del_people(string id){

if(chk_people(id)){

guest *p = head

guest *pre = p

while(NULL!=p->next&&id!=p->id){

pre = p

p = p->next

}

if(NULL!=p->next){

pre->next = p->next

delete p

return true

}

else if(NULL==p->next&&id==p->id){

if(p!=head){

pre->next = NULL

delete p

return true

}

}

}

return false

}

void guest_mgr::print_people(){

if(NULL==head){

cout<<"no guest in the list.\n"

return

}

guest* p = head

while(NULL!=p){

cout<<p->id<<" "<<p->pwd<<"\n"

p=p->next

}

cout<<endl

}

///////////////////////////////菜单//////////////////////////////

guest_mgr* mylist//在菜单函数中要用到,不要移动它

string fn = "data.txt"//同上

void login(){

cout<<"\n-------------------Login----------------------\n"

string id,pwd

cout<<"ID:"

cin>>id

if(mylist->chk_people(id)){

cout<<"\nPassword:"

cin>>pwd

if(mylist->chk_people(id,pwd)){

cout<<"\nlogin successful.\n"

}

else{

cout<<"sorry,your password is wrong.\n"

}

}

else{

cout<<"the id is not exsit.\n"

}

cout<<"\n-------------------Login----------------------\n"

}

void add(){

cout<<"\n-------------------Add Guest----------------------\n"

string id,pwd

cout<<"ID:"

cin>>id

cout<<"\nPassword:"

cin>>pwd

if(mylist->add_people(id,pwd)){

cout<<"\nadd guest successful.\n"

}

else{

cout<<"sorry,the system is wrong.\n"

}

cout<<"\n-------------------Add Guest----------------------\n"

}

void del(){

cout<<"\n-----------------Delete Guest--------------------\n"

string id

cout<<"ID:"

cin>>id

if(mylist->chk_people(id)){

char c

cout<<"\nare you sure to delete the guest with ID "<<id<<" .(Y/N)"<<endl

cin>>c

if(c=='y'||c=='Y'){

if(mylist->del_people(id))

cout<<"delete guest successful.\n"

else

cout<<"sorry,the system is wrong.\n"

}

}

else{

cout<<"\nsorry,the guest "<<id<<" is not exsit.\n"

}

cout<<"\n-----------------Delete Guest--------------------\n"

}

void menu(){

int c

cout<<"\n****************************Main Menu****************************\n"

cout<<"1.登录\t2.添加用户\t3.删除用户\t4.打印用户清单\t5.退出"

cout<<"\n****************************Main Menu****************************\n"

cin>>c

switch(c){

case 1:login()break

case 2:add()break

case 3:del()break

case 4:mylist->print_people()break

default:mylist->write_file(fn)exit(0)

}

}

void main(){

mylist = new guest_mgr()

mylist->read_file(fn)

while(1)

menu()

cout<<endl

}

1.数据脱敏

数据脱敏是保证数据安全的最基本的手段,脱敏方法有很多,最常用的就是使用可逆加密算法,对入仓每一个敏感字段都需要加密。比如手机号,邮箱,身份z号,yhk号等信息

2.数据权限控制

需要开发一套完善的数据权限控制体系,最好是能做到字段级别,有些表无关人员是不需要查询的,所以不需要任何权限,有些表部分人需要查询,除数据工程师外,其他人均需要通过OA流程进行权限审批,需要查看哪些表的哪些字段,为什么需要这个权限等信息都需要审批存档。

3.程序检查

有些字段明显是敏感数据,比如身份z号,手机号等信息,但是业务库并没有加密,而且从字段名来看,也很难看出是敏感信息,所以抽取到数据仓库后需要使用程序去统一检测是否有敏感数据,然后根据检测结果让对应负责人去确认是否真的是敏感字段,是否需要加密等。

4.流程化 *** 作

流程化主要是体现在公司内部取数或者外部项目数据同步,取数的时候如果数据量很大或者包含了敏感信息,是需要提OA 审批流程的,让大家知道谁要取这些数据,取这些数据的意义在哪,出了问题可以回溯,快速定位到责任人。开发外部项目的时候,不同公司之间的数据同步,是需要由甲方出具同意书的,否则的话风险太大。

5.敏感SQL实时审查及 *** 作日志分析

及时发现敏感sql的执行并询问责任人,事后分析 *** 作日志,查出有问题的 *** 作。

6.部门重视数据安全

把数据安全当做一项KPI去考核,让大家积极的参与到数据安全管理当中去。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10060007.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存