⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odbcset.h

📁 用ODBC写的数据库接口,支持SQlserver,mysql
💻 H
字号:
// ODBCSet.h: interface for the CODBCSet class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ODBCSET_H__B87857A0_A997_48BD_9142_AD86790D7426__INCLUDED_)
#define AFX_ODBCSET_H__B87857A0_A997_48BD_9142_AD86790D7426__INCLUDED_

#include <windows.h>
#define MAX_FNAME_LEN 256
//#include "MyODBC.h"	// Added by ClassView
//#if _MSC_VER > 1000
//#pragma once
//#endif // _MSC_VER > 1000

typedef struct 
{
	char	name[MAX_FNAME_LEN];
	short	datatype,c_datatype;
	unsigned long maxlength;
} COL_DATAFMT_ODBC;//每一字段的描述,名称,类型,长度

typedef struct
{
	char*	value;
	long 	valuelen;
}COL_DATA_ODBC;	//每一列的内容,一个结构代表了一列的所有数据

/*typedef struct
{
	char* value;
	long length;
}CELL_DATA_ODBC;//每个单元格的内容
*/
void  UpperStr(const char *in,char *out);


class CODBCSet
{
public:
	int m_cols;			//查询返回列数
    long m_rows;

//    inline int m_currcol;

	COL_DATAFMT_ODBC *m_coldatafmt;
	COL_DATA_ODBC* m_coldata;
//    CELL_DATA_ODBC m_celldata;
public:
	CODBCSet();
	virtual ~CODBCSet();
	int const GetCols();
	int const GetRows();
	void Empty();
	COL_DATAFMT_ODBC *GetColInfo(int i);
	BOOL IsEmpty();
/*	class Row
	{
		CODBCSet& m_recordset;
		int m_iRow;
	public:
		inline Row(CODBCSet& recordset, int iRow):m_recordset(recordset), m_iRow(iRow){}

		inline const CELL_DATA_ODBC operator[](int iCol)const
		{ return m_recordset( iCol, m_iRow);}

		inline const CELL_DATA_ODBC operator[](LPCSTR strColName)const
		{ return m_recordset(strColName, m_iRow);}

	};//用Row来表示CRecordSet中的每一行,
*/
//	inline const Row operator[](int iRow)
//	{ return Row(*this, iRow); }//得到批定的行

	inline const COL_DATA_ODBC *operator [](int iCol) const//得到指定行和列的值
	{
//		CELL_DATA_ODBC celldata;
//		celldata.value = m_coldata[iCol].value + iRow*m_coldatafmt[iCol].maxlength;
		// oracle:
		//              indicator == -1, The selected value is null, and the value of
		//                                         the output variable is unchanged.
		//              indicator  == 0, Oracle assigned an intact value to the host variable.
		//              indicator  > 0 ,    The length of the item is greater than the length of
		//                                         the output variable; the item has been truncated. The positive value
		//                                         returned in the indicator variable is the actual length before truncation.

        //m_celldata.value = m_coldata[iCol].value;
		//m_celldata.length = m_coldata[iCol].valuelen[iRow];
		//m_celldata.value[celldata.length] = 0;
		return &m_coldata[iCol];
	}

	inline const COL_DATA_ODBC *operator [](LPCSTR strColName) const
	{
		//CELL_DATA_ODBC celldata;
        char szColName[MAX_FNAME_LEN];
        int m_currcol;
        UpperStr(strColName,szColName);
		for( m_currcol = 0; m_currcol < m_cols; m_currcol++  )
		{
			if( strcmp(m_coldatafmt[m_currcol].name, szColName)== 0 )
			{
				break;
			}
		}

		if( m_currcol >= m_cols )
		{ // not found column according its name
			//celldata.value = 0;  celldata.length = 0;
            return NULL;
		}
		else 
		{			
			/*celldata.value = m_coldata[iCol].value + iRow*m_coldatafmt[iCol].maxlength;
			celldata.length = m_coldata[iCol].valuelen[iRow];
			celldata.value[celldata.length] = 0;*/
		    return &m_coldata[m_currcol];
		}
//		return celldata;
	}

	inline const COL_DATA_ODBC *GetValueByName(LPCSTR strColName,int &m_currcol) const
	{
		//CELL_DATA_ODBC celldata;
        char szColName[MAX_FNAME_LEN];
//        int m_currcol;
        UpperStr(strColName,szColName);
		for( m_currcol = 0; m_currcol < m_cols; m_currcol++  )
		{
			if( strcmp(m_coldatafmt[m_currcol].name, szColName)== 0 )
			{
				break;
			}
		}

		if( m_currcol >= m_cols )
		{ // not found column according its name
			//celldata.value = 0;  celldata.length = 0;
            return NULL;
		}
		else
		{
			/*celldata.value = m_coldata[iCol].value + iRow*m_coldatafmt[iCol].maxlength;
			celldata.length = m_coldata[iCol].valuelen[iRow];
			celldata.value[celldata.length] = 0;*/
		    return &m_coldata[m_currcol];
		}
    }
};

#endif // !defined(AFX_ODBCSET_H__B87857A0_A997_48BD_9142_AD86790D7426__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -