Status & Roadmap
Authors & License
Funding U++
Search on this site

SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo



class SqlMassInsert

This class is intended for situations where a lot of data has to be inserted into database using SQL commands. Using separate insert statements for each row can be slow in this case, mainly due to network traffic. SqlMassInsert buffers single inserts and, based on specific SQL dialect, inserts many rows with single SQL statement.


Public Method List


SqlMassInsert& operator()(SqlId col, const Value& val)

Adds a single column to be inserted.



SqlMassInsert& operator()(const ValueMap& data)

Inserts a set of columns defined by key-value pairs of data (key is the name of column, value is the inserted value).



SqlMassInsert& EndRow(SqlBool remove = SqlBool())

Finishes one row. Note that each row has to have the same columns added in the same order. If remove is not empty, it is combined using or and if combined condition is not empty during Flush, delete statement is issued before inserting rows, using combined condition in the where clause. This is intended for situation where rows are replaced (in addition to be inserted) - this it is possible to specify condition for row being inserted, so that it is removed (if exists) before inserting a new value. Rows must always have the same columns before EndRow is invoked, and exception to this rule is when EndRow is invoked without any columns added - in that case, nothing is inserted, only remove condition is used.



void Flush()

Inserts all buffered rows. SqlMassInsert calls this when buffer reaches threshold and in destructor. Usually there is no need to call Flush directly, except perhaps at the end of inserting to retrieve the final IsError.



bool IsError() const

Returns true if SQL error was detected.



SqlMassInsert& UseTransaction(bool b = true)

Inserting a batch of rows (in Flush) uses transaction. This is default.



SqlMassInsert& NoUseTransaction()

Same as UseTransaction(false).



SqlMassInsert(Sql& sql, SqlId table)

Creates instance for sql context and table .



SqlMassInsert(SqlId table)

Creates instance for default context (SQL) and table ..




Calls Flush.


Do you want to contribute?