Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::DbImport Class Reference

This class is the meat of the dbimport utility. More...

#include <dbimport.h>

List of all members.

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)
DbQueryInitialiseInsertQuery (DbConnection *theConnection)
DbQueryInitialiseUpdateQuery (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
DbConnectionitsConnection
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
DbQueryitsDuplicateCheckQuery
SaveRowList itsRowsToSave


Detailed Description

This class is the meat of the dbimport utility.

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.


Member Enumeration Documentation

enum look::DbImport::ColumnAllowance
 

What to do if the columns in the table don't match those in the file. The file is rejected if unsuitable.

Enumeration values:
EXACT   Table must match file
ALLOW_EXTRA_IN_FILE   Table must be subset of file
ALLOW_EXTRA_IN_DATABASE   File must be subset of table
ALLOW_ANY_EXTRA   No check

enum look::DbImport::DateFormat
 

How shall we convert dates.

Enumeration values:
DATE_FORMAT_NORMAL   Simple date parsing using LookDateTime::Set()
DATE_FORMAT_EXTENDED   More flexible (but slower) parsing using LookDateTimeReader

enum look::DbImport::ErrorAction
 

What to do on an import error.

Enumeration values:
CONTINUE   Carry on (ignore the row with an error)
ABORT   Stop the import

enum look::DbImport::ImportMatchBehaviour
 

What to do when a match is found? (match based on primary columns).

Enumeration values:
FAIL_IMPORT   Fail the import
FAIL_BUT_IGNORE_DUPLICATE   Fail the import unless it was an exact match (all columns match)
UPDATE   Update to the new values
IGNORE_NEW   Keep the old row

enum look::DbImport::TextConversionMode
 

How shall we deal with control characters.

Enumeration values:
CONVERT_NORMAL   \t goes to tab, \r to cr, \n to lf, \ to \
CONVERT_TO_QE   If a string is quoted (" quotes), quotes are stripped and "" are converted to "


Constructor & Destructor Documentation

look::DbImport::DbImport ( DbConnection * theConnection = NULL )
 

Constructor.

Parameters:
theConnection   Connection to use. At some point in the future this may be useful, but at the moment this always commits when it's finished.


Member Function Documentation

bool look::DbImport::DoImport ( const LookString & theFileName )
 

Actually do the import.

Parameters:
theFileName   File to import from
Returns:
true for success. DbError will be set in case of failure.

void look::DbImport::SetAllowNullDates ( bool allowNullDates = true ) [inline]
 

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.

void look::DbImport::SetDOSLineEnds ( bool useCRLF ) [inline]
 

Parameters:
useCRLF   true if the file has cr/lf (DOS) line ends, false for lf (unix).

void look::DbImport::SetFromTable ( const LookString & theTableName )
 

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.

Parameters:
theTableName   Table name

void look::DbImport::SetNCommitRows ( long theNRows ) [inline]
 

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.

void look::DbImport::SetPrimaryColumns ( const LookString & theColumnNames )
 

Set primary columns.

Parameters:
theColumnNames   Comma-separated list of column names used for primary key matching. Whitespace not allowed.

void look::DbImport::SetToTable ( const LookString & theTableName )
 

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.

Parameters:
theTableName   Table name


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:08 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001