addData

void sqlDataManager.addData ( String table, Map data ) (professional and enterprise editions only)
void sqlDataManager.addData ( String table, String columnName, Object value ) (professional and enterprise editions only)

Description

Add data to fields, in preparation for insertion into a database.

When adding data in a many-to-many relation, if setAutoManyToMany is set to false, a null row should be inserted into the relating table so the datamanager will link the keys correctly between related tables. For example, dm.addData("many_to_many", null);

Before adding data the first time, you must build the schema of any tables you will use, as well as add foreign keys if you are not using a database engine that natively supports them (such as InnoDB for MySQL).

Parameters

  • table Name of the database table that the data corresponds to, as a string.
  • data (this or columnName and value) Map using field names as keys to desired values to be added in the database for fields. This can be a dataRecord object.
  • columnName (requires value) The name of the column/field in the database table that the data is being added for, as a string.
  • value (requires columnName) The value being inserted into the column/field.
  • The SqlDataManager will attempt to convert a value that is given to the correct format for the database. For example, if the database requires an int for a column named age, dm.addData("table", "age", "32") will convert the String "32" to an int before adding it to the database. See the table below the examples for other types of java objects and how they map to SQL types.

The table and columnName parameters are not case sensitive. The same is true for the key values in the data map.

Return Values

Returns void.

Change Log

Version Description
5.0 Available for professional and enterprise editions.

Examples

Add Data from Data Record

 // Get datamanager
 dm = session.getv( "DATAMANAGER" );

 // Add DataRecord Information into person table
 dm.addData( "person", dataRecord );

 // Create and add query to buffer
 dm.commit( "person" );

Add Data In a Specific Field

 // Get datamanager
 dm = session.getv( "DATAMANAGER" );

 // Add DataRecord Information into person table
 dm.addData( "person", dataRecord );

 // Add Specific Other Data
 dm.addData( "person", "date_collected", "2010-07-13" );

 // Create and add query to buffer
 dm.commit( "person" );

Java Object and SQL Type Mappings

Since the DataManager is designed with screen-scraper in mind all inputs support using the String type in addition to their corresponding Java object type, but the String needs to be parseable into the corresponding data type. For example if there is a column that is defined as an Integer in the database then the String needs to be parseable by Integer.parseInt(String value). Here is a mapping of the sql types (based on java.sql.Types) to Java objects:

SQL Type       Java Object
java.sql.Types.CHAR String
java.sql.Types.VARCHAR String
java.sql.Types.LONGVARCHAR String
java.sql.Types.LONGNVARCHAR String
java.sql.Types.NUMERIC BigDecimal
java.sql.Types.DECIMAL BigDecimal
java.sql.Types.TINYINT Integer
java.sql.Types.SMALLINT Integer
java.sql.Types.INTEGER Integer
java.sql.Types.BIGINT Long
java.sql.Types.REAL Float
java.sql.Types.FLOAT Double
java.sql.Types.DOUBLE Double
java.sql.Types.BIT Boolean
java.sql.Types.BINARY ByteArray
java.sql.Types.VARBINARY ByteArray
java.sql.Types.LONGVARBINARY ByteArray
java.sql.Types.DATE SQLDate or Long
java.sql.Types.TIME SQLTime or Long
java.sql.Types.TIMESTAMP SQLTime or Long
java.sql.Types.ARRAY Object
java.sql.Types.BLOB ByteArray
java.sql.Types.CLOB Object
java.sql.Types.JAVA_OBJECT Object
java.sql.Types.OTHER Object

See Also

  • commit() [SqlDataManager] - Commits a prepared row of data to the queue to be updated in the database
  • commitAll() [SqlDataManager] - Commits all prepared rows of data to the queue to be updated in the database