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

📄 podbc.h

📁 sloedgy open sip stack source code
💻 H
📖 第 1 页 / 共 2 页
字号:
	  */
	  class Row : public PObject
	  {
	  public:

		/** Constructor
			Create a Dummy row of data to act as a 
			Record Marker. Template Field are created
			and Stored in a PARRAY.
		*/
		  Row(PODBCStmt * stmt);

		/** Retrieve Field Data given the specifed column.
			Note: Columns atart at 1 and not exceed PODBCStmt::GetColumnCount()
		*/
		  Field & Column(PINDEX col);

		/** Retreive Field Data given the Column Name
		*/
		  Field & Column(PString name);

		/** Retrieve the Column Names
		*/
		  PStringArray ColumnNames();

		/** Columns. The Number of Columns in the RecordSet
		*/
		  PINDEX Columns();

		/** Rows	The Number of Rows 
		*/
		  PINDEX Rows();

		/** Retrieve Field Data given specified column
		*/
		  Field & operator[] (PINDEX col);

		/** Retrieve Field Data given the column Name.
		*/
		  Field & operator[] (PString col);

		/** Navigate to Specified Row
		*/
		  BOOL Navigate(PINDEX row);

		/** SetNewRow Set New Row for input
		*/
		  void SetNewRow();

		/** Post the Row back to the Database.
			When Row::NewRow is true the data
			can be posted back to the Database;
			If Edit Invoked then releasea the
			RowHandler for Navigation.
		*/
		  BOOL Post();

		/** Delete the Current Record from the
			RecordSet
		*/
		  BOOL Delete(PINDEX row =0);

		  PODBCRecord * rec;      /// Record Structure

		  PINDEX CurRow;          /// Current Row
		  BOOL NewRow;			  /// Flag to Indicate New Row (requires either Post or Delete)
		  PINDEX RowCount;		  /// Number of Rows.

	  protected:
		  PArray<Field> Fields;	  /// PODBC::Field Array Cache (Used for New Row)
	  };
  //@}

   /** PODBC::Table
		This is the main Class to access Data returned by a Select Query.
		The Table does not actually create the RecordSet but acts as a wrapper 
		to the driver to access the cached data in the Driver.
   */
  class Table : public PObject
  {
  public:

   /**@name Constructor/Deconstructor */
  //@{ 
	  /** Constructor
			Using the HDBC and TableName/Select SQL Query 
			creates a virtual Table in the OBDC driver.
	  */
	  Table(PODBC * odbc, PString Query);

	  /** Deconstructor
	  */
	  ~Table();
  //@}

   /**@name Data Storage */
  //@{
    /** Add New Row
	*/
	  Row NewRow();

	/** Delete Row 0 indicates Current Row
	*/
	  BOOL DeleteRow(PINDEX row = 0);

	/** Post Update back to Database
	*/
	  BOOL Post();
  //@}

   /**@name Utilities */
  //@{
	  /** Rows. Returns the Number of Rows in the Resultant RecordSet
	  */
	  PINDEX Rows();

	  /** Columns. Returns the Number of Columns in the Resultant RecordSet
	  */
	  PINDEX Columns();

	  /** ColumnNames. Return the list of column Names of the Resultant RecordSet
	  */
	  PStringArray ColumnNames();

	  /** Obtain the Record Handler. This can be used as a Template to obtain
			Record Information. A call to tablename[i] will update the recordHandler
			with the Values contained in i Record. 
	  */
	  Row & RecordHandler();

	  /** Row return the fetched row in the Cached RecordSet. An Array of PODBC::Field
	  */
	  Row & operator[] (PINDEX row);

	  /** Returns the Field data at a predetermined position in the Resultant
			RecordSet. It Fetches the Row than isolates the Column from the fetched 
			data.
	  */
	  Field & operator() (PINDEX row, PINDEX col);

	  /** Returns the indicated Column Holder for the RecordSet,
			This can be used for iterative Row calls.
	  */
	  Field & Column(PINDEX col);

	  /** Returns the indicated Column Holder Name for the RecordSet,	
	  */
	  Field & Column(PString Name);
  //@}

  protected:
	  PODBCStmt stmt;			/// ODBC Fetched Statement Info
	  PString tableName;		/// Name of the Fetched Table (if used in Constructor)
	  Row * RowHandler;			/// row Handler
  };

   /**@name Data Queries */
  //@{ 
	  /** Load a specified Table/Stored Query or 
			General 'SELECT' SQL Query.
			This function will return a PODBC::Table for
			further analysis. Do Not Use this Function for
			any other SQL statements other than SELECT.
	  */
	  Table LoadTable(PString table);

	  /** Added Information to the DataSource. Use this 
			function if you just want to use a SQL statement
			to add data to a datasource without retreiving the
			data itself. ie "UPDATE" "APPEND" "INSERT" queries.
	  */
	  BOOL Query(PString Query);
  //@}


   /**@name DataSource Access */
  //@{ 
	 /** DataSource
			This is the main function to call to contact a
			DataSource. Source specifies the Type of DataSource
			to contact and the Data parameter contain the relevent
			connection information. You can choose to call this function
			or use the specific Connection function.
	  */
	  BOOL DataSource(DataSources Source, ConnectData Data);
  
	  /** General Connect Function
			Custom connection strings should call this 
			to connect Don't ask why its LPCTSTR!
	  */
	  virtual BOOL Connect(LPCTSTR svSource);

	  /** Connect to IBM DB2 DataSource
	  */
	  BOOL Connect_DB2(PFilePath DBPath);

	  /** Connect to MS Office excel spreadsheet
	  */
	  BOOL Connect_XLS(PFilePath XLSPath,PString DefDir = "");

	  /** Connect to an ascii text or cvs file
	  */
	  BOOL Connect_TXT(PFilePath TXTPath);

	  /** Connect to a Foxpro dataSource
	  */
	  BOOL Connect_FOX(PFilePath DBPath,PString User = "",
			  PString Pass = "",PString Type= "DBF",
			  BOOL Exclusive=FALSE);

	  /** Connect to a MS Access *.mdb DataSource.
	  */
	  BOOL Connect_MDB(PFilePath MDBPath,PString User ="",
				PString Pass = "",BOOL Exclusive=FALSE);

	  /** Connect to a paradox database datastore
	  */
	  BOOL Connect_PDOX(PDirectory DBPath,PDirectory DefaultDir,
				int version =5);

	  /** Connect to an Oracle Datasource
	  */
	  BOOL Connect_Oracle(PString Server,PString User="", PString Pass="");

	  /** Connect to a DBase DataStore
	  */
	  BOOL Connect_DBASE(PDirectory DBPath);

	  /** Connect to a MS SQL Server
	  */
	  BOOL Connect_MSSQL(PString User="",PString Pass="", 
			 PString Host ="(local)",BOOL Trusted = TRUE, 
			 MSSQLProtocols Proto=MSSQLNamedPipes);

	  /** Connect to a mySQL Server
	  */
	  BOOL Connect_mySQL(PString User="",PString Pass="",
			 PString Host= "localhost",
			 int Port=3306,int Option=0);

	  /** Connect to a mySQL Server's specified DataBase.
	  */
	  BOOL ConnectDB_mySQL(PString DB,PString User="",
			PString Pass="",PString Host= "localhost",
			int Port=3306,int Option=0);

	  /** Connect to a postgreSQL Server
	  */
	  BOOL Connect_postgreSQL(PString DB,PString User,
        PString Pass,PString Host, int Port=5432,int Option=0);

	  /** General Disconnect from DataSource.
	  */
	  void Disconnect();
  //@}

   /**@name Utilities */
  //@{ 
	  /** Retrieve a List of Tables in the Datasource
			use the option field to specify the type of
			data to access. ie "TABLE" or "VIEW" (further dev req'd)
	  */
	  PStringArray TableList(PString option = "");

	  /** Check whether their is a limit to Datalength
			when obtaining Long Data
	  */
	  BOOL NeedLongDataLen();

	  /** OnSQL Error
	  */
	  virtual void OnSQLError(PString RetCode, PString RetString) 
			{  cout << RetCode << " " << RetString << endl; };


	  /** Set the Number of Decimal places to
			round to By Default it is 4. However if the field
			decimal places is less then Precision Value the 
			field rounding will be used. This must be set prior
			to calling LoadTable()
	  */
	  void SetPrecision(int Digit);

	  /** Set the Time Display Format
	  */
	  void SetTimeFormat(PTime::TimeFormat tformat);

	  /** Operator Handle DataBase Connection
	  */
	  operator HDBC() { return m_hDBC; };
  //@}
	  	
	 PODBC::DataSources  dbase; /// Database Type connected to

