基于Linux的多功能聊天室
作者:网络转载 发布时间:[ 2015/2/4 17:58:55 ] 推荐标签:Linux 操作系统
rc=sqlite3_exec(db,sql,NULL,NULL,errmsg);
if(rc==SQLITE_OK)
{
return 1;
}
else
{
return 0;
}
}
int update_user(sqlite3*db,char**errmsg,char*name,char*toname)//修改密码
{
int rc;
char sql[1024];
sprintf(sql,"update user set name='%s'where name='%s'",toname,name);
rc=sqlite3_exec(db,sql,NULL,NULL,errmsg);
if(rc==SQLITE_OK)
{
return 1;
}
else
{
return 0;
}
}
int update_db_data(sqlite3*db,char**errmsg,char*name,char*toname)//修改密码
{
int rc1;
int rc2;
char sql[1024];
sprintf(sql,"update data set name='%s'where name='%s'",toname,name);
rc1=sqlite3_exec(db,sql,NULL,NULL,errmsg);
memset(sql,0,1024);
sprintf(sql,"update data set toname='%s'where toname='%s'",toname,name);
rc2=sqlite3_exec(db,sql,NULL,NULL,errmsg);
if(rc1==SQLITE_OK&&rc2==SQLITE_OK)
{
return 1;
}
else
{
return 0;
}
}
int update_flag(sqlite3*db,char**errmsg,char*name,int flag)//禁言解禁操作
{
int rc;
char sql[1024];
sprintf(sql,"update online set flag=%d where name='%s'",flag,name);
rc=sqlite3_exec(db,sql,NULL,NULL,errmsg);
if(rc==SQLITE_OK)
{
return 1;
}
else
{
return 0;
}
}
int delete_user(sqlite3*db,char**errmsg,char*name)//注销用户
{
int rc;
char sql[1024];
sprintf(sql,"delete from user where name='%s'",name);
rc=sqlite3_exec(db,sql,NULL,NULL,errmsg);
if(rc==SQLITE_OK)
{
return 1;
}
else
{
return 0;
}
}
void read_online_all(sqlite3*db,char**errmsg,vpChat temp)//向在线用户发送信息
{
int rc;
sqlite3_stmt*stmt=NULL;
rc=sqlite3_prepare(db,"select*from online",-1,&stmt,0);
is_sqlite_ok(rc);
rc=sqlite3_step(stmt);
int userflag=1;
while(rc==SQLITE_ROW)
{
my_strcpy(temp->msg,sqlite3_column_text(stmt,1));
mywrite(temp);
sleep(1);
rc=sqlite3_step(stmt);
}
}
void read_data(sqlite3*db,char**errmsg,vpChat temp)//向在线用户发送信息
{
int rc;
char name[80];
char toname[80];
sqlite3_stmt*stmt=NULL;
rc=sqlite3_prepare(db,"select*from data",-1,&stmt,0);
is_sqlite_ok(rc);
rc=sqlite3_step(stmt);
int userflag=1;
while(rc==SQLITE_ROW)
{
my_strcpy(name,sqlite3_column_text(stmt,2));
my_strcpy(toname,sqlite3_column_text(stmt,3));
if( my_strcmp(temp->name,name)==0)
{
strcat(temp->msg,"你");
strcat(temp->msg,"给");
strcat(temp->msg,toname);
strcat(temp->msg,"发了");
strcat(temp->msg,sqlite3_column_text(stmt,4));
strcat(temp->msg," ");
my_strcpy(temp->time,sqlite3_column_text(stmt,1));
mywrite(temp);
memset(temp->msg,0,sizeof(temp->msg));
sleep(1);
}
if(my_strcmp(temp->name,toname)==0)
{
strcat(temp->msg,toname);
strcat(temp->msg,"给你发了");
strcat(temp->msg,sqlite3_column_text(stmt,4));
strcat(temp->msg," ");
my_strcpy(temp->time,sqlite3_column_text(stmt,1));
mywrite(temp);
memset(temp->msg,0,sizeof(temp->msg));
sleep(1);
}
rc=sqlite3_step(stmt);
}
}
这个是数据库的各类操作呢!
那么它的头文件估计也是函数申明
void is_sqlite(int rc);//测试数据库
void is_malloc_ok(vpChat*list);
void is_sqlite_ok(int rc);
void open_db(sqlite3**db);//打开数据库
void creat_user_db(sqlite3*db,char**errmsg);//建立user数据表
void creat_data_db(sqlite3*db,char**errmsg);//建立data数据表
void creat_online_db(sqlite3*db,char**errmsg);//建立online数据表
void creat_server_db(sqlite3*db,char**errmsg);//建立server数据表
void insert_server_db(sqlite3*db,char*time,char**errmsg);
void read_db_ok(sqlite3*db,char*errmsg,char*tablename);
void delete_clean_db(sqlite3*db,char*tablename,char**errmsg);
int read_online_fd(sqlite3*db,char**errmsg,char*user);
int read_online_flag(sqlite3*db,char**errmsg,char*user);
void write_online_all(sqlite3*db,char**errmsg,vpChat temp);
int update_passwd(sqlite3*db,char**errmsg,char*name,char*passwd);
void insert_data_db(sqlite3*db,char**errmsg,char*time,vpChat temp);
int update_flag(sqlite3*db,char**errmsg,char*name,int flag);
int delete_user(sqlite3*db,char**errmsg,char*name);
void read_online_all(sqlite3*db,char**errmsg,vpChat temp);
void read_data(sqlite3*db,char**errmsg,vpChat temp);
int update_user(sqlite3*db,char**errmsg,char*name,char*toname);
int update_db_data(sqlite3*db,char**errmsg,char*name,char*toname);
干货来了,string.c
很明显是我为了面试准备所写的函数!经测是有效的!
#include"data.h"
int my_strlen(const char*str)
{
int len;
while(*str++!='
