📄 sqldatabase.h
字号:
//
#ifndef _SQLDATABASE_H__
#define _SQLDATABASE_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include <windows.h>
#include <sql.h>
#include <string>
using namespace std;
class CSQLException
{
public:
CSQLException() :m_nRetCode( 0 ) {;}
CSQLException( SQLRETURN r ) { m_nRetCode = r; }
~CSQLException() {;}
SQLRETURN m_nRetCode;
string m_strError;
string m_strStateNativeOrigin;
string _statement;
void Delete() { delete this; }
private:
CSQLException( const CSQLException& o ) {;}
//operator = ( CSQLException& ) {;}
};
class CSQLDatabase {
public:
CSQLDatabase();
virtual ~CSQLDatabase();
bool SQLConnect( const char* dsn, const char* user="", const char* password="" );
bool Open( const char* dsn, const char* user="", const char* password="" );
bool OpenEx( const char* dsn, const char* user="", const char* password="" );
bool Close();
bool ExecuteSQL( const char* a_szStmt );
bool IsOpen() { return _isOpen; }
void ThrowError( SQLSMALLINT handleType=SQL_HANDLE_STMT );
const char* GetSQLString( const char* stmt, const char* sDefault="" );
int GetSQLInt( const char* stmt, int nDefault=0 );
SQLRETURN GetRetCode() { return _rc; }
bool SupportsTransactions(); // supports ROLLBACK and COMMIT
void SetAutoCommit( bool tf ); // makes all transactions COMMIT immediately
bool GetAutoCommit();
bool Commit();
bool Rollback();
SQLRETURN _rc; // void*
SQLHENV _henv; // void*
SQLHDBC _hdbc; // void*
HSTMT _hstmt; // void*
private:
bool _isOpen;
string _dsn;
string _user;
string _pswd;
string _sResult; // for GetSQL... functions
bool _autoCommit;
};
#endif // !defined _SQLDATABASE_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -