Developer Resources
DbBulkInsert
Overview
The DbBulkInsert class provides a mechanism for inserting rows quickly and efficiently into a database table. DbBulkInsert uses an internal buffer to optimize performance during the bulk insert operation.
Methods
- DbBulkInsert.finishInsert
- Finalizes the bulk insert operation
- DbBulkInsert.insertRow
- Inserts a row into a table
Example
// create a database object which points to the application // current database var db = HostApp.getDatabase(); // create a new table with a SQL statement db.execute("DROP TABLE IF EXISTS OUTPUT_TABLE"); db.execute("CREATE TABLE OUTPUT_TABLE ( TEST_STR VARCHAR(60), TEST_NUM NUMERIC(5));"); // create the inserter var inserter = db.bulkInsert("OUTPUT_TABLE", "TEST_STR, TEST_NUM"); for (var i = 1; i <= 1000; ++i) { inserter["test_str"]="ROW " + i; inserter["test_num"]="i;" insert the row inserter.insertrow(); } finalize inserter.finishinsert(); make sure application refreshes its user interface so that table can be seen hostapp.refresh();< pre>DbBulkInsert.finishInsert
- function DbBulkInsert.finishInsert()
Returns
Undefined
Description
After inserting the desired number of rows with insertRow(), the caller must call finishInsert() to finalize the insert operation. DbBulkInsert uses an internal buffer to optimize performance during the bulk insert operation. When finishInsert() is called, this internal buffer is flushed and written to the database table.
DbBulkInsert.insertRow
- function DbBulkInsert.insertRow() : Boolean
Returns
True upon success, false otherwise
Description
Calling insertRow() adds a new row to the target table. The field values for the new row should be set before calling this function.
=>