SQL Relay C++ API
Public Member Functions | Protected Member Functions | List of all members
sqlrexport Class Reference

#include <sqlrexport.h>

Inherited by sqlrexportdomnode [virtual], sqlrexportfile [virtual], and sqlrexporttable [virtual].

Public Member Functions

 sqlrexport ()
 
virtual ~sqlrexport ()
 
void setSqlrConnection (sqlrconnection *sqlrcon)
 
void setSqlrCursor (sqlrcursor *sqlrcur)
 
sqlrconnectiongetSqlrConnection ()
 
sqlrcursorgetSqlrCursor ()
 
void setTable (const char *table)
 
const char * getTable ()
 
void setExcludeColumns (bool excludecolumns)
 
bool getExcludeColumns ()
 
void setColumnsToExclude (const char *const *columnstoexclude)
 
const char *const * getColumnsToExclude ()
 
void setLogger (logger *lg)
 
logger * getLogger ()
 
void setCoarseLogLevel (uint8_t coarseloglevel)
 
uint8_t getCoarseLogLevel ()
 
void setFineLogLevel (uint8_t fineloglevel)
 
uint8_t getFineLogLevel ()
 
void setLogIndent (uint32_t logindent)
 
uint32_t getLogIndent ()
 
void setLogErrors (bool logerrors)
 
bool getLogErrors ()
 
virtual bool exportData ()
 
uint64_t getExportedRowCount ()
 

Protected Member Functions

virtual bool exportStart ()
 
virtual bool columnsStart ()
 
virtual bool columnStart ()
 
virtual bool columnEnd ()
 
virtual bool columnsEnd ()
 
virtual bool rowsStart ()
 
virtual bool rowStart ()
 
virtual bool fieldStart ()
 
virtual bool fieldEnd ()
 
virtual bool rowEnd ()
 
virtual bool rowsEnd ()
 
virtual bool beginStart ()
 
virtual bool beginEnd ()
 
virtual bool commitStart ()
 
virtual bool commitEnd ()
 
virtual bool error (int64_t errornumber, const char *errormessage)
 
virtual bool exportEnd ()
 
void setExcludeRow (bool excluderow)
 
bool getExcludeRow ()
 
void setCurrentRow (uint64_t currentrow)
 
uint64_t getCurrentRow ()
 
void setCurrentColumn (uint32_t currentcol)
 
uint32_t getCurrentColumn ()
 
void setCurrentColumnName (const char *currentcolname)
 
const char * getCurrentColumnName ()
 
void setCurrentField (const char *currentfield)
 
const char * getCurrentField ()
 
void setIsNumericColumn (uint64_t index, bool numeric)
 
bool getIsNumericColumn (uint64_t index)
 
void clearAreNumericColumns ()
 
void setExportedRowCount (uint64_t exportedrowcount)
 

Detailed Description

The sqlrexport class provides a base class for child classes that wish to implement export of data from a database, via SQL Relay. It provides various common methods. Each child class should implement the exportData() method.

Constructor & Destructor Documentation

◆ sqlrexport()

sqlrexport::sqlrexport ( )

Creates an instance of the sqlrexport class.

◆ ~sqlrexport()

virtual sqlrexport::~sqlrexport ( )
virtual

Destroys this instance of the sqlrexport class.

Member Function Documentation

◆ beginEnd()

virtual bool sqlrexport::beginEnd ( )
protectedvirtual

This method should be called after a begin().

This implementation just returns true but a child class may override this method to do something else.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ beginStart()

virtual bool sqlrexport::beginStart ( )
protectedvirtual

This method should be called before a begin().

This implementation just returns true but a child class may override this method to do something else.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ clearAreNumericColumns()

void sqlrexport::clearAreNumericColumns ( )
protected

Clears the data types of all columns, setting them to to non-numeric.

Not commonly called by implementations of the *Start/End() methods.

◆ columnEnd()

virtual bool sqlrexport::columnEnd ( )
protectedvirtual

This method should be called after the export of each column.

