EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SetSQLDumper Class Reference

Python object SQL dumper. More...

#include "RowsetReader.h"

Inheritance diagram for SetSQLDumper:
Collaboration diagram for SetSQLDumper:

Public Member Functions

 SetSQLDumper (const char *table, const char *keyField, FILE *out)
 
bool VisitTuple (const PyTuple *rep)
 the nested types Visitor More...
 
bool VisitObject (const PyObject *rep)
 Object type visitor. More...
 
- Public Member Functions inherited from PyVisitor
virtual ~PyVisitor ()
 
virtual bool VisitInteger (const PyInt *rep)
 primitive data visitors More...
 
virtual bool VisitLong (const PyLong *rep)
 
virtual bool VisitReal (const PyFloat *rep)
 
virtual bool VisitBoolean (const PyBool *rep)
 
virtual bool VisitNone (const PyNone *rep)
 
virtual bool VisitBuffer (const PyBuffer *rep)
 
virtual bool VisitString (const PyString *rep)
 
virtual bool VisitWString (const PyWString *rep)
 
virtual bool VisitToken (const PyToken *rep)
 
virtual bool VisitList (const PyList *rep)
 
virtual bool VisitDict (const PyDict *rep)
 
virtual bool VisitObjectEx (const PyObjectEx *rep)
 
virtual bool VisitPackedRow (const PyPackedRow *rep)
 PackedRow type visitor. More...
 
virtual bool VisitSubStruct (const PySubStruct *rep)
 wrapper types Visitor More...
 
virtual bool VisitSubStream (const PySubStream *rep)
 
virtual bool VisitChecksumedStream (const PyChecksumedStream *rep)
 

Protected Attributes

const std::string mTable
 
const std::string mKeyField
 
FILE *const mOut
 

Detailed Description

Python object SQL dumper.

Scans visited PyRep for any dumpable rowsets or tuplesets; if any is found, it's dumped using RowsetToSQL.

Author
Zhur, Bloody.Rabbit

Definition at line 191 of file RowsetReader.h.

Constructor & Destructor Documentation

SetSQLDumper::SetSQLDumper ( const char *  table,
const char *  keyField,
FILE *  out 
)

Definition at line 247 of file RowsetReader.cpp.

248 : mTable( table ),
249  mKeyField( keyField ),
250  mOut( out )
251 {
252 }
const std::string mKeyField
Definition: RowsetReader.h:203
FILE *const mOut
Definition: RowsetReader.h:204
const std::string mTable
Definition: RowsetReader.h:202

Member Function Documentation

bool SetSQLDumper::VisitObject ( const PyObject rep)
virtual

Object type visitor.

Reimplemented from PyVisitor.

Definition at line 311 of file RowsetReader.cpp.

References PyString::content(), mKeyField, mOut, mTable, sLog, PyObject::type(), and PyVisitor::VisitObject().

312 {
313  if( rep->type()->content() == "util.Rowset" )
314  {
315  //we found a friend, decode it
316  util_Rowset rowset;
317 
318  //must be duplicated in order to be decoded ...
319  PyObject* dup = new PyObject( *rep );
320  if( !rowset.Decode( &dup ) )
321  sLog.Error( "SetSQLDumper", "Unable to load a rowset from the object body!" );
322  else
323  {
324  RowsetReader reader( rowset );
325  if( ReaderToSQL<RowsetReader>( mTable.c_str(), mKeyField.c_str(), mOut, reader ) )
326  return true;
327 
328  sLog.Error( "SetSQLDumper", "Failed to convert rowset to SQL." );
329  }
330  }
331 
332  //fallback
333  return PyVisitor::VisitObject( rep );
334 }
const std::string mKeyField
Definition: RowsetReader.h:203
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
Python object.
Definition: PyRep.h:826
PyString * type() const
Definition: PyRep.h:844
virtual bool VisitObject(const PyObject *rep)
Object type visitor.
Definition: PyVisitor.cpp:69
FILE *const mOut
Definition: RowsetReader.h:204
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
const std::string mTable
Definition: RowsetReader.h:202

Here is the call graph for this function:

bool SetSQLDumper::VisitTuple ( const PyTuple rep)
virtual

the nested types Visitor

Reimplemented from PyVisitor.

Definition at line 254 of file RowsetReader.cpp.

References PyRep::AsList(), PyList::begin(), PyList::end(), PyTuple::GetItem(), PyRep::IsList(), mKeyField, mOut, mTable, PyTuple::size(), sLog, and PyVisitor::VisitTuple().

255 {
256  //first we want to check to see if this could possibly even be a tupleset.
257  if( 2 == rep->size()
258  && rep->GetItem( 0 )->IsList()
259  && rep->GetItem( 1 )->IsList() )
260  {
261  const PyList* possible_header = rep->GetItem( 0 )->AsList();
262  const PyList* possible_items = rep->GetItem( 1 )->AsList();
263 
264  //check each element of the lists to make sure they line up.
265  bool valid = true;
266  PyList::const_iterator cur, end;
267 
268  cur = possible_header->begin();
269  end = possible_header->end();
270  for(; valid && cur != end; ++cur)
271  {
272  if( !(*cur)->IsString() )
273  valid = false;
274  }
275 
276  cur = possible_items->begin();
277  end = possible_items->end();
278  for(; valid && cur != end; ++cur)
279  {
280  if( !(*cur)->IsList() )
281  valid = false;
282 
283  //it would be possible I guess to check each element of each item to make sure
284  //it is a terminal type (non-container), but I dont care right now.
285  }
286 
287  if( valid )
288  {
289  //ok, it looks like a tupleset... nothing we can do now but interpret it as one...
290  util_Tupleset rowset;
291 
292  //must be duplicated in order to be decoded ...
293  PyTuple* dup = new PyTuple( *rep );
294  if( !rowset.Decode( &dup ) )
295  sLog.Error( "SetSQLDumper", "Unable to interpret tuple as a tupleset, it may not even be one." );
296  else
297  {
298  TuplesetReader reader( rowset );
299  if( ReaderToSQL<TuplesetReader>( mTable.c_str(), mKeyField.c_str(), mOut, reader ) )
300  return true;
301 
302  sLog.Error( "SetSQLDumper", "Failed to convert tupleset to SQL." );
303  }
304  }
305  }
306 
307  //fallback
308  return PyVisitor::VisitTuple( rep );
309 }
virtual bool VisitTuple(const PyTuple *rep)
the nested types Visitor
Definition: PyVisitor.cpp:36
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
size_t size() const
Definition: PyRep.h:591
const std::string mKeyField
Definition: RowsetReader.h:203
const_iterator begin() const
Definition: PyRep.h:660
storage_type::const_iterator const_iterator
Definition: PyRep.h:644
Python tuple.
Definition: PyRep.h:567
bool IsList() const
Definition: PyRep.h:109
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
PyList * AsList()
Definition: PyRep.h:140
const_iterator end() const
Definition: PyRep.h:661
FILE *const mOut
Definition: RowsetReader.h:204
const std::string mTable
Definition: RowsetReader.h:202
Python list.
Definition: PyRep.h:639

Here is the call graph for this function:

Member Data Documentation

const std::string SetSQLDumper::mKeyField
protected

Definition at line 203 of file RowsetReader.h.

Referenced by VisitObject(), and VisitTuple().

FILE* const SetSQLDumper::mOut
protected

Definition at line 204 of file RowsetReader.h.

Referenced by VisitObject(), and VisitTuple().

const std::string SetSQLDumper::mTable
protected

Definition at line 202 of file RowsetReader.h.

Referenced by VisitObject(), and VisitTuple().


The documentation for this class was generated from the following files: