Software and Services, Portable Libraries  2019.Mar.01
A library for managing digital certificates
SQL_odbc.hpp
1 //
2 // (C) Copyright 2001-2015 Software and Services LLC, All Rights Reserved.
3 //
4 // NOTICE:
5 //
6 // THIS SOURCE CODE BELONGS TO SOFTWARE AND SERVICES LIMITED LIBILITY
7 // CORPORATION, AN IDAHO CORPORATION. THIS CODE IS CONSIDERED A
8 // TRADE SECRET AND IS NOT TO BE DIVULGED OR USED BY PARTIES WHO HAVE
9 // NOT RECEIVED WRITTEN AUTHORIZATION FROM THE OWNER.
10 //
11 // THIS SOURCE CODE IS UNPUBLISHED WORK FULLY PROTECTED BY THE UNITED
12 // STATES COPYRIGHT LAWS AND IS CONSIDERED A TRADE SECRET BELONGING
13 // TO THE COPYRIGHT HOLDER.
14 //
15 // THIS SOFTWARE AND MANUAL ARE BOTH PROTECTED BY UNITED STATES
16 // COPYRIGHT LAW (TITLE 17 UNITED STATES CODE). UNAUTHORIZED REPRODUCTION
17 // AND/OR SALE MAY RESULT IN IMPRISONMENT OF UP TO ONE YEAR AND FINES
18 // OF UP TO $100,000 (17 USC 506). COPYRIGHT INFRINGERS MAY ALSO
19 // BE SUBJECT TO CIVIL LIABILITY.
20 //
21 // ALL OF THIS CODE IS ORIGINAL WORK BY THE COPYRIGHT HOLDER.
22 //
23 
24 #ifndef __SOFTWARE_AND_SERVICES_LIBPCSQL_ODBC_HH__
25 #define __SOFTWARE_AND_SERVICES_LIBPCSQL_ODBC_HH__
26 
27 #ifdef BUILDING_LIBRARY_SQL_ODBC
28 #ifndef EXPORT_SASSQL
29 #define EXPORT_SASSQL EXPORT_OUT
30 #endif
31 #include "../SQL.hpp"
32 #else
33 #ifndef EXPORT_SASSQL
34 #define EXPORT_SASSQL EXPORT_IN
35 #endif
36 #include <SaS/Sql/SQL_odbc.hpp>
37 #endif
38 
39 #include <SaS/Common/Error.hpp>
40 
41 #if defined(USE_ODBC)
42 
43 #include <sql.h>
44 #include <sqlext.h>
45 #include <sqltypes.h>
46 #include <vector>
47 
48 namespace SoftwareAndServices
49 {
50  namespace Library
51  {
52  namespace Database
53  {
54 
55  //#define T_RESULT ODBC_RES
56  //#define T_ROW ODBC_ROW
57 
63  class SQL_odbc
64  : public SQL
65  {
66  public:
67 
71  SQL_odbc();
72 
76  ~SQL_odbc();
77 
84  unsigned long GetAffectedRows() const;
85 
92  unsigned long GetRowsSelected() const;
93 
100  unsigned long GetFieldCount() const;
101 
110  bool Query(const char * QueryString);
111 
135  virtual bool Connect(const char * hostName,
136  const char * dbName,
137  const char * userName,
138  const char * password,
139  const char * hostAddress,
140  short port);
141 
148  virtual bool Disconnect();
149 
157  virtual bool IsConnected() const;
158 
167  virtual bool Lock(const char * tableList);
168 
175  virtual bool Unlock();
176 
183  static const char * GetGuid();
184 
191  virtual Error * GetError() const;
192 
199  virtual bool NextRow() const;
200 
209  virtual const char * GetFieldValue(unsigned int offset) const;
210 
219  virtual const char * GetFieldName(unsigned int offset) const;
220 
229  virtual const char * DefaultValue(unsigned int offset) const;
230 
231 
240  virtual SQL::SqlDataType_e Type(unsigned int offset) const;
241 
250  virtual unsigned long Length(unsigned int offset) const;
251 
260  virtual unsigned long MaxLength(unsigned int offset) const;
261 
262 
271  virtual unsigned long Decimals(unsigned int offset) const;
272 
281  virtual bool IsPrimaryKey(unsigned int offset) const;
282 
291  virtual bool IsUnique(unsigned int offset) const;
292 
293 
302  virtual bool IsNotNull(unsigned int offset) const;
303 
312  virtual bool IsBlob(unsigned int offset) const;
313 
322  virtual bool IsNumeric(unsigned int offset) const;
323 
324  //virtual bool addFlag(attr);
325  //virtual bool dropFlag(attr);
326 
327  protected:
328 
332  static const char * _Guid;
333 
337  SQLHENV _Dsn;
338 
342  SQLHDBC _Connection;
343 
347  mutable Error * _Error;
348 
352  mutable unsigned int _RowNumber;
353 
357  mutable std::vector<void*> _ColData;
358  };
359  }
360  }
361 }
362 
363 #endif // USE_ODBC
364 #endif //__SOFTWARE_AND_SERVICES_LIBPCSQL_ODBC_HH__
virtual Error * GetError() const
Get the last error.
virtual bool IsUnique(unsigned int offset) const
Determin if the indicated field is the unique.
virtual bool NextRow() const
Advance the row pointer in the result set.
static const char * _Guid
The current GUID.
Definition: SQL_odbc.hpp:332
Extension to SoftwareAndServices::Library::SQL for ODBC.
Definition: SQL_odbc.hpp:63
SQL_odbc()
SQL_odbc - Default constructor.
virtual unsigned long Decimals(unsigned int offset) const
Get the decimals of the indicated field.
unsigned long GetRowsSelected() const
Get the number of rows returned after a SELECT.
The SQL class is a pure virtual interface class for SQL access.
Definition: SQL.hpp:128
std::vector< void * > _ColData
The set of column data.
Definition: SQL_odbc.hpp:357
virtual bool Unlock()
Unlock the ODBC tables.
static const char * GetGuid()
The the current GUID.
virtual SQL::SqlDataType_e Type(unsigned int offset) const
Get the dataType of the indicated field.
unsigned long GetFieldCount() const
Get the number of fields in the result set.
virtual const char * DefaultValue(unsigned int offset) const
Get default value of the indicated field.
virtual bool IsPrimaryKey(unsigned int offset) const
Determin if the indicated field is the primary key.
bool Query(const char *QueryString)
Perform a SQL query.
virtual bool Lock(const char *tableList)
Lock all tables listed in the ODBC database.
virtual bool Disconnect()
Disconnect from the ODBC datbase.
virtual unsigned long MaxLength(unsigned int offset) const
Get the maximum length of the indicated field.
Copyright Douglas Mark Royer DouglasRoyer@gmail.com.
Definition: Base.hpp:98
virtual const char * GetFieldValue(unsigned int offset) const
Get the value of the indicated field.
virtual bool IsNumeric(unsigned int offset) const
Determin if the indicated field is a numeric type.
virtual unsigned long Length(unsigned int offset) const
Get the length of the indicated field.
virtual bool Connect(const char *hostName, const char *dbName, const char *userName, const char *password, const char *hostAddress, short port)
Connect to an ODBC database.
SqlDataType_e
Generic names for data types.
Definition: SQL.hpp:197
virtual bool IsConnected() const
Determine if this object is connected to an ODBC database.
virtual bool IsNotNull(unsigned int offset) const
Determin if the indicated field is the allowed to be NULL.
virtual const char * GetFieldName(unsigned int offset) const
Get name of the indicated field.
virtual bool IsBlob(unsigned int offset) const
Determin if the indicated field is a blob type.
unsigned int _RowNumber
Curent row number.
Definition: SQL_odbc.hpp:352
unsigned long GetAffectedRows() const
Get the number of rows affected by actions like INSERT.