Note that it should be called for each column, whether or not columns are excluded, and whether or not this particular column is excluded.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

If you called setColumnName(...) in columnStart(), and had to allocate memory for the new value, then this may be an appropriate place to free that memory. See notes in columnStart() for details.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ columnsEnd()

virtual bool sqlrexport::columnsEnd ( )
protectedvirtual

This method should be called after the export of the columns.

Note that it should be called whether or not columns are excluded.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

If you called setColumnName(...) in columnStart(), and had to allocate memory for the new value, then this may be an appropriate place to free that memory. See notes in columnStart() for details.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ columnsStart()

virtual bool sqlrexport::columnsStart ( )
protectedvirtual

This method should be called prior to the export of the columns.

Note that it should be called whether or not columns are excluded.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ columnStart()

virtual bool sqlrexport::columnStart ( )
protectedvirtual

This method should be called prior to the export of each column.

Note that it should be called for each column, whether or not columns are excluded, and whether or not this particular column is excluded.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

If you want to modify the name of the column that is going to be exported, this is a good method to override to call setCurrentColumnName(...)

Note, however...

The memory allocated to store the new value must persist until the value is actually exported. When this is depends on the implementation of the exportData() method.

Implementations that export to a file or json domnode typically export the column name before calling columnEnd(). As such, storage for the updated column name may be freed inside of your implementation of columnEnd().

However, other implementations may export all column names at once prior to calling columnsEnd(). In this case, storage for the updated column name should be freed inside of your implemenatation of columnsEnd().

Be sure to verify how the various exportData() methods that you are using were written, and use care when freeing storage allocated for updated column names.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ commitEnd()

virtual bool sqlrexport::commitEnd ( )
protectedvirtual

This method should be called after a commit().

This implementation just returns true but a child class may override this method to do something else.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ commitStart()

virtual bool sqlrexport::commitStart ( )
protectedvirtual

This method should be called before a commit().

This implementation just returns true but a child class may override this method to do something else.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ error()

virtual bool sqlrexport::error ( int64_t errornumber,
const char * errormessage )
protectedvirtual

This method should be called if a commit(), begin(), executeQuery(), or other database operation fails.

This implementation just returns false but a child class may override this method to do something else.

Should return true if export may continue, or false if should stop.

◆ exportData()

virtual bool sqlrexport::exportData ( )
virtual

Exports the result set of the cursor currently in use as set by the most recent call to setSqlrCursor().

Returns true on success and false if an error occurred.

Note that the default implementation of this method just returns true. Child classes should override this method.

Reimplemented in sqlrexportcsv, sqlrexportcsvjsondomnode, sqlrexportdomnode, sqlrexportfile, sqlrexporttable, and sqlrexportxml.

◆ exportEnd()

virtual bool sqlrexport::exportEnd ( )
protectedvirtual

This method should be called at the end of the export process.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ exportStart()

virtual bool sqlrexport::exportStart ( )
protectedvirtual

This method should be called at the beginning of the export process.

This implementation just returns true but a child class may override this method to do something else.

At this point...

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ fieldEnd()

virtual bool sqlrexport::fieldEnd ( )
protectedvirtual

This method should be called after the export of each field.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

If you called setCurrentField(...) in fieldStart(), and had to allocate memory for the new value, then this may be an appropriate place to free that memory. See notes in fieldStart() for details.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ fieldStart()

virtual bool sqlrexport::fieldStart ( )
protectedvirtual

This method should be called by prior to the export of each field.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

If you want to modify the value of the field that is going to be exported, this is a good method to override to call setCurrentField(...)

Note, however...

The memory allocated to store the new value must persist until the value is actually exported. When this is depends on the implementation of the exportData() method.

Implementations that export to a file or json domnode typically export the field before calling fieldEnd(). As such, storage for the updated field value may be freed inside of your implementation of fieldEnd().

However, implementations that export to a table tend to build an insert statement, bind values before calling fieldEnd(), and then execute the statement before calling rowEnd(). In this case, storage for the updated field value should be freed inside of your implemenatation of rowEnd().

