mysql的c++封装类

CppMySQL是一个用C++编写的MySQL数据库库的封装,提供了连接、查询、事务处理等功能。该库包括两个主要类:CppMySQLQuery用于执行查询并获取结果,CppMySQL3DB负责数据库的打开、关闭及各种操作。源代码包含了详细的注释和使用示例。
摘要由CSDN通过智能技术生成
//.h

// CppMysql - A C++ wrapper around the mysql database library.
//
// Copyright (c) 2009 Rob Groves. All Rights Reserved. lizp.net@gmail.com
//
// Permission to use, copy, modify, and distribute this software and its
// documentation for any purpose, without fee, and without a written
// agreement, is hereby granted, provided that the above copyright notice,
// this paragraph and the following two paragraphs appear in all copies,
// modifications, and distributions.
//
// IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
// PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
// EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
// ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO OBLIGATION
// TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
//
// u can use it for anything, but u must show the source
// frome http://blog.csdn.net/bat603
// by ben
// if u find some questions, please tell me with email
//
// V1.0  18/09/2009 -Initial Version for cppmysql

#ifndef _CPP_MYSQL_1_H_
#define _CPP_MYSQL_1_H_
#include "mysql.h"

typedef unsigned int u_int;
typedef unsigned long u_long;
typedef MYSQL*  DB_HANDLE;
class CppMySQL3DB;
class CppMySQLQuery
{
 friend class CppMySQL3DB;
public:
    CppMySQLQuery();
 //当执行拷贝构造函数后,括号里的类已经无效,不能再使用
    CppMySQLQuery(CppMySQLQuery& rQuery);
 //当执行赋值构造函数后,=右边的类已经无效,不能再使用
    CppMySQLQuery& operator=(CppMySQLQuery& rQuery);
    virtual ~CppMySQLQuery();
 u_long numRow();//多少行
    int numFields();//多少列
    int fieldIndex(const char* szField);
 //0...n-1列
    const char* fieldName(int nCol);
 //   const char* fieldDeclType(int nCol);
 //   int fieldDataType(int nCol);
 u_long seekRow(u_long offerset);
    int getIntField(int nField, int nNullValue=0);
    int getIntField(const char* szField, int nNullValue=0);
    double getFloatField(int nField, double fNullValue=0.0);
    double getFloatField(const char* szField, double fNullValue=0.0);
 //0...n-1列
    const char* getStringField(int nField, const char* szNullValue="");
    const char* getStringField(const char* szField, const char* szNullValue="");
    const unsigned char* getBlobField(int nField, int& nLen);
    const unsigned char* getBlobField(const char* szField, int& nLen);
    bool fieldIsNull(int nField);
    bool fieldIsNull(const char* szField);
    bool eof();
    void nextRow();
    void finalize();
private:
 void freeRes();
    void checkVM();
private:
 MYSQL_RES*  _mysql_res;
 MYSQL_FIELD* _field;
 MYSQL_ROW  _row;
 u_long   _row_count;
 u_int   _field_count; </
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值