NCBI C++ ToolKit
python_ncbi_dbapi.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: python_ncbi_dbapi.hpp 60029 2013-10-17 18:30:19Z ucko $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Sergey Sikorskiy
27 *
28 * File Description:
29 * Status: *Initial*
30 *
31 * ===========================================================================
32 */
33 
36 
37 #include <dbapi/dbapi.hpp>
39 #include <set>
40 
42 
43 namespace python
44 {
45 
46 //////////////////////////////////////////////////////////////////////////////
47 // eStandardMode stands for Python DB API specification mode
48 // as defined in http://www.python.org/peps/pep-0249.html
49 // eSimpleMode is a simplified mode as it is supported by the
50 // NCBI DBAPI. The eSimpleMode was introduced by a request.
52 
53 //////////////////////////////////////////////////////////////////////////////
54 class CBinary : public pythonpp::CExtObject<CBinary>
55 {
56 public:
57  CBinary(void);
58  CBinary(const string& value);
59  ~CBinary(void);
60 
61 public:
62  string GetValue(void) const
63  {
64  return m_Value;
65  }
66 
67 private:
68  const string m_Value;
69 };
70 
71 //////////////////////////////////////////////////////////////////////////////
72 class CNumber : public pythonpp::CExtObject<CNumber>
73 {
74 public:
75  CNumber(void);
76  ~CNumber(void);
77 };
78 
79 //////////////////////////////////////////////////////////////////////////////
80 class CRowID : public pythonpp::CExtObject<CRowID>
81 {
82 public:
83  CRowID(void);
84  ~CRowID(void);
85 };
86 
87 //////////////////////////////////////////////////////////////////////////////
88 class CStringType : public pythonpp::CExtObject<CStringType>
89 {
90 public:
91  CStringType(void);
92  ~CStringType(void);
93 };
94 
95 //////////////////////////////////////////////////////////////////////////////
96 class CDateTimeType : public pythonpp::CExtObject<CDateTimeType>
97 {
98 public:
99  CDateTimeType(void);
100  ~CDateTimeType(void);
101 };
102 
103 ////////////////////////////////////////////////////////////////////////////////
115  };
116 
118 RetrieveStatementType(const string& stmt, EStatementType default_type = estNone);
119 
121 
122 ////////////////////////////////////////////////////////////////////////////////
124 {
125 public:
127 
128  CParamFmt(TFormat user_fmt = eTSQL, TFormat drv_fmt = eTSQL);
129 
130 public:
131  TFormat GetUserFmt(void) const
132  {
133  return m_UserFmt;
134  }
135  TFormat GetDriverFmt(void) const
136  {
137  return m_DrvFmt;
138  }
139  static const char* GetName(TFormat fmt);
140 
141 private:
144 };
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 class CStmtStr
148 {
149 public:
150  CStmtStr(void)
151  : m_StmType(estNone)
152  {
153  }
154  CStmtStr(const string& str,
155  EStatementType default_type = estSelect,
156  const CParamFmt& fmt = CParamFmt()
157  )
158  : m_StmType(estNone)
159  {
160  SetStr(str, default_type, fmt);
161  }
162 
163  // We will accume that SQL has type estFunction if it is
164  // hard to get an actual type.
165  void SetStr(const string& str,
166  EStatementType default_type = estSelect,
167  const CParamFmt& fmt = CParamFmt()
168  );
169 
170 public:
171  string GetStr(void) const
172  {
173  return m_StmtStr;
174  }
176  {
177  return m_StmType;
178  }
179 
180 private:
181  string::size_type find_numeric(const string& str,
182  string::size_type offset,
183  int& param_len
184  );
185  string::size_type find_named(const string& str,
186  string::size_type offset,
187  int& param_len
188  );
189  string::size_type find_TSQL(const string& str,
190  string::size_type offset,
191  int& param_len
192  );
193 
194 private:
195  string m_StmtStr;
197 };
198 
199 //////////////////////////////////////////////////////////////////////////////
200 // Forward declaration ...
201 class CConnection;
202 class CTransaction;
203 
204 //////////////////////////////////////////////////////////////////////////////
205 // IStatement plus additinal informaion ...
207 {
208 public:
209  CStmtHelper(CTransaction* trans);
210  CStmtHelper(CTransaction* trans, const CStmtStr& stmt);
211  ~CStmtHelper(void);
212 
213 public:
214  // void SetStr(const string& stmt, EStatementType default_type = estFunction);
215  void SetStr(const CStmtStr& stmt, CDB_UserHandler* handler);
216  void SetParam(const string& name, const CVariant& value);
217  void SetParam(size_t index, const CVariant& value);
218 
219  void Execute(void);
220  void Close(void);
221  long GetRowCount(void) const;
222  void FillDescription(pythonpp::CList& descr);
223 
224  bool MoveToNextRS(void);
225  IResultSet& GetRS(void);
226  const IResultSet& GetRS(void) const;
227  bool HasRS(void) const;
228 
229  int GetReturnStatus(void);
230 
231 private:
232  void DumpResult(void);
233  void ReleaseStmt(void);
234  void CreateStmt(CDB_UserHandler* handler);
235 
236 private:
237  CTransaction* const m_ParentTransaction; //< A transaction to which belongs this cursor object
238  auto_ptr<IStatement> m_Stmt; //< DBAPI SQL statement interface
245 };
246 
247 //////////////////////////////////////////////////////////////////////////////
248 class CVariantSet;
249 
251 {
252 public:
253  virtual ~CResultSetProxy(void) {}
254 
255  virtual bool MoveToNextRS(void) = 0;
256  virtual bool MoveToLastRS(void) = 0;
257  virtual CVariantSet& GetRS(void) = 0;
258  virtual const CVariantSet& GetRS(void) const = 0;
259  virtual bool HasRS(void) const = 0;
260  virtual void DumpResult(void) = 0;
261 };
262 
263 //////////////////////////////////////////////////////////////////////////////
264 // ICallableStatement plus additinal informaion ...
266 {
267 public:
270  ~CCallableStmtHelper(void);
271 
272 public:
273  // void SetStr(const string& stmt, int num_arg, EStatementType default_type = estFunction);
274  void SetStr(const CStmtStr& stmt, CDB_UserHandler* handler);
275  void SetParam(const string& name, const CVariant& value, bool& output_param);
276  void SetParam(size_t index, const CVariant& value, bool& output_param);
277 
278  void Execute(bool cache_results = false);
279  void Close(void);
280  long GetRowCount(void) const;
281  void FillDescription(pythonpp::CList& descr);
282 
283  bool MoveToNextRS(void);
284  bool MoveToLastRS(void);
285  CVariantSet& GetRS(void);
286  const CVariantSet& GetRS(void) const;
287  bool HasRS(void) const;
288 
289  int GetReturnStatus(void);
290 
291 private:
292  void DumpResult(void);
293  void ReleaseStmt(void);
294  void CreateStmt(CDB_UserHandler* handler);
295 
296 private:
297  CTransaction* const m_ParentTransaction; //< A transaction to which belongs this cursor object
298  auto_ptr<ICallableStatement> m_Stmt; //< DBAPI SQL statement interface
305 };
306 
307 class CCursor;
308 
310 {
311 public:
313  : m_Cursor(cursor)
314  {}
315 
317 
318  virtual bool HandleIt(CDB_Exception* ex);
319 
320 private:
322 };
323 
324 //////////////////////////////////////////////////////////////////////////////
325 // Cursor borrows connections from a parent transaction.
326 class CCursor : public pythonpp::CExtObject<CCursor>
327 {
328  friend class CTransaction;
329 
330 protected:
331  CCursor(CTransaction* trans);
332 
333 public:
334  ~CCursor(void);
335 
336  void AddInfoMessage(const string& message);
337 
338 public:
339  // Python methods ...
340 
341  /// Call a stored database procedure with the given name. The
342  /// sequence of parameters must contain one entry for each
343  /// argument that the procedure expects. The result of the
344  /// call is returned as modified copy of the input
345  /// sequence. Input parameters are left untouched, output and
346  /// input/output parameters replaced with possibly new values.
347  /// callproc(procname[,parameters]);
350  /// Close the cursor now (rather than whenever __del__ is
351  /// called). The cursor will be unusable from this point
352  /// forward; an Error (or subclass) exception will be raised
353  /// if any operation is attempted with the cursor.
354  /// close();
356  /// Prepare and execute a database operation (query or
357  /// command). Parameters may be provided as sequence or
358  /// mapping and will be bound to variables in the operation.
359  /// Variables are specified in a database-specific notation
360  /// (see the module's paramstyle attribute for details). [5]
361  /// execute(operation[,parameters]);
363  PyObject* CreateIter(void);
364  /// Prepare a database operation (query or command) and then
365  /// execute it against all parameter sequences or mappings
366  /// found in the sequence seq_of_parameters.
367  /// executemany(operation,seq_of_parameters);
369  /// Fetch the next row of a query result set, returning a
370  /// single sequence, or None when no more data is
371  /// available. [6]
372  /// An Error (or subclass) exception is raised if the previous
373  /// call to executeXXX() did not produce any result set or no
374  /// call was issued yet.
375  /// fetchone();
377  /// Fetch the next set of rows of a query result, returning a
378  /// sequence of sequences (e.g. a list of tuples). An empty
379  /// sequence is returned when no more rows are available.
380  /// The number of rows to fetch per call is specified by the
381  /// parameter. If it is not given, the cursor's arraysize
382  /// determines the number of rows to be fetched. The method
383  /// should try to fetch as many rows as indicated by the size
384  /// parameter. If this is not possible due to the specified
385  /// number of rows not being available, fewer rows may be
386  /// returned.
387  /// An Error (or subclass) exception is raised if the previous
388  /// call to executeXXX() did not produce any result set or no
389  /// call was issued yet.
390  /// fetchmany([size=cursor.arraysize]);
392  /// Fetch all (remaining) rows of a query result, returning
393  /// them as a sequence of sequences (e.g. a list of tuples).
394  /// Note that the cursor's arraysize attribute can affect the
395  /// performance of this operation.
396  /// An Error (or subclass) exception is raised if the previous
397  /// call to executeXXX() did not produce any result set or no
398  /// call was issued yet.
399  /// fetchall();
401  /// This method will make the cursor skip to the next
402  /// available set, discarding any remaining rows from the
403  /// current set.
404  /// If there are no more sets, the method returns
405  /// None. Otherwise, it returns a true value and subsequent
406  /// calls to the fetch methods will return rows from the next
407  /// result set.
408  /// An Error (or subclass) exception is raised if the previous
409  /// call to executeXXX() did not produce any result set or no
410  /// call was issued yet.
411  /// nextset();
413  /// This can be used before a call to executeXXX() to
414  /// predefine memory areas for the operation's parameters.
415  /// sizes is specified as a sequence -- one item for each
416  /// input parameter. The item should be a Type Object that
417  /// corresponds to the input that will be used, or it should
418  /// be an integer specifying the maximum length of a string
419  /// parameter. If the item is None, then no predefined memory
420  /// area will be reserved for that column (this is useful to
421  /// avoid predefined areas for large inputs).
422  /// This method would be used before the executeXXX() method
423  /// is invoked.
424  /// setinputsizes(sizes);
426  /// Set a column buffer size for fetches of large columns
427  /// (e.g. LONGs, BLOBs, etc.). The column is specified as an
428  /// index into the result sequence. Not specifying the column
429  /// will set the default size for all large columns in the
430  /// cursor.
431  /// This method would be used before the executeXXX() method
432  /// is invoked.
433  /// setoutputsize(size[,column]);
435  //
437 
438 private:
440  {
441  return *m_ParentTransaction;
442  }
443 
444 private:
445  void CloseInternal(void);
446  bool NextSetInternal(void);
447 
448 private:
449  CVariant GetCVariant(const pythonpp::CObject& obj) const;
450 
451  void SetupParameters(const pythonpp::CDict& dict, CStmtHelper& stmt);
453  // Return *true* if there are output parameters.
455  void SetupParameters(const pythonpp::CSequence& dict,
457  vector<size_t>* out_params);
458 
459  void ExecuteCurrStatement(void);
460 
461  static bool isDML(EStatementType stmtType)
462  {
463  return stmtType == estInsert || stmtType == estDelete || stmtType == estUpdate;
464  }
465  static bool isDDL(EStatementType stmtType)
466  {
467  return stmtType == estCreate || stmtType == estDrop || stmtType == estAlter;
468  }
469 
470 private:
471  pythonpp::CObject m_PythonConnection; //< For reference counting purposes only
472  pythonpp::CObject m_PythonTransaction; //< For reference counting purposes only
473  CTransaction* m_ParentTransaction; //< A transaction to which belongs this cursor object
474  int m_NumOfArgs; //< Number of arguments in a callable statement
475  long m_RowsNum;
481  size_t m_ArraySize;
487  bool m_Closed;
488 };
489 
490 class CCursorIter : public pythonpp::CExtObject<CCursorIter>
491 {
492  friend class CCursor;
493 
494 protected:
495  CCursorIter(CCursor* cursor);
496 
497 public:
498  ~CCursorIter(void);
499 
500 public:
501  PyObject* GetNext(void);
502 
503 public:
507 };
508 
509 //////////////////////////////////////////////////////////////////////////////
512 
513 //////////////////////////////////////////////////////////////////////////////
515 {
516 public:
517  CSelectConnPool(CTransaction* trans, size_t size = 3);
518 
519 public:
520  IConnection* Create(void);
521  void Destroy(IConnection* db_conn);
522  void Clear(void);
523  // Means that nobody uses connections from the pool.
524  bool Empty(void) const
525  {
526  return ((m_ConnList.size() - m_ConnPool.size()) == 0);
527  }
528 
529 private:
530  const CConnection& GetConnection(void) const;
531  CConnection& GetConnection(void);
532 
533 private:
535  const size_t m_PoolSize;
536  TConnectionList m_ConnPool; //< A pool of connection for SELECT statements
537  TConnectionList m_ConnList; //< A list of all allocated connection for SELECT statements
538 };
539 
540 //////////////////////////////////////////////////////////////////////////////
541 
542 // eImplicitTrans meant that a transaction will be started automaticaly,
543 // without your help.
544 // eExplicitTrans means that you have to start a transaction manualy by calling
545 // the "BEGIN TRANSACTION" statement.
547 
548 // A pool with one connection only ...
549 // Strange but useful ...
551 {
552 public:
553  CDMLConnPool( CTransaction* trans, ETransType trans_type = eImplicitTrans );
554 
555 public:
556  IConnection* Create(void);
557  void Destroy(IConnection* db_conn);
558  void Clear(void);
559  bool Empty(void) const
560  {
561  return (m_NumOfActive == 0);
562  }
563 
564 public:
565  void commit(void) const;
566  void rollback(void) const;
567 
568 private:
569  const CConnection& GetConnection(void) const;
570  CConnection& GetConnection(void);
571 
572  IStatement& GetLocalStmt(void) const;
573 
574 private:
576  auto_ptr<IConnection> m_DMLConnection; //< Transaction has only one DML connection
578  auto_ptr<IStatement> m_LocalStmt; //< DBAPI SQL statement interface
579  bool m_Started;
581 };
582 
583 //////////////////////////////////////////////////////////////////////////////
584 class CTransaction : public pythonpp::CExtObject<CTransaction>
585 {
586  friend class CConnection;
587  friend class CSelectConnPool;
588  friend class CDMLConnPool;
589 
590 protected:
591  CTransaction(
592  CConnection* conn,
594  EConnectionMode conn_mode = eSimpleMode
595  );
596 
597 public:
598  ~CTransaction(void);
599 
600 public:
606 
607 public:
608  // CCursor factory interface ...
609  CCursor* CreateCursor(void);
611 
612 public:
613  // Factory for DML connections (actualy, only one connection)
615  {
616  return m_DMLConnPool.Create();
617  }
619  {
620  m_DMLConnPool.Destroy(db_conn);
621  }
622 
623 public:
624  // Factory for "data-retrieval" connections
626  void DestroySelectConnection(IConnection* db_conn);
627 
628 public:
629  const CConnection& GetParentConnection(void) const
630  {
631  return *m_ParentConnection;
632  }
634  {
635  return *m_ParentConnection;
636  }
637 
638 protected:
639  void CloseInternal(void);
640  void CommitInternal(void) const
641  {
643  }
644  void RollbackInternal(void) const
645  {
647  }
648  void CloseOpenCursors(void);
649 
650 private:
651  pythonpp::CObject m_PythonConnection; //< For reference counting purposes only
652  CConnection* m_ParentConnection; //< A connection to which belongs this transaction object
653  TCursorList m_CursorList;
654 
655  CDMLConnPool m_DMLConnPool; //< A pool of connections for DML statements
656  CSelectConnPool m_SelectConnPool; //< A pool of connections for SELECT statements
658 };
659 
660 //////////////////////////////////////////////////////////////////////////////
661 // CConnection does not represent an "physical" connection to a database.
662 // In current implementation CConnection is a factory of CTransaction.
663 // CTransaction owns and manages "physical" connections to a database.
664 
665 class CConnection : public pythonpp::CExtObject<CConnection>
666 {
667 public:
668  CConnection(
669  const string& driver_name,
670  const string& db_type,
671  const string& server_name,
672  const string& db_name,
673  const string& user_name,
674  const string& user_pswd,
675  const pythonpp::CObject& extra_params
676  );
677  ~CConnection(void);
678 
679 public:
680  // Python Interface ...
687 
688 public:
689  // Connection factory interface ...
690  IConnection* MakeDBConnection(void) const;
691 
692 public:
693  // CTransaction factory interface ...
695  void DestroyTransaction(CTransaction* trans);
696 
697 protected:
699  {
700  return *m_DefTransaction;
701  }
702 
703 private:
705 
708 
711  CTransaction* m_DefTransaction; //< The lifetime of the default transaction will be managed by Python
712  TTransList m_TransList; //< List of user-defined transactions
714  string m_ModuleName;
715 };
716 
717 //////////////////////////////////////////////////////////////////////////////
718 // Python Database API exception classes ... 2/4/2005 8:18PM
719 
720 // This is the exception inheritance layout:
721 //
722 // StandardError
723 // |__Warning
724 // |__Error
725 // |__InterfaceError
726 // |__DatabaseError
727 // |__DataError
728 // |__OperationalError
729 // |__IntegrityError
730 // |__InternalError
731 // |__ProgrammingError
732 // |__NotSupportedError
733 
734 class CWarning : public pythonpp::CUserError<CWarning>
735 {
736 public:
737  CWarning(const string& msg);
738 };
739 
740 class CError : public pythonpp::CUserError<CError>
741 {
742 public:
743  CError(void)
744  { }
746  { x_Init(e, GetPyException()); }
747  CError(const string& msg, long db_errno = 0,
748  const string& db_msg = kEmptyStr)
749  { x_Init(msg, db_errno, db_msg, GetPyException()); }
750 
751 protected:
752  CError(const string& msg, PyObject* err_type);
753 
754  void x_Init(const CDB_Exception& e, PyObject* err_type);
755  void x_Init(const string& msg, long db_errno, const string& db_msg,
756  PyObject* err_type);
757  };
758 
759  #define PYTHON_DBAPI_ERROR_CLASS(Name, Base) \
760  class Name : public pythonpp::CUserError<Name, Base> \
761  { \
762  public: \
763  Name() \
764  { } \
765  Name(const CDB_Exception& e) \
766  { x_Init(e, GetPyException()); } \
767  Name(const string& msg, long db_errno = 0, \
768  const string& db_msg = kEmptyStr) \
769  { x_Init(msg, db_errno, db_msg, GetPyException()); } \
770  static void Rethrow(const CDB_Exception& e) \
771  { throw Name(e); } \
772  protected: \
773  Name(const string& msg, PyObject* err_type) \
774  : pythonpp::CUserError<Name, Base>(msg, err_type) \
775  { } \
776 }
777 
786 
787 /* Old implementation of CDatabaseError ...
788 class CDatabaseError : public pythonpp::CUserError<CDatabaseError, CError>
789 {
790 public:
791  CDatabaseError(const string& msg)
792  : pythonpp::CUserError<CDatabaseError, CError>( msg )
793  {
794  }
795 
796 protected:
797  CDatabaseError(const string& msg, PyObject* err_type)
798  : pythonpp::CUserError<CDatabaseError, CError>(msg, err_type)
799  {
800  }
801 };
802 */
803 
804 /* DO NOT delete this code.
805 class CDatabaseError : public pythonpp::CExtObject<CDatabaseError>, public pythonpp::CError
806 {
807 public:
808  typedef pythonpp::CExtObject<CDatabaseError> obj_type;
809 
810  CDatabaseError(void)
811  : m_db_errno(0)
812  {
813  obj_type::ROAttr(string("db_errno"), m_db_errno);
814  obj_type::ROAttr(string("db_msg"), m_db_msg);
815  }
816  CDatabaseError(const string& msg, long errno = 0, const string& db_msg = kEmptyStr)
817  : m_db_msg(db_msg)
818  , m_db_errno(errno)
819  {
820  ROAttr("db_errno", m_db_errno);
821  ROAttr("db_msg", m_db_msg);
822  }
823 
824 public:
825  static void Declare(
826  const char* name,
827  const char* descr = 0,
828  PyTypeObject* base = &PyBaseObject_Type
829  )
830  {
831  Py_INCREF(base);
832 
833  obj_type::Declare(name, descr, base);
834 
835  // if ( PyModule_AddObject( pythonpp::CModuleExt::GetPyModule(), const_cast<char*>(name), GetPyException() ) == -1 ) {
836  if ( PyModule_AddObject( pythonpp::CModuleExt::GetPyModule(), "DatabaseErrorExt", GetPyException() ) == -1 ) {
837  throw pythonpp::CSystemError( "Unable to add an object to a module" );
838  }
839  }
840 
841 public:
842  static PyObject* GetPyException(void)
843  {
844  static CDatabaseError obj;
845 
846  return &obj;
847  }
848 
849 private:
850  string m_db_msg;
851  long m_db_errno;
852 };
853 */
854 
855 //////////////////////////////////////////////////////////////////////////////
856 inline
857 const CConnection&
859 {
861 }
862 
863 inline
866 {
868 }
869 
870 //////////////////////////////////////////////////////////////////////////////
871 inline
872 const CConnection&
874 {
876 }
877 
878 inline
881 {
883 }
884 
885 }
886 
888 
889 
IDataSource –.
Definition: dbapi.hpp:938
CWarning(const string &msg)
auto_ptr< CResultSetProxy > m_RSProxy
const string m_Value
void rollback(void) const
IConnection * CreateDMLConnection(void)
EStatementType RetrieveStatementType(const string &stmt, EStatementType default_type)
string::size_type find_numeric(const string &str, string::size_type offset, int &param_len)
void CommitInternal(void) const
pythonpp::CObject m_PythonCursor
virtual bool MoveToNextRS(void)=0
pythonpp::CObject close(const pythonpp::CTuple &args)
auto_ptr< IStatement > m_Stmt
virtual bool MoveToLastRS(void)=0
PyObject * GetNext(void)
CConnection * m_ParentConnection
CCursor * CreateCursor(void)
void ExecuteCurrStatement(void)
CTransaction *const m_ParentTransaction
pythonpp::CObject cursor(const pythonpp::CTuple &args)
void x_Init(const CDB_Exception &e, PyObject *err_type)
static void handler(int)
pythonpp::CObject close(const pythonpp::CTuple &args)
Close the cursor now (rather than whenever __del__ is called).
CParamFmt(TFormat user_fmt=eTSQL, TFormat drv_fmt=eTSQL)
void FillDescription(pythonpp::CList &descr)
pythonpp::CObject fetchall(const pythonpp::CTuple &args)
Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e...
pythonpp::CList m_InfoMessages
CStmtStr(const string &str, EStatementType default_type=estSelect, const CParamFmt &fmt=CParamFmt())
IResultSet & GetRS(void)
pythonpp::CObject commit(const pythonpp::CTuple &args)
bool HasRS(void) const
CConnection & GetParentConnection(void)
const EConnectionMode m_ConnectionMode
pythonpp::CObject rollback(const pythonpp::CTuple &args)
CCallableStmtHelper m_CallableStmtHelper
size_type size() const
Definition: set.hpp:132
CTransaction * CreateTransaction(void)
void DestroyCursor(CCursor *cursor)
const TSeqPos offset(200)
void SetParam(const string &name, const CVariant &value, bool &output_param)
const CConnection & GetConnection(void) const
CStmtHelper m_StmtHelper
static PyObject * GetPyException(void)
pythonpp::CObject cursor(const pythonpp::CTuple &args)
#define kEmptyStr
Definition: ncbistr.hpp:120
void SetParam(const string &name, const CVariant &value)
CVariant GetCVariant(const pythonpp::CObject &obj) const
IConnection * MakeDBConnection(void) const
void Execute(bool cache_results=false)
set< CCursor * > TCursorList
void DestroySelectConnection(IConnection *db_conn)
pythonpp::CObject executemany(const pythonpp::CTuple &args)
Prepare a database operation (query or command) and then execute it against all parameter sequences o...
const CConnection & GetConnection(void) const
CVariant –.
Definition: variant.hpp:94
CDB_UserHandler * m_UserHandler
void FillDescription(pythonpp::CList &descr)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
IConnection * Create(void)
pythonpp::CObject setoutputsize(const pythonpp::CTuple &args)
Set a column buffer size for fetches of large columns (e.g.
CCursorIter(CCursor *cursor)
CTransaction * m_ParentTransaction
pythonpp::CObject __enter__(const pythonpp::CTuple &args)
pythonpp::CObject transaction(const pythonpp::CTuple &args)
void Destroy(IConnection *db_conn)
bool Empty(void) const
EStatementType m_StmType
CError(const CDB_Exception &e)
void CreateStmt(CDB_UserHandler *handler)
#define PYTHON_DBAPI_ERROR_CLASS(Name, Base)
CSelectConnPool m_SelectConnPool
CTransaction & GetDefaultTransaction(void)
static HSTMT stmt
Definition: rebindpar.c:12
virtual CVariantSet & GetRS(void)=0
CTransaction & GetTransaction(void)
CCursor(CTransaction *trans)
IConnection * CreateSelectConnection(void)
pythonpp::CObject rollback(const pythonpp::CTuple &args)
const CConnection & GetParentConnection(void) const
static bool isDML(EStatementType stmtType)
auto_ptr< IStatement > m_LocalStmt
void SetupParameters(const pythonpp::CDict &dict, CStmtHelper &stmt)
IStatement & GetLocalStmt(void) const
CTransaction(CConnection *conn, pythonpp::EOwnershipFuture ownnership=pythonpp::eOwned, EConnectionMode conn_mode=eSimpleMode)
CError(const string &msg, long db_errno=0, const string &db_msg=kEmptyStr)
EStatementType GetType(void) const
long GetRowCount(void) const
set< IConnection * > TConnectionList
int size
CConnection(const string &driver_name, const string &db_type, const string &server_name, const string &db_name, const string &user_name, const string &user_pswd, const pythonpp::CObject &extra_params)
void DestroyTransaction(CTransaction *trans)
void commit(void) const
TFormat GetUserFmt(void) const
void Destroy(IConnection *db_conn)
const ETransType m_TransType
virtual bool HandleIt(CDB_Exception *ex)
Handle the exceptions resulting from a native API call, one-by-one.
CDB_Exception –.
Definition: exception.hpp:116
TFormat GetDriverFmt(void) const
char value[7]
Definition: config.c:428
pythonpp::CObject nextset(const pythonpp::CTuple &args)
This method will make the cursor skip to the next available set, discarding any remaining rows from t...
string GetStr(void) const
auto_ptr< IResultSet > m_RS
void SetStr(const CStmtStr &stmt, CDB_UserHandler *handler)
pythonpp::CObject get_proc_return_status(const pythonpp::CTuple &args)
pythonpp::CTuple MakeTupleFromResult(IResultSet &rs)
PyObject * CreateIter(void)
string::size_type find_named(const string &str, string::size_type offset, int &param_len)
CInfoHandler_CursorCollect m_InfoHandler
auto_ptr< ICallableStatement > m_Stmt
string GetValue(void) const
static bool isDDL(EStatementType stmtType)
CTransaction *const m_ParentTransaction
static const char * str(char *buf, int n)
Definition: stats.c:84
Defines the database API innterfaces for a variety of DBMS.
void SetStr(const CStmtStr &stmt, CDB_UserHandler *handler)
pythonpp::CObject m_PythonConnection
string::size_type find_TSQL(const string &str, string::size_type offset, int &param_len)
IConnection * Create(void)
void DestroyDMLConnection(IConnection *db_conn)
static CS_CONNECTION * conn
Definition: get_send_data.c:18
void RollbackInternal(void) const
pythonpp::CObject commit(const pythonpp::CTuple &args)
virtual bool HasRS(void) const =0
set< CTransaction * > TTransList
CDBDefaultConnParams m_DefParams
pythonpp::CObject fetchmany(const pythonpp::CTuple &args)
Fetch the next set of rows of a query result, returning a sequence of sequences (e.g.
pythonpp::CObject m_Description
void SetStr(const string &str, EStatementType default_type=estSelect, const CParamFmt &fmt=CParamFmt())
pythonpp::CObject setinputsizes(const pythonpp::CTuple &args)
This can be used before a call to executeXXX() to predefine memory areas for the operation's paramete...
CSelectConnPool(CTransaction *trans, size_t size=3)
EConnectionMode m_ConnectionMode
pythonpp::CList m_DescrList
void AddInfoMessage(const string &message)
CCPPToolkitConnParams m_Params
CStmtHelper(CTransaction *trans)
CDBDefaultConnParams::
pythonpp::CObject m_PythonConnection
CCallableStmtHelper(CTransaction *trans)
pythonpp::CObject callproc(const pythonpp::CTuple &args)
Call a stored database procedure with the given name.
CTransaction * m_Transaction
pythonpp::CObject close(const pythonpp::CTuple &args)
pythonpp::CObject __enter__(const pythonpp::CTuple &args)
virtual void DumpResult(void)=0
void CreateStmt(CDB_UserHandler *handler)
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
pythonpp::CObject __enter__(const pythonpp::CTuple &args)
auto_ptr< IConnection > m_DMLConnection
pythonpp::CObject fetchone(const pythonpp::CTuple &args)
Fetch the next row of a query result set, returning a single sequence, or None when no more data is a...
pythonpp::CObject execute(const pythonpp::CTuple &args)
Prepare and execute a database operation (query or command).
CTransaction * m_DefTransaction
static const char * GetName(TFormat fmt)
CDMLConnPool(CTransaction *trans, ETransType trans_type=eImplicitTrans)
pythonpp::CObject m_PythonTransaction
Modified on Tue Aug 23 18:26:35 2016 by modify_doxy.py rev. 506947