Be sure to verify how the various exportData() methods that you are using were written, and use care when freeing storage allocated for updated field values.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ getCoarseLogLevel()

uint8_t sqlrexport::getCoarseLogLevel ( )

Returns the coarse log level.

◆ getColumnsToExclude()

const char *const * sqlrexport::getColumnsToExclude ( )

Returns the current set of columns that will not be exported as a NULL-terminated array.

◆ getCurrentColumn()

uint32_t sqlrexport::getCurrentColumn ( )
protected

Gets the index of the column that is currently being exported.

May be called by implementations of the *Start/End() methods.

◆ getCurrentColumnName()

const char * sqlrexport::getCurrentColumnName ( )
protected

Gets the name of the column that is currently being exported.

May be called by implementations of the *Start/End() methods.

◆ getCurrentField()

const char * sqlrexport::getCurrentField ( )
protected

Gets the value of the field that is currently being exported.

May be called by implementations of the *Start/End() methods.

◆ getCurrentRow()

uint64_t sqlrexport::getCurrentRow ( )
protected

Gets the index of the row that is currently being exported.

May be called by implementations of the *Start/End() methods.

◆ getExcludeColumns()

bool sqlrexport::getExcludeColumns ( )

Returns whether or not column information will be exported.

◆ getExcludeRow()

bool sqlrexport::getExcludeRow ( )
protected

Gets whether the current row will be excluded or not. Rows that are excluded are not exported.

May be called by implementations of the *Start/End() methods.

◆ getExportedRowCount()

uint64_t sqlrexport::getExportedRowCount ( )

Returns the number of rows that were exported by the most recent call to exportData(), or the current number of rows that have been exported, if called from inside one of the Start()/End() methods.

◆ getFineLogLevel()

uint8_t sqlrexport::getFineLogLevel ( )

Returns the fine log level.

◆ getIsNumericColumn()

bool sqlrexport::getIsNumericColumn ( uint64_t index)
protected

Get whether the data type of the column in position "index" is a numeric type or not.

May be called by implementations of the *Start/End() methods.

◆ getLogErrors()

bool sqlrexport::getLogErrors ( )

Returns true if SQL errors will be logged at the coarse log level and false otherwise.

◆ getLogger()

logger * sqlrexport::getLogger ( )

Returns the logger that is set to use when logging progress or NULL if no logger is set.

◆ getLogIndent()

uint32_t sqlrexport::getLogIndent ( )

Returns the log indent.

◆ getSqlrConnection()

sqlrconnection * sqlrexport::getSqlrConnection ( )

Returns the instance of sqlrconnection that this instance is configured to use to fetch data for the export.

◆ getSqlrCursor()

sqlrcursor * sqlrexport::getSqlrCursor ( )

Returns the instance of sqlrursor that this instance is configured to use to fetch data for the export.

◆ getTable()

const char * sqlrexport::getTable ( )

Gets the name of the table associated with the export.

This may be used differently by different child classes. Eg. it may be the name of the table being exported, or the name of the table that data is being exported to.

◆ rowEnd()

virtual bool sqlrexport::rowEnd ( )
protectedvirtual

This method should be called after the export of each row.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

If you called setCurrentField(...) in fieldStart(), and had to allocate memory for the new value, then this may be an appropriate place to free that memory. See notes in fieldStart() for details.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ rowsEnd()

virtual bool sqlrexport::rowsEnd ( )
protectedvirtual

This method should be called after the export of the rows.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ rowsStart()

virtual bool sqlrexport::rowsStart ( )
protectedvirtual

This method should be called by prior to the export of the rows.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ rowStart()

virtual bool sqlrexport::rowStart ( )
protectedvirtual

This method should be called prior to the export of each row.

This implementation just returns true but a child class may override this method to do something else.

At this point, unless specifically set otherwise in an overridden method...

This is a good place to call setExcludeRow(true) if you don't want this row to be exported.

Should return true on success and false if an error occurred and export should stop if this method return false.

◆ setCoarseLogLevel()