protected:

  SQLRETURN       m_nReturn;      // Internal SQL Error code
  HENV            m_hEnv;         // Handle to environment
  HDBC            m_hDBC;         // Handle to database connection
};

/**		
	DSN (Data Source Name) Connection. The connection settings 
	have been preconfiured in the MDAC (Microsoft Data Access Component)
	and is called using those Preset Settings. Calling the PDSNConnection::Connect
	has the same effect and is a replaceable for PODBC::DataSource,
 */


class PDSNConnection : public PODBC
{
  PCLASSINFO(PDSNConnection, PODBC);

public:

  /**@name Constructor/Deconstructor */
  //@{
	  PDSNConnection();
	  ~PDSNConnection();
  //@}

  /**@name Connection/Disconnect */
  //@{
	  /** Connect to the MDAC using a pre-existing MDAC Defined DataSource
			This is different than calling PODBC::DataSource in that the 
			Data Source is known defined externally within MDAC,
	  */
	  BOOL Connect( PString Source ,PString Username, PString Password);

};

 //--
/** PODBCRecord
		This Class is used to analyse the fetched data and handles
		Data Conversion/Read Write operations. It is used in conjuction
		with the PODBCStmt Class
*/

class PODBCRecord : public PObject
{
  
  PCLASSINFO(PODBCRecord, PObject);

HSTMT m_hStmt;

public:

