闲来无事,花了两天时间写了一个功能还不太完善的Mysql控制台,因为自己也是才学C++不久,程序写的比较烂,有很多的BUG,只是记录下.
测试平台:
操作系统: GNU/Linux 编辑器:vi 编译器:g++
系统上需要安装好MySQL。我的是从源码编译安装的,因此安装到了:/usr/local/lnmp/mysql 目录中
源码结构:
----src
----include
--------fields.h //登陆参数类声明
--------dbhelper.h //数据库操作类声明
-----dbhelper.cpp //数据库操作类的实现
------fields.cpp //登陆参数类的实现
-------main.cpp //主程序
(1).登陆参数类声明 (include/fields.h)源码:
#ifndef _FIELDS_H_
#define _FIELDS_H_
#include
#include
using namespace std;
class Fields
{
private:
char *username; //用户名
char *password; //密码
char *server; //服务器
char *defaultDb; //默认数据库
unsigned int port; //端口号
char *unix_socket; //套接字,默认为NULL
unsigned int flag; //客户端标志默认为0
public:
Fields(char *usr,char *pass,unsigned int pt=3306,char *server="localhost",
char *defaultDb="test",char *socket=NULL,unsigned int f=0);
Fields(const Fields & f);
virtual ~Fields();
Fields & operator=(const Fields &f);
/*设置*/
bool setUser(char *user);
bool setPass(char *pass);
bool setServer(char *server="localhost");
bool setDefaultDb(char *db="test");
bool setPort(unsigned int pt=3306);
bool setSocket(char *socket=NULL);
bool setFlag(unsigned int flag=0);
/*获取*/
char *getUser()const;
char *getPass()const;
char *getServer()const;
char *getDefaultDb()const;
unsigned int getPort()const;
char *getSocket()const;
unsigned int getFlag()const;
/*友元<
friend ostream & operator<
};
#endif