#include <dbimport.h>
Public Types | |
enum | ColumnAllowance { EXACT = 0, ALLOW_EXTRA_IN_FILE, ALLOW_EXTRA_IN_DATABASE, ALLOW_ANY_EXTRA } |
enum | ImportMatchBehaviour { FAIL_IMPORT = 0, FAIL_BUT_IGNORE_DUPLICATE, UPDATE, IGNORE_NEW } |
What to do when a match is found? (match based on primary columns). More... | |
enum | TextConversionMode { CONVERT_NORMAL = 1, CONVERT_TO_QE } |
How shall we deal with control characters. More... | |
enum | DateFormat { DATE_FORMAT_NORMAL = 1, DATE_FORMAT_EXTENDED } |
How shall we convert dates. More... | |
enum | ErrorAction { CONTINUE = 0, ABORT } |
What to do on an import error. More... | |
Public Methods | |
DbImport (DbConnection *theConnection=NULL) | |
Constructor. More... | |
~DbImport () | |
Destructor. | |
bool | DoImport (const LookString &theFileName) |
Actually do the import. More... | |
void | SetPrimaryColumns (const LookString &theColumnNames) |
Set primary columns. More... | |
void | SetFromTable (const LookString &theTableName) |
Table to import from. More... | |
void | SetToTable (const LookString &theTableName) |
Table to import into. More... | |
void | SetColumnAllowances (ColumnAllowance theAllowance) |
Set what to do if columns in file and table don't match. | |
void | SetImportMatchBehaviour (ImportMatchBehaviour theImportMatchBehaviour) |
Set what to do if duplicate rows found. | |
void | SetNULLString (const LookString &theString) |
Set string to use as NULL marker (default is "]^NULL^["). | |
void | SetTextConversionMode (TextConversionMode theConversionMode) |
Set control character conversion mode. | |
void | SetDOSLineEnds (bool useCRLF) |
long | GetNRowsInserted (void) |
How many rows were inserted? | |
long | GetNRowsUpdated (void) |
How many rows were updated? | |
long | GetNRowsWithErrors (void) |
How many rows had errors? | |
void | SetAllowNullDates (bool allowNullDates=true) |
void | SetErrorAction (ErrorAction theErrorAction) |
Set error behaviour. | |
void | SetDateFormat (DateFormat theDateFormat) |
Set date format. | |
void | SetExDatePartOrder (LookDateTimeReader::DatePartOrder theExDatePartOrder) |
void | SetExDateTimeOrder (LookDateTimeReader::DateTimeOrder theExDateTimeOrder) |
void | SetNCommitRows (long theNRows) |
Set how many rows to import before a commit. More... | |
Protected Types | |
typedef std::deque<SaveRow> | SaveRowList |
Protected Methods | |
LookString | GetNextLine (std::istream &theStream, bool &finished) |
LookString | GetColumn (const LookString &theLine, int theColumnIndex) |
bool | CheckColumnNames (void) |
void | MakeUpper (LookStringList &theStringList) |
void | MakeUpper (DbDescribeTable::ColumnInfoList &theColumnList) |
void | AddParameterToQuery (DbQuery *theQuery, const LookString &theString, DbDescribeTable::SColumnInfo &theColumnDescription) |
bool | InitialiseDuplicateCheckQuery (void) |
bool | LoadRowForImport (const LookString &theRowString, int theRowNumber) |
void | TokeniseAndConvertRow (const LookString &theInString, StringVector &theReturnStrings) |
bool | CheckMatchingRows (SaveRow &theRow, int theRowNumber) |
bool | CheckStoredRowPK (SaveRow &theNewRow, SaveRow &theOldRow) |
bool | RowsIdentical (SaveRow &theNewRow, SaveRow &theOldRow) |
bool | RowsIdentical (SaveRow &theNewRow, DbRow *theOldRow) |
DbQuery* | InitialiseInsertQuery (DbConnection *theConnection) |
DbQuery* | InitialiseUpdateQuery (DbConnection *theConnection) |
bool | InsertRow (SaveRow &theRow, DbQuery *theQuery) |
bool | UpdateRow (SaveRow &theRow, DbQuery *theQuery) |
bool | SaveImport (void) |
Protected Attributes | |
LookStringList | itsPrimaryColumns |
LookString | itsToTable |
LookString | itsFromTable |
ColumnAllowance | itsColumnAllowance |
ImportMatchBehaviour | itsImportMatchBehaviour |
bool | itAllowsNullDates |
TextConversionMode | itsTextConversionMode |
DateFormat | itsDateFormat |
LookDateTimeReader::DatePartOrder | itsExDatePartOrder |
LookDateTimeReader::DateTimeOrder | itsExDateTimeOrder |
ErrorAction | itsErrorAction |
LookString | itsNULLString |
LookString | itsLFString |
DbConnection* | itsConnection |
bool | itCommits |
long | itsNCommitRows |
long | itsNRowsInserted |
long | itsNRowsUpdated |
long | itsNRowsWithErrors |
LookString | itsDestinationTable |
DbDescribeTable::ColumnInfoList | itsColumnDescriptions |
LookStringList | itsColumnNames |
LongValList | itsPrimaryColumnIndices |
LongValList | itsPrimaryColumnDatabaseIndices |
LookStringList | itsCommonColumnNames |
LongValList | itsCommonColumnFileIndices |
LongValList | itsCommonColumnTableIndices |
BoolValList | itsCommonColumnPrimaryFlags |
bool | itsUpdateIsAllowed |
bool | itIsLoadingData |
DbQuery* | itsDuplicateCheckQuery |
SaveRowList | itsRowsToSave |
As such, it might not belong here. The intention was to allow other things (eg applications) use the import/export.
This takes a file exported by dbexport and imports it. The basic file format is
TABLENAME\tSQL statement Col1\tcol2\tcol3 r1c1\tr1c2\tr1c3 r2c1\tr2c2\tr2c3
where \t means 'tab'. It is in unix form, ie lines separated by \n.
This is configurable to an extent.
The manual page for dbimport explains quite a lot.
|
What to do if the columns in the table don't match those in the file. The file is rejected if unsuitable. |
|
How shall we convert dates.
|
|
What to do on an import error.
|
|
What to do when a match is found? (match based on primary columns).
|
|
How shall we deal with control characters.
|
|
Constructor.
|
|
Actually do the import.
|
|
If your date columns is 'NOT NULL WITH DEFAULT' you can't import NULL into it. You may however be able to import the empty string (!). If this is true set allowNullDates to true. |
|
|
|
Table to import from. This can be used as a check that you're using the right file. It compares the table name in the first line of the file with theTableName and rejects the file if it doesn't match.
|
|
Set how many rows to import before a commit. You probably need to set this for very big imports as otherwise it just loads all the data up into memory and spends its time swapping. |
|
Set primary columns.
|
|
Table to import into. If you're deleting anything before the import, you need to set the to table. This can also be used to import into a different table to that specified in the file.
|