void sqlrexport::setCoarseLogLevel ( uint8_t coarseloglevel)

Sets the coarse log level. General log messages will be logged at this level. If the log level of "lg" (set by setLogger() above) is set equal to or greater than "coarseloglevel" then general log messages will be logged. Defaults to 0.

◆ setColumnsToExclude()

void sqlrexport::setColumnsToExclude ( const char *const * columnstoexclude)

If "columnstoexclude" is a null terminated array of column names, then those columns will not be exported. If "columnstoexclude" is NULL then all columns will be exported.

◆ setCurrentColumn()

void sqlrexport::setCurrentColumn ( uint32_t currentcol)
protected

Sets the index of the column that is currently being exported.

Not commonly called by implementations of the *Start/End() methods.

◆ setCurrentColumnName()

void sqlrexport::setCurrentColumnName ( const char * currentcolname)
protected

Sets the name of the column that is currently being exported.

May be called by columnStart(). Not commonly called by other *Start/End() methods.

◆ setCurrentField()

void sqlrexport::setCurrentField ( const char * currentfield)
protected

Sets the value of the field that is currently being exported.

Not commonly called by implementations of the *Start/End() methods.

◆ setCurrentRow()

void sqlrexport::setCurrentRow ( uint64_t currentrow)
protected

Sets the index of the row that is currently being exported.

Not commonly called by implementations of the *Start/End() methods.

◆ setExcludeColumns()

void sqlrexport::setExcludeColumns ( bool excludecolumns)

If "excludecolumns" is set false, then column information will be exported (eg. to the CSV header, XML tags inside of the file, etc.).

If "excludecolumns" is set true, then column information will not be exported.

Defaults to false.

◆ setExcludeRow()

void sqlrexport::setExcludeRow ( bool excluderow)
protected

Sets whether the current row will be excluded or not. Rows that are excluded are not exported.

May be called by rowStart(), fieldStart(), or fieldEnd(). Not commonly called by other *Start/End() methods.

◆ setExportedRowCount()

void sqlrexport::setExportedRowCount ( uint64_t exportedrowcount)
protected

Sets the number of rows that have been exported.

Not commonly called by implementations of the *Start/End() methods.

◆ setFineLogLevel()

void sqlrexport::setFineLogLevel ( uint8_t fineloglevel)

Sets the fine log level. Detailed log messages will be logged at this level. If the log level of "lg" (set by setLogger() above) is set equal to or greater than "coarseloglevel" then general log messages will be logged. Defaults to 9.

◆ setIsNumericColumn()

void sqlrexport::setIsNumericColumn ( uint64_t index,
bool numeric )
protected

Sets whether the data type of the column in position "index" is a numeric type or not. If "numeric" is true then the type of the column is set to numeric. If "numeric" is false then the type of the column is set to non-numeric.

Not commonly called by implementations of the *Start/End() methods.

◆ setLogErrors()

void sqlrexport::setLogErrors ( bool logerrors)

If "logerrors" is set true then SQL errors will be logged at the coarse log level. If set false then SQL errors will not be logged. Defaults to false.

◆ setLogger()

void sqlrexport::setLogger ( logger * lg)

Sets the logger to use when logging progress to "lg". If "lg" is set to NULL then progress will not be logged. Defaults to NULL.

◆ setLogIndent()

void sqlrexport::setLogIndent ( uint32_t logindent)

Sets the log indent level to "logindent". Defaults to 0.

◆ setSqlrConnection()

void sqlrexport::setSqlrConnection ( sqlrconnection * sqlrcon)

Sets the instance of sqlrconnection that this instance will use to fetch data for the export.

◆ setSqlrCursor()

void sqlrexport::setSqlrCursor ( sqlrcursor * sqlrcur)

Sets the instance of sqlrcursor that this instance will use to fetch data for the export.

◆ setTable()

void sqlrexport::setTable ( const char * table)

Sets the name of the table associated with the export.

This may be used differently by different child classes. Eg. it may be the name of the table being exported, or the name of the table that data is being exported to.