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

📄 vmodbcconnection.h

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 H
字号:
#ifndef ODBC_CONNECTION_H_INCLUDED
#define ODBC_CONNECTION_H_INCLUDED
/*****************************************************************************/
/*                              HEADER FILE                                  */
/*****************************************************************************/
/*
       $Archive:   $

      $Revision:   $
          $Date:   $
        $Author:   $

    Description:   Declaration of a database connection management class. 
                   Based on CDatabase, but without all the afx rigor-morol

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
/*****************************************************************************/


#include <vector>
#include <sql.h>
#include <sqlext.h>
#pragma comment( lib, "odbc32.lib" )
#pragma comment( lib, "odbccp32.lib" )

#include "VMString.h"

 
#define SQL_SETPOSUPDATES          0x0001
#define SQL_POSITIONEDSQL          0x0002
#define SQL_GDBOUND                0x0004
#define ODBC_CALL_WAIT( SQLFunc )  do{}while( ( nRetCode = (SQLFunc) ) == SQL_STILL_EXECUTING )


const int ciErrorMsgSize = 1024;


class VMODBCConnection
{
public:
  VMODBCConnection( void );

  enum DbOpenOptions
  {
    openExclusive   = 0x0001, // Not implemented
    openReadOnly    = 0x0002, // Open database read only
    useCursorLib    = 0x0004, // Use ODBC cursor lib
    noOdbcDialog    = 0x0008, // Don't display ODBC Connect dialog
    forceOdbcDialog = 0x0010, // Always display ODBC connect dialog
  };

  virtual bool Open( LPCTSTR lpszDSN, 
                     bool    bExclusive  = false,
                     bool    bReadonly   = false, 
                     LPCTSTR lpszConnect = "ODBC;",
                     bool bUseCursorLib  = true );

  virtual bool OpenEx( LPCTSTR lpszConnectString, DWORD dwOptions = 0 );
  virtual void Close( void );

  bool IsOpen( void )
  { 
    return( m_bIsOpen ); 
  };

  bool CanUpdate( void ) const;
  bool CanTransact( void ) const;

  VMString GetDatabaseName( void );
  const VMString& GetConnect( void ) const;

  bool GetVendorInfo( char* pchOutput, int iBufferLength );
  bool GetDbmsHostName( char* pchOutput, int iBufferLength );

  DWORD GetBookmarkPersistence( void ) const;
  int GetCursorCommitBehavior( void ) const;
  int GetCursorRollbackBehavior( void ) const;

  void SetLoginTimeout( DWORD dwSeconds, HSTMT hStmt = NULL );
  void SetQueryTimeout( DWORD dwSeconds, HSTMT hStmt = NULL );

  // transaction control
  bool BeginTrans( void );
  bool CommitTrans( void );
  bool Rollback( void );

  int  ExecuteSQLGetRowCount( LPCTSTR lpszSQL );
  void ExecuteSQL( LPCTSTR lpszSQL );

  void Cancel( void );

	// set special options
  //
  virtual void OnSetOptions( HSTMT hstmt );

  virtual ~VMODBCConnection( void );

  // general error check
  //
  virtual bool Check( RETCODE nRetCode );
  bool PASCAL CheckHstmt( RETCODE, HSTMT hstmt );

  virtual void BindParameters( HSTMT hstmt );

  void SetSynchronousMode( bool bSynchronous );
  bool Reconnect( void );

  void OnTimerEvent( UINT uiTimerID );

protected:
  HDBC m_hdbc;

  bool m_bStripTrailingSpaces;
  bool m_bIncRecordCountOnAdd;
  bool m_bAddForUpdate;
  char m_chIDQuoteChar;
  char m_reserved1[3];

  VMString m_oConnect;

  int   nRefCount;
  bool  m_bUpdatable;
  bool  m_bTransactions;
  SWORD m_nTransactionCapable;
  SWORD m_nCursorCommitBehavior;
  SWORD m_nCursorRollbackBehavior;
  DWORD m_dwUpdateOptions;
  DWORD m_dwBookmarkAttributes;   // cache driver bookmark persistence
  DWORD m_dwLoginTimeout;
  HSTMT m_hstmt;
  DWORD m_dwQueryTimeout;

  unsigned int m_uiReconnectWait;
  bool         m_bReconnectTimer;
  UCHAR        m_auchErrorMsg[ ciErrorMsgSize ];
  int          m_iReconnectAttempts;
  bool         m_bIsOpen;

  void ReplaceBrackets( LPTSTR lpchSQL );
  void AllocConnect( DWORD dwOptions );
  bool Connect( DWORD dwOptions );
  void VerifyConnect( void );
  void GetConnectInfo( void );
  void Free( void );
  RETCODE CheckForSQLErrors( RETCODE retCode, const char* pchFile, UINT uiLine );
  bool    VerifySQLConnect( RETCODE retCode, const char* pcFile, UINT uiLine );

  void GetErrorMessages(SQLSMALLINT iHandleType, SQLHANDLE hSqlHandle, bool bIsConnected = true );

  static HENV m_henvAllConnections;
  static int  m_nAllocatedConnections;
};


#endif


/*****************************************************************************/
/* Check-in history */
/*
 *$Log:  $
*/
/*****************************************************************************/


⌨️ 快捷键说明

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