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

📄 mydb.h

📁 pimserver是syncml_vc开发包的服务器实例
💻 H
字号:

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the MYDB_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// MYDB_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef MYDB_EXPORTS
#define MYDB_API __declspec(dllexport)
#else
#define MYDB_API __declspec(dllimport)
#endif
#pragma once
#include <sql.h>        // core
#include <sqlext.h>     // extensions
#define COLLEN  256
#define CELLLEN  1024

MYDB_API typedef struct 
{
	TCHAR	name[COLLEN];
	short	datatype;
} COL_DATAFMT;//每一字段的描述,名称,类型,长度

MYDB_API typedef struct  
{
	TCHAR value[CELLLEN];
}CELL_DATA;//每个单元格的内容

MYDB_API typedef struct
{
	CELL_DATA celldata;
}COL_DATA;	//每一列的内容,一个结构代表了一列的所有数据
class CMySet;
// This class is exported from the mydb.dll
class MYDB_API CMydb {
public:
	CMydb(void);

	virtual ~CMydb();
	BOOL IsOpen();
	BOOL ConnectDB(LPCTSTR szDSN,LPCTSTR szUser,LPCTSTR szPwd);
	BOOL CMydb::ReConnectDB();
	BOOL FetchData();
	BOOL PrepareSql(LPCTSTR cpSql, CMySet &rset);
	BOOL DisConnect();
	BOOL ExeSqlDirect(LPCTSTR cpSqlStmt);
	SQLSMALLINT    GetDefaultCType(LONG  iODBCType);
	UINT ConvertDataToChar();
	VOID BuildSqlError(SQLHSTMT &hstmt, int iHandleType ,TCHAR* strAlert);
	UINT GetAffectedRows();
	TCHAR* GetSqlError();
protected:
	SQLHENV m_henv;
	SQLHDBC m_hdbc;
	SQLHSTMT m_hstmt;
	SQLRETURN m_retcode;
	CMySet *m_pSet;
	TCHAR m_szSqlError[1024];
	LONG m_nAffectedRows;
	TCHAR m_szDsn[1024];
	TCHAR m_szUser[1024];
	TCHAR m_szPwd[1024];

	// TODO: add your methods here.
};

class MYDB_API CMySet  
{
public:
	UINT m_nCols;			//查询返回列数
	COL_DATAFMT* m_stColDataFmt;
	COL_DATA* m_stColData;
	CELL_DATA  m_stCellData;
public:
	CMySet();
	virtual ~CMySet();
	UINT const GetCols();
	TCHAR *GetFieldName(UINT index);
	TCHAR *GetFieldValueByName(TCHAR *sName);
	TCHAR *GetFieldValue(UINT index);
	VOID Empty();
	BOOL IsEmpty();
	/*
	class Row 
	{
		CMySet& m_recordset;
		int m_iRow;
	public:
		inline Row(CODBCSet& recordset, int iRow):m_recordset(recordset), m_iRow(iRow){}
	
		inline const CELL_DATA operator[](int iCol)const 
		{ return m_recordset( iCol, m_iRow);}
		
		inline const CELL_DATA operator[](LPCSTR strColName)const 
		{ return m_recordset(strColName, m_iRow);}
		
	};//用Row来表示CRecordSet中的每一行,

	inline const Row operator[](int iRow)
	{ return Row(*this, iRow); }//得到批定的行

	inline const CELL_DATA operator ()(int iCol, int iRow = 0)const//得到指定行和列的值
	{
		CELL_DATA celldata;
		sprintf(celldata.value,"%s",m_coldata+iRow*m_cols*100+iCol*100);
		return celldata;
	}

	inline const CELL_DATA operator ()(LPCSTR strColName, int iRow = 0)const 
	{
		CELL_DATA celldata;
		int iCol;
		for( iCol = 0; iCol < m_cols; iCol++  )
		{
			if( strcmp(m_coldatafmt[iCol].name, strColName)== 0 )
			{
				break;
			}
		}

		if( iCol >= m_cols )
		{ 
			sprintf(celldata.value,"%s","");  //celldata.length = 0;
		}
		else 
		{			
			sprintf(celldata.value,"%s",m_coldata+iRow*m_cols*100+iCol*100);
		}
		return celldata;
	}
	*/

	

};

⌨️ 快捷键说明

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