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.
// create a database object which points to the application
// current database
const 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
const inserter = db.bulkInsert("OUTPUT_TABLE", "TEST_STR, TEST_NUM");
for (let i = 1; i <= 1000; ++i) {
inserter["TEST_STR"] = `ROW ${i}`;
inserter["TEST_NUM"] = i;
// insert the row
inserter.insertRow();
}
// finalize the insert
inserter.finishInsert();
// make sure the application refreshes its user
// interface so that the table can be seen
HostApp.open("OUTPUT_TABLE");
HostApp.refresh(); Undefined
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.
True upon success, false otherwise
Calling insertRow() adds a new row to the target table. The field values for the new row should be set before calling this function.