   /**@name Constructor/Deconstructor */
  //@{ 
	  /** Constructor 
	  */
	   PODBCRecord(PODBCStmt * hStmt);

	  /** Deconstructor
	  */
	  ~PODBCRecord(){};
  //@}

   /**@name Data Collection/Saving */
  //@{ 
	  /** Data: Main Call to retrieve and convert Field Data 
			and return the information in the PODBC::Field structure.
	  */
	  void Data(PINDEX Column, PODBC::Field & field);

	  /** InternalGetData is call when retrieving string or large binary 
			data where the size is indetermined. The Function can be iteratively
			called until the function returns FALSE.
	  */
	  BOOL InternalGetData(USHORT Column, LPVOID pBuffer, 
		ULONG pBufLen, LONG * dataLen=NULL, int Type=SQL_C_DEFAULT);

	  /* Get Long Character Data. Long Data fields cannot be bound
			and Data must be Got from the RecordSet.
	  */
	  PString GetLongData(PINDEX Column);
  
	  /** Post the new record back to the RecordSet;
	  */
	  BOOL PostNew(PODBC::Row & rec);

	  /** Post the Updated record back to the RecordSet;
	  */
	  BOOL PostUpdate(PODBC::Row & rec);

	  /** Post a Delete command to the RecordSet; Default
		  1 Row is deleted.
	  */
	  BOOL PostDelete(PINDEX row= 1);

	  /** Check for and Save Long Data
	  */
	  BOOL InternalSaveLongData(SQLRETURN nRet,PODBC::Row & rec);

	  /** InternalBindColumn for Data input.
	  */
	  BOOL InternalBindColumn(USHORT Column,LPVOID pBuffer,
			ULONG pBufferSize,LONG * pReturnedBufferSize=NULL,
			USHORT nType=SQL_C_TCHAR);
  //@}

   /**@name Data Information */
  //@{ 
	  /** ColumnByName returns the column number of the column name
			If not found returns column value of 0;
	  */
	  PINDEX ColumnByName(PString Column);

	  /** ColumnCount No of columns
	  */
	  PINDEX ColumnCount();

	  /** ColumnTypes
	  */
	  PODBC::FieldTypes ColumnType(PINDEX Column );

	  /** Column Size
	  */
	  DWORD ColumnSize( PINDEX Column );

	  /** Column Scale
	  */
	  DWORD ColumnScale( PINDEX Column );

	  /** Column Name
	  */
	  PString ColumnName( PINDEX Column);

	  /** ColumnPrecision Get the Number of Decimal places
			if Precision is set the precision is set to the
			lessor of the Two.
	  */
	  unsigned int ColumnPrecision( PINDEX Column );

	  /** IsColumn Nullable. Accepts NULL value
	  */
	  BOOL IsColumnNullable( PINDEX Column );

	  /** IsColumn Updateable ie is not ReadOnly
	  */
	  BOOL IsColumnUpdatable( PINDEX Column );

	  /** IsColumnAutoIndex (ie don't give default Value)
	  */
	  BOOL IsColumnAutoIndex( PINDEX Column );

  //@}

   /**@name Data Conversion Settings */
  //@{ 
	  /** Conversion Settings
	  */
	  static unsigned int Precision;      /// Double Real Float Decimal digit rounding def= 4;
	  static int MaxCharSize;		      /// Long Data Limit KBytes def = 56; (56 Kbytes)
	  static PTime::TimeFormat TimeFormat;/// Time Format
  //@}

	  PODBCStmt * Stmt;					/// Statement Class
	  PODBC::DataSources dbase;			/// Database Type connecting to


};
#endif // !defined(PODBC_H)

⌨️ 快捷键说明

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