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

Inherits sqlrimport, and csvsax.

Public Member Functions

 sqlrimportcsv ()
 
 ~sqlrimportcsv ()
 
void insertPrimaryKey (const char *primarykeycolumnname, uint32_t primarykeycolumnindex, const char *primarykeysequence)
 
void removePrimaryKey ()
 
void insertStaticValue (const char *columnname, uint32_t columnindex, const char *value)
 
void removeStaticValue (uint32_t columnindex)
 
void setIgnoreColumnsWithEmptyNames (bool ignorecolumnswithemptynames)
 
void setIgnoreEmptyRows (bool ignoreemptyrows)
 
bool importFromFile (const char *filename)
 
- Public Member Functions inherited from sqlrimport
 sqlrimport ()
 
virtual ~sqlrimport ()
 
void setSqlrConnection (sqlrconnection *sqlrcon)
 
void setSqlrCursor (sqlrcursor *sqlrcur)
 
void setDbType (const char *dbtype)
 
void setObjectName (const char *objectname)
 
void setIgnoreColumns (bool ignorecolumns)
 
void mapColumnName (const char *from, const char *to)
 
void mixedCaseColumnNames ()
 
void lowerCaseColumnNames ()
 
void upperCaseColumnNames ()
 
void mapFieldValue (const char *from, const char *to)
 
void setCommitCount (uint64_t commitcount)
 
void setLogger (logger *lg)
 
void setCoarseLogLevel (uint8_t coarseloglevel)
 
void setFineLogLevel (uint8_t fineloglevel)
 
void setLogIndent (uint32_t logindent)
 
void setLogErrors (bool logerrors)
 

Protected Member Functions

virtual bool column (const char *name, bool quoted)
 
virtual bool headerEnd ()
 
virtual bool bodyStart ()
 
virtual bool rowStart ()
 
virtual bool field (const char *value, bool quoted)
 
virtual bool rowEnd ()
 
virtual bool bodyEnd ()
 

Constructor & Destructor Documentation

◆ sqlrimportcsv()

sqlrimportcsv::sqlrimportcsv ( )

Creates an instance of the sqlrimportcsv class.

◆ ~sqlrimportcsv()

sqlrimportcsv::~sqlrimportcsv ( )

Destroys this intance of the sqlrimportcsv class.

Member Function Documentation

◆ bodyEnd()

virtual bool sqlrimportcsv::bodyEnd ( )
protectedvirtual

Called when the end of the CSV body is encountered. May be overridden to do application-specific work upon encountering the end of the CSV body. Returns false if an error occurred when processing the end of the CSV body and true otherwise. Overridden methods may return false to stop processing.

◆ bodyStart()

virtual bool sqlrimportcsv::bodyStart ( )
protectedvirtual

Called when the beginning of the CSV body is encountered. May be overridden to do application-specific work upon encountering the start of the body. Returns false if an error occurred when processing the start of the body and true otherwise. Overridden methods may return false to stop processing.

◆ column()

virtual bool sqlrimportcsv::column ( const char *  name,
bool  quoted 
)
protectedvirtual

Called when a column is encountered in the CSV header, even if setColumnNames(true) is set. May be overridden to do application-specific work upon encountering a column. "name" contains the column name. "quoted" is set true if the colum name is quoted in the file, and false otherwise. Returns false if an error occurred when processing the column and true otherwise. Overridden methods may return false to stop processing.

◆ field()

virtual bool sqlrimportcsv::field ( const char *  value,
bool  quoted 
)
protectedvirtual

Called when a field is encountered. May be overridden to do application-specific work upon encountering a field. "value" contains the column name. "quoted" is set true if the colum name is quoted in the file, and false otherwise. Returns false if an error occurred when processing the field and true otherwise. Overridden methods may return false to stop processing.

◆ headerEnd()

virtual bool sqlrimportcsv::headerEnd ( )
protectedvirtual

Called when the end of the CSV header is encountered, even if setColumnNames(true) is set. May be overridden to do application-specific work upon encountering the end of the header. Returns false if an error occurred when processing the end of the header and true otherwise. Overridden methods may return false to stop processing.

◆ importFromFile()

bool sqlrimportcsv::importFromFile ( const char *  filename)
virtual

Imports data from "filename". The table (or sequence) to import the data into will be derived from the import file name or may be overridden using setObjectName().

Implements sqlrimport.

◆ insertPrimaryKey()

void sqlrimportcsv::insertPrimaryKey ( const char *  primarykeycolumnname,
uint32_t  primarykeycolumnindex,
const char *  primarykeysequence 
)

Inserts a primary key at "primarykeycolumnindex".

If setIgnoreColumns(false) is set (the default) then "primarykeycolumnname" must be supplied. Otherwise it can be set to NULL or an empty string.

If "primarykeycolumnsequence" is non-empty and non-null then nextval('"primarykeycolumnsequence"') will be used to generate the key. Otherwise a NULL will be used in an attempt to trigger an autoincrement/serial column to generate a key.

◆ insertStaticValue()

void sqlrimportcsv::insertStaticValue ( const char *  columnname,
uint32_t  columnindex,
const char *  value 
)

Inserts static value "value" at "columnindex" for all rows.

If setIgnoreColumns(false) is set (the default) then "columnname" must be supplied. Otherwise it can be set to NULL or an empty string.

◆ removePrimaryKey()

void sqlrimportcsv::removePrimaryKey ( )

Removes any primary key configuaration set by a prior call to insertPrimaryKey().

◆ removeStaticValue()

void sqlrimportcsv::removeStaticValue ( uint32_t  columnindex)

Removes any static value configuaration at "columnindex" set by a prior call to insertStaticValue().

◆ rowEnd()

virtual bool sqlrimportcsv::rowEnd ( )
protectedvirtual

Called when the end of a row is encountered. May be overridden to do application-specific work upon encountering the end of a row. Returns false if an error occurred when processing the end of a row and true otherwise. Overridden methods may return false to stop processing.

◆ rowStart()

virtual bool sqlrimportcsv::rowStart ( )
protectedvirtual

Called when the beginning of a row is encountered. May be overridden to do application-specific work upon encountering the start of a row. Returns false if an error occurred when processing the start of a row and true otherwise. Overridden methods may return false to stop processing.

◆ setIgnoreColumnsWithEmptyNames()

void sqlrimportcsv::setIgnoreColumnsWithEmptyNames ( bool  ignorecolumnswithemptynames)

If "ignorecolumnswithemptynames" is set true, then columns with empty column names will be completely ignored. It will be as if those columns are completely absent from the CSV, which may be important to keep in mind when specifying indexes for primary keys or static values.

Note that "ignorecolumsnwithemptynames" is observed even if setIgnoreColumns(true) is set.

◆ setIgnoreEmptyRows()

void sqlrimportcsv::setIgnoreEmptyRows ( bool  ignoreemptyrows)

Configures the instance to ignore empty rows.