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 98960 2023-01-26 16:13:39Z 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 CBinaryType : public pythonpp::CExtObject<CBinaryType>
55 {
56 public:
57  CBinaryType(void);
58  CBinaryType(const string& value);
59  ~CBinaryType(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 ////////////////////////////////////////////////////////////////////////////////
116  };
117 
119 RetrieveStatementType(const string& stmt,
120  EStatementType default_type = estNone,
121  ETriState output_expected = eTriState_Unknown);
122 
124 
125 ////////////////////////////////////////////////////////////////////////////////
127 {
128 public:
130 
131  CParamFmt(TFormat user_fmt = eTSQL, TFormat drv_fmt = eTSQL);
132 
133 public:
134  TFormat GetUserFmt(void) const
135  {
136  return m_UserFmt;
137  }
138  TFormat GetDriverFmt(void) const
139  {
140  return m_DrvFmt;
141  }
142  static const char* GetName(TFormat fmt);
143 
144 private:
147 };
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 class CStmtStr
151 {
152 public:
153  CStmtStr(void)
154  : m_StmType(estNone)
155  {
156  }
157  CStmtStr(const string& str,
158  EStatementType default_type = estSelect,
159  const CParamFmt& fmt = CParamFmt()
160  )
161  : m_StmType(estNone)
162  {
163  SetStr(str, default_type, fmt);
164  }
165 
166  // We will accume that SQL has type estFunction if it is
167  // hard to get an actual type.
168  void SetStr(const string& str,
169  EStatementType default_type = estSelect,
170  const CParamFmt& fmt = CParamFmt(),
171  ETriState output_expected = eTriState_Unknown
172  );
173 
174 public:
175  string GetStr(void) const
176  {
177  return m_StmtStr;
178  }
180  {
181  return m_StmType;
182  }
183 
184 private:
185  string::size_type find_numeric(const string& str,
186  string::size_type offset,
187  int& param_len
188  );
189  string::size_type find_named(const string& str,
190  string::size_type offset,
191  int& param_len
192  );
193  string::size_type find_TSQL(const string& str,
194  string::size_type offset,
195  int& param_len
196  );
197 
198 private:
199  string m_StmtStr;
201 };
202 
203 //////////////////////////////////////////////////////////////////////////////
204 // Forward declaration ...
205 class CConnection;
206 class CTransaction;
207 
208 //////////////////////////////////////////////////////////////////////////////
209 // IStatement plus additinal informaion ...
211 {
212 public:
213  CStmtHelper(CTransaction* trans);
214  CStmtHelper(CTransaction* trans, const CStmtStr& stmt);
215  ~CStmtHelper(void);
216 
217 public:
218  // void SetStr(const string& stmt, EStatementType default_type = estFunction);
219  void SetStr(const CStmtStr& stmt, CDB_UserHandler* handler);
220  void SetParam(const string& name, const CVariant& value);
221  void SetParam(size_t index, const CVariant& value);
222 
223  void Execute(void);
224  void Close(void);
225  long GetRowCount(void) const;
226  void FillDescription(pythonpp::CList& descr);
227 
228  bool MoveToNextRS(void);
229  IResultSet& GetRS(void);
230  const IResultSet& GetRS(void) const;
231  bool HasRS(void) const;
232 
233  int GetReturnStatus(void);
234 
235 private:
236  void DumpResult(void);
237  void ReleaseStmt(void);
239 
240 private:
241  CTransaction* const m_ParentTransaction; //< A transaction to which belongs this cursor object
242  unique_ptr<IStatement> m_Stmt; //< DBAPI SQL statement interface
243  unique_ptr<IResultSet> m_RS;
249 };
250 
251 //////////////////////////////////////////////////////////////////////////////
252 class CVariantSet;
253 
255 {
256 public:
257  virtual ~CResultSetProxy(void) {}
258 
259  virtual bool MoveToNextRS(void) = 0;
260  virtual bool MoveToLastRS(void) = 0;
261  virtual CVariantSet& GetRS(void) = 0;
262  virtual const CVariantSet& GetRS(void) const = 0;
263  virtual bool HasRS(void) const = 0;
264  virtual void DumpResult(void) = 0;
265 };
266 
267 //////////////////////////////////////////////////////////////////////////////
268 // ICallableStatement plus additinal informaion ...
270 {
271 public:
274  ~CCallableStmtHelper(void);
275 
276 public:
277  // void SetStr(const string& stmt, int num_arg, EStatementType default_type = estFunction);
278  void SetStr(const CStmtStr& stmt, CDB_UserHandler* handler);
279  void SetParam(const string& name, const CVariant& value, bool& output_param);
280  void SetParam(size_t index, const CVariant& value, bool& output_param);
281 
282  void Execute(bool cache_results = false);
283  void Close(void);
284  long GetRowCount(void) const;
285  void FillDescription(pythonpp::CList& descr);
286 
287  bool MoveToNextRS(void);
288  bool MoveToLastRS(void);
289  CVariantSet& GetRS(void);
290  const CVariantSet& GetRS(void) const;
291  bool HasRS(void) const;
292 
293  int GetReturnStatus(void);
294 
295 private:
296  void DumpResult(void);
297  void ReleaseStmt(void);
299 
300 private:
301  CTransaction* const m_ParentTransaction; //< A transaction to which belongs this cursor object
302  unique_ptr<ICallableStatement> m_Stmt; //< DBAPI SQL statement interface
303  unique_ptr<CResultSetProxy> m_RSProxy;
309 };
310 
311 class CCursor;
312 
314 {
315 public:
317  : m_Cursor(cursor)
318  {}
319 
321 
322  virtual bool HandleIt(CDB_Exception* ex);
323 
324 private:
326 };
327 
328 //////////////////////////////////////////////////////////////////////////////
329 // Cursor borrows connections from a parent transaction.
330 class CCursor : public pythonpp::CExtObject<CCursor>
331 {
332  friend class CTransaction;
333 
334 protected:
335  CCursor(CTransaction* trans);
336 
337 public:
338  ~CCursor(void);
339 
340  void AddInfoMessage(const string& message);
341 
342 public:
343  // Python methods ...
344 
345  /// Call a stored database procedure with the given name. The
346  /// sequence of parameters must contain one entry for each
347  /// argument that the procedure expects. The result of the
348  /// call is returned as modified copy of the input
349  /// sequence. Input parameters are left untouched, output and
350  /// input/output parameters replaced with possibly new values.
351  /// callproc(procname[,parameters]);
354  /// Close the cursor now (rather than whenever __del__ is
355  /// called). The cursor will be unusable from this point
356  /// forward; an Error (or subclass) exception will be raised
357  /// if any operation is attempted with the cursor.
358  /// close();
360  /// Prepare and execute a database operation (query or
361  /// command). Parameters may be provided as sequence or
362  /// mapping and will be bound to variables in the operation.
363  /// Variables are specified in a database-specific notation
364  /// (see the module's paramstyle attribute for details). [5]
365  /// execute(operation[,parameters]);
367  const pythonpp::CDict& kwargs);
368  PyObject* CreateIter(void);
369  /// Prepare a database operation (query or command) and then
370  /// execute it against all parameter sequences or mappings
371  /// found in the sequence seq_of_parameters.
372  /// executemany(operation,seq_of_parameters);
374  const pythonpp::CDict& kwargs);
375  /// Fetch the next row of a query result set, returning a
376  /// single sequence, or None when no more data is
377  /// available. [6]
378  /// An Error (or subclass) exception is raised if the previous
379  /// call to executeXXX() did not produce any result set or no
380  /// call was issued yet.
381  /// fetchone();
383  /// Fetch the next set of rows of a query result, returning a
384  /// sequence of sequences (e.g. a list of tuples). An empty
385  /// sequence is returned when no more rows are available.
386  /// The number of rows to fetch per call is specified by the
387  /// parameter. If it is not given, the cursor's arraysize
388  /// determines the number of rows to be fetched. The method
389  /// should try to fetch as many rows as indicated by the size
390  /// parameter. If this is not possible due to the specified
391  /// number of rows not being available, fewer rows may be
392  /// returned.
393  /// An Error (or subclass) exception is raised if the previous
394  /// call to executeXXX() did not produce any result set or no
395  /// call was issued yet.
396  /// fetchmany([size=cursor.arraysize]);
398  /// Fetch all (remaining) rows of a query result, returning
399  /// them as a sequence of sequences (e.g. a list of tuples).
400  /// Note that the cursor's arraysize attribute can affect the
401  /// performance of this operation.
402  /// An Error (or subclass) exception is raised if the previous
403  /// call to executeXXX() did not produce any result set or no
404  /// call was issued yet.
405  /// fetchall();
407  /// This method will make the cursor skip to the next
408  /// available set, discarding any remaining rows from the
409  /// current set.
410  /// If there are no more sets, the method returns
411  /// None. Otherwise, it returns a true value and subsequent
412  /// calls to the fetch methods will return rows from the next
413  /// result set.
414  /// An Error (or subclass) exception is raised if the previous
415  /// call to executeXXX() did not produce any result set or no
416  /// call was issued yet.
417  /// nextset();
419  /// This can be used before a call to executeXXX() to
420  /// predefine memory areas for the operation's parameters.
421  /// sizes is specified as a sequence -- one item for each
422  /// input parameter. The item should be a Type Object that
423  /// corresponds to the input that will be used, or it should
424  /// be an integer specifying the maximum length of a string
425  /// parameter. If the item is None, then no predefined memory
426  /// area will be reserved for that column (this is useful to
427  /// avoid predefined areas for large inputs).
428  /// This method would be used before the executeXXX() method
429  /// is invoked.
430  /// setinputsizes(sizes);
432  /// Set a column buffer size for fetches of large columns
433  /// (e.g. LONGs, BLOBs, etc.). The column is specified as an
434  /// index into the result sequence. Not specifying the column
435  /// will set the default size for all large columns in the
436  /// cursor.
437  /// This method would be used before the executeXXX() method
438  /// is invoked.
439  /// setoutputsize(size[,column]);
441  //
443 
444 private:
446  {
447  return *m_ParentTransaction;
448  }
449 
450 private:
451  void CloseInternal(void);
452  bool NextSetInternal(void);
453 
454 private:
455  CVariant GetCVariant(const pythonpp::CObject& obj) const;
456 
457  void SetupParameters(const pythonpp::CDict& dict, CStmtHelper& stmt);
459  // Return *true* if there are output parameters.
461  void SetupParameters(const pythonpp::CSequence& dict,
463  vector<size_t>* out_params);
464 
466 
467  static bool isDML(EStatementType stmtType)
468  {
469  return stmtType == estInsert || stmtType == estDelete || stmtType == estUpdate;
470  }
471  static bool isDDL(EStatementType stmtType)
472  {
473  return stmtType == estCreate || stmtType == estDrop || stmtType == estAlter;
474  }
475 
476 private:
477  pythonpp::CObject m_PythonConnection; //< For reference counting purposes only
478  pythonpp::CObject m_PythonTransaction; //< For reference counting purposes only
479  CTransaction* m_ParentTransaction; //< A transaction to which belongs this cursor object
480  int m_NumOfArgs; //< Number of arguments in a callable statement
481  long m_RowsNum;
487  size_t m_ArraySize;
493  bool m_Closed;
494 };
495 
496 class CCursorIter : public pythonpp::CExtObject<CCursorIter>
497 {
498  friend class CCursor;
499 
500 protected:
501  CCursorIter(CCursor* cursor);
502 
503 public:
504  ~CCursorIter(void);
505 
506 public:
507  PyObject* GetNext(void);
508 
509 public:
513 };
514 
515 //////////////////////////////////////////////////////////////////////////////
518 
519 //////////////////////////////////////////////////////////////////////////////
521 {
522 public:
523  CSelectConnPool(CTransaction* trans, size_t size = 3);
524 
525 public:
526  IConnection* Create(void);
527  void Destroy(IConnection* db_conn);
528  void Clear(void);
529  // Means that nobody uses connections from the pool.
530  bool Empty(void) const
531  {
532  return ((m_ConnList.size() - m_ConnPool.size()) == 0);
533  }
534 
535 private:
536  const CConnection& GetConnection(void) const;
537  CConnection& GetConnection(void);
538 
539 private:
541  const size_t m_PoolSize;
542  TConnectionList m_ConnPool; //< A pool of connection for SELECT statements
543  TConnectionList m_ConnList; //< A list of all allocated connection for SELECT statements
544 };
545 
546 //////////////////////////////////////////////////////////////////////////////
547 
548 // eImplicitTrans meant that a transaction will be started automaticaly,
549 // without your help.
550 // eExplicitTrans means that you have to start a transaction manualy by calling
551 // the "BEGIN TRANSACTION" statement.
553 
554 // A pool with one connection only ...
555 // Strange but useful ...
557 {
558 public:
559  CDMLConnPool( CTransaction* trans, ETransType trans_type = eImplicitTrans );
560 
561 public:
562  IConnection* Create(void);
563  void Destroy(IConnection* db_conn);
564  void Clear(void);
565  bool Empty(void) const
566  {
567  return (m_NumOfActive == 0);
568  }
569 
570 public:
571  void commit(void) const;
572  void rollback(void) const;
573 
574 private:
575  const CConnection& GetConnection(void) const;
576  CConnection& GetConnection(void);
577 
578  IStatement& GetLocalStmt(void) const;
579 
580 private:
582  unique_ptr<IConnection> m_DMLConnection; //< Transaction has only one DML connection
584  unique_ptr<IStatement> m_LocalStmt; //< DBAPI SQL statement interface
585  bool m_Started;
587 };
588 
589 //////////////////////////////////////////////////////////////////////////////
590 class CTransaction : public pythonpp::CExtObject<CTransaction>
591 {
592  friend class CConnection;
593  friend class CSelectConnPool;
594  friend class CDMLConnPool;
595 
596 protected:
597  CTransaction(
598  CConnection* conn,
600  EConnectionMode conn_mode = eSimpleMode
601  );
602 
603 public:
604  ~CTransaction(void);
605 
606 public:
612 
613 public:
614  // CCursor factory interface ...
615  CCursor* CreateCursor(void);
617 
618 public:
619  // Factory for DML connections (actualy, only one connection)
621  {
622  return m_DMLConnPool.Create();
623  }
625  {
626  m_DMLConnPool.Destroy(db_conn);
627  }
628 
629 public:
630  // Factory for "data-retrieval" connections
632  void DestroySelectConnection(IConnection* db_conn);
633 
634 public:
635  const CConnection& GetParentConnection(void) const
636  {
637  return *m_ParentConnection;
638  }
640  {
641  return *m_ParentConnection;
642  }
643 
644 protected:
645  void CloseInternal(void);
646  void CommitInternal(void) const
647  {
649  }
650  void RollbackInternal(void) const
651  {
653  }
654  void CloseOpenCursors(void);
655 
656 private:
657  pythonpp::CObject m_PythonConnection; //< For reference counting purposes only
658  CConnection* m_ParentConnection; //< A connection to which belongs this transaction object
660 
661  CDMLConnPool m_DMLConnPool; //< A pool of connections for DML statements
662  CSelectConnPool m_SelectConnPool; //< A pool of connections for SELECT statements
664 };
665 
666 //////////////////////////////////////////////////////////////////////////////
667 // CConnection does not represent an "physical" connection to a database.
668 // In current implementation CConnection is a factory of CTransaction.
669 // CTransaction owns and manages "physical" connections to a database.
670 
671 class CConnection : public pythonpp::CExtObject<CConnection>
672 {
673 public:
674  CConnection(
675  const string& driver_name,
676  const string& db_type,
677  const string& server_name,
678  const string& db_name,
679  const string& user_name,
680  const string& user_pswd,
681  const pythonpp::CObject& extra_params
682  );
683  ~CConnection(void);
684 
685 public:
686  // Python Interface ...
693 
694 public:
695  // Connection factory interface ...
696  IConnection* MakeDBConnection(void) const;
697 
698 public:
699  // CTransaction factory interface ...
701  void DestroyTransaction(CTransaction* trans);
702 
703 protected:
705  {
706  return *m_DefTransaction;
707  }
708 
709 private:
711 
714 
717  CTransaction* m_DefTransaction; //< The lifetime of the default transaction will be managed by Python
718  TTransList m_TransList; //< List of user-defined transactions
720  string m_ModuleName;
721 };
722 
723 //////////////////////////////////////////////////////////////////////////////
724 // Python Database API exception classes ... 2/4/2005 8:18PM
725 
726 // This is the exception inheritance layout:
727 //
728 // StandardError
729 // |__Warning
730 // |__Error
731 // |__InterfaceError
732 // |__DatabaseError
733 // |__DataError
734 // |__OperationalError
735 // |__IntegrityError
736 // |__InternalError
737 // |__ProgrammingError
738 // |__NotSupportedError
739 
740 class CWarning : public pythonpp::CUserError<CWarning>
741 {
742 public:
743  CWarning(const string& msg);
744 };
745 
746 class CError : public pythonpp::CUserError<CError>
747 {
748 public:
749  CError(void)
750  { }
752  { x_Init(e, GetPyException()); }
753  CError(const string& msg, long db_errno = 0,
754  const string& db_msg = kEmptyStr)
755  { x_Init(msg, db_errno, db_msg, GetPyException()); }
756 
757 protected:
758  CError(const string& msg, PyObject* err_type);
759 
760  void x_Init(const CDB_Exception& e, PyObject* err_type);
761  void x_Init(const string& msg, long db_errno, const string& db_msg,
762  PyObject* err_type);
763  };
764 
765  #define PYTHON_DBAPI_ERROR_CLASS(Name, Base) \
766  class Name : public pythonpp::CUserError<Name, Base> \
767  { \
768  public: \
769  Name() \
770  { } \
771  Name(const CDB_Exception& e) \
772  { x_Init(e, GetPyException()); } \
773  Name(const string& msg, long db_errno = 0, \
774  const string& db_msg = kEmptyStr) \
775  { x_Init(msg, db_errno, db_msg, GetPyException()); } \
776  static void Rethrow(const CDB_Exception& e) \
777  { throw Name(e); } \
778  protected: \
779  Name(const string& msg, PyObject* err_type) \
780  : pythonpp::CUserError<Name, Base>(msg, err_type) \
781  { } \
782 }
783 
792 
793 /* Old implementation of CDatabaseError ...
794 class CDatabaseError : public pythonpp::CUserError<CDatabaseError, CError>
795 {
796 public:
797  CDatabaseError(const string& msg)
798  : pythonpp::CUserError<CDatabaseError, CError>( msg )
799  {
800  }
801 
802 protected:
803  CDatabaseError(const string& msg, PyObject* err_type)
804  : pythonpp::CUserError<CDatabaseError, CError>(msg, err_type)
805  {
806  }
807 };
808 */
809 
810 /* DO NOT delete this code.
811 class CDatabaseError : public pythonpp::CExtObject<CDatabaseError>, public pythonpp::CError
812 {
813 public:
814  typedef pythonpp::CExtObject<CDatabaseError> obj_type;
815 
816  CDatabaseError(void)
817  : m_db_errno(0)
818  {
819  obj_type::ROAttr(string("db_errno"), m_db_errno);
820  obj_type::ROAttr(string("db_msg"), m_db_msg);
821  }
822  CDatabaseError(const string& msg, long errno = 0, const string& db_msg = kEmptyStr)
823  : m_db_msg(db_msg)
824  , m_db_errno(errno)
825  {
826  ROAttr("db_errno", m_db_errno);
827  ROAttr("db_msg", m_db_msg);
828  }
829 
830 public:
831  static void Declare(
832  const char* name,
833  const char* descr = 0,
834  PyTypeObject* base = &PyBaseObject_Type
835  )
836  {
837  Py_INCREF(base);
838 
839  obj_type::Declare(name, descr, base);
840 
841  // if ( PyModule_AddObject( pythonpp::CModuleExt::GetPyModule(), const_cast<char*>(name), GetPyException() ) == -1 ) {
842  if ( PyModule_AddObject( pythonpp::CModuleExt::GetPyModule(), "DatabaseErrorExt", GetPyException() ) == -1 ) {
843  throw pythonpp::CSystemError( "Unable to add an object to a module" );
844  }
845  }
846 
847 public:
848  static PyObject* GetPyException(void)
849  {
850  static CDatabaseError obj;
851 
852  return &obj;
853  }
854 
855 private:
856  string m_db_msg;
857  long m_db_errno;
858 };
859 */
860 
861 //////////////////////////////////////////////////////////////////////////////
862 inline
863 const CConnection&
865 {
867 }
868 
869 inline
872 {
874 }
875 
876 //////////////////////////////////////////////////////////////////////////////
877 inline
878 const CConnection&
880 {
882 }
883 
884 inline
887 {
889 }
890 
891 }
892 
894 
895 
CDB_Exception –.
Definition: exception.hpp:118
CVariant –.
Definition: variant.hpp:99
IDataSource –.
Definition: dbapi.hpp:963
string GetValue(void) const
CTransaction *const m_ParentTransaction
CCallableStmtHelper(CTransaction *trans)
unique_ptr< ICallableStatement > m_Stmt
unique_ptr< CResultSetProxy > m_RSProxy
void SetStr(const CStmtStr &stmt, CDB_UserHandler *handler)
void SetParam(const string &name, const CVariant &value, bool &output_param)
void CreateStmt(CDB_UserHandler *handler)
void FillDescription(pythonpp::CList &descr)
void Execute(bool cache_results=false)
CCPPToolkitConnParams m_Params
CTransaction * CreateTransaction(void)
void DestroyTransaction(CTransaction *trans)
EConnectionMode m_ConnectionMode
set< CTransaction * > TTransList
pythonpp::CObject __enter__(const pythonpp::CTuple &args)
CDBDefaultConnParams m_DefParams
pythonpp::CObject commit(const pythonpp::CTuple &args)
IConnection * MakeDBConnection(void) const
pythonpp::CObject close(const pythonpp::CTuple &args)
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)
pythonpp::CObject rollback(const pythonpp::CTuple &args)
CTransaction * m_DefTransaction
CTransaction & GetDefaultTransaction(void)
pythonpp::CObject cursor(const pythonpp::CTuple &args)
pythonpp::CObject transaction(const pythonpp::CTuple &args)
CCursorIter(CCursor *cursor)
PyObject * GetNext(void)
pythonpp::CObject m_PythonCursor
CStmtHelper m_StmtHelper
pythonpp::CObject fetchmany(const pythonpp::CTuple &args)
Fetch the next set of rows of a query result, returning a sequence of sequences (e....
pythonpp::CList m_InfoMessages
pythonpp::CObject __enter__(const pythonpp::CTuple &args)
pythonpp::CList m_DescrList
void ExecuteCurrStatement(void)
void AddInfoMessage(const string &message)
pythonpp::CObject m_Description
pythonpp::CObject m_PythonTransaction
pythonpp::CObject fetchall(const pythonpp::CTuple &args)
Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e....
CInfoHandler_CursorCollect m_InfoHandler
PyObject * CreateIter(void)
CCursor(CTransaction *trans)
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...
pythonpp::CObject close(const pythonpp::CTuple &args)
Close the cursor now (rather than whenever __del__ is called).
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 get_proc_return_status(const pythonpp::CTuple &args)
CCallableStmtHelper m_CallableStmtHelper
CTransaction * m_ParentTransaction
static bool isDML(EStatementType stmtType)
static bool isDDL(EStatementType stmtType)
pythonpp::CObject execute(const pythonpp::CTuple &args, const pythonpp::CDict &kwargs)
Prepare and execute a database operation (query or command).
void SetupParameters(const pythonpp::CDict &dict, CStmtHelper &stmt)
pythonpp::CObject callproc(const pythonpp::CTuple &args)
Call a stored database procedure with the given name.
pythonpp::CObject m_PythonConnection
CVariant GetCVariant(const pythonpp::CObject &obj) const
pythonpp::CObject setoutputsize(const pythonpp::CTuple &args)
Set a column buffer size for fetches of large columns (e.g.
pythonpp::CObject executemany(const pythonpp::CTuple &args, const pythonpp::CDict &kwargs)
Prepare a database operation (query or command) and then execute it against all parameter sequences o...
CTransaction & GetTransaction(void)
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...
CDMLConnPool(CTransaction *trans, ETransType trans_type=eImplicitTrans)
const ETransType m_TransType
IStatement & GetLocalStmt(void) const
unique_ptr< IStatement > m_LocalStmt
CTransaction * m_Transaction
const CConnection & GetConnection(void) const
IConnection * Create(void)
void Destroy(IConnection *db_conn)
unique_ptr< IConnection > m_DMLConnection
CError(const CDB_Exception &e)
void x_Init(const CDB_Exception &e, PyObject *err_type)
CError(const string &msg, long db_errno=0, const string &db_msg=kEmptyStr)
virtual bool HandleIt(CDB_Exception *ex)
Handle the exceptions resulting from a native API call, one-by-one.
TFormat GetDriverFmt(void) const
static const char * GetName(TFormat fmt)
TFormat GetUserFmt(void) const
CParamFmt(TFormat user_fmt=eTSQL, TFormat drv_fmt=eTSQL)
virtual void DumpResult(void)=0
virtual bool HasRS(void) const =0
virtual const CVariantSet & GetRS(void) const =0
virtual bool MoveToLastRS(void)=0
virtual bool MoveToNextRS(void)=0
virtual CVariantSet & GetRS(void)=0
const CConnection & GetConnection(void) const
void Destroy(IConnection *db_conn)
IConnection * Create(void)
CSelectConnPool(CTransaction *trans, size_t size=3)
void FillDescription(pythonpp::CList &descr)
CDB_UserHandler * m_UserHandler
void SetParam(const string &name, const CVariant &value)
unique_ptr< IResultSet > m_RS
CStmtHelper(CTransaction *trans)
void SetStr(const CStmtStr &stmt, CDB_UserHandler *handler)
long GetRowCount(void) const
CTransaction *const m_ParentTransaction
unique_ptr< IStatement > m_Stmt
IResultSet & GetRS(void)
void CreateStmt(CDB_UserHandler *handler)
string::size_type find_named(const string &str, string::size_type offset, int &param_len)
EStatementType GetType(void) const
CStmtStr(const string &str, EStatementType default_type=estSelect, const CParamFmt &fmt=CParamFmt())
void SetStr(const string &str, EStatementType default_type=estSelect, const CParamFmt &fmt=CParamFmt(), ETriState output_expected=eTriState_Unknown)
string::size_type find_numeric(const string &str, string::size_type offset, int &param_len)
string::size_type find_TSQL(const string &str, string::size_type offset, int &param_len)
EStatementType m_StmType
string GetStr(void) const
pythonpp::CObject __enter__(const pythonpp::CTuple &args)
IConnection * CreateSelectConnection(void)
pythonpp::CObject commit(const pythonpp::CTuple &args)
pythonpp::CObject rollback(const pythonpp::CTuple &args)
CTransaction(CConnection *conn, pythonpp::EOwnershipFuture ownnership=pythonpp::eOwned, EConnectionMode conn_mode=eSimpleMode)
const CConnection & GetParentConnection(void) const
IConnection * CreateDMLConnection(void)
void RollbackInternal(void) const
CSelectConnPool m_SelectConnPool
CCursor * CreateCursor(void)
pythonpp::CObject close(const pythonpp::CTuple &args)
void DestroyCursor(CCursor *cursor)
CConnection & GetParentConnection(void)
void DestroySelectConnection(IConnection *db_conn)
void CommitInternal(void) const
void DestroyDMLConnection(IConnection *db_conn)
CConnection * m_ParentConnection
const EConnectionMode m_ConnectionMode
pythonpp::CObject m_PythonConnection
pythonpp::CObject cursor(const pythonpp::CTuple &args)
CWarning(const string &msg)
static PyObject * GetPyException(void)
size_type size() const
Definition: set.hpp:132
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
Defines the database API innterfaces for a variety of DBMS.
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static HSTMT stmt
Definition: rebindpar.c:12
static const char * str(char *buf, int n)
Definition: stats.c:84
int offset
Definition: replacements.h:160
ETriState
Enumeration to represent a tristate value.
Definition: ncbimisc.hpp:128
@ eTriState_Unknown
The value is indeterminate.
Definition: ncbimisc.hpp:129
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
const struct ncbi::grid::netcache::search::fields::SIZE size
set< CCursor * > TCursorList
set< IConnection * > TConnectionList
EStatementType RetrieveStatementType(const string &stmt, EStatementType default_type, ETriState output_expected)
pythonpp::CTuple MakeTupleFromResult(IResultSet &rs)
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define PYTHON_DBAPI_ERROR_CLASS(Name, Base)
Modified on Wed Apr 17 13:11:04 2024 by modify_doxy.py rev